Ran update_copyright.py, updating all the copyright blurbs and adding AUTHORS.
[hooke.git] / hooke / ui / gui / point_request.py
1 # Copyright (C) 2008-2010 Alberto Gomez-Casado
2 #                         Fabrizio Benedetti
3 #                         Massimo Sandal <devicerandom@gmail.com>
4 #                         W. Trevor King <wking@drexel.edu>
5 #
6 # This file is part of Hooke.
7 #
8 # Hooke is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation, either
11 # version 3 of the License, or (at your option) any later version.
12 #
13 # Hooke is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with Hooke.  If not, see
20 # <http://www.gnu.org/licenses/>.
21
22 class ClickedPoint(object):
23     '''
24     this class defines what a clicked point on the curve plot is
25     '''
26     def __init__(self):
27
28         self.is_marker=None #boolean ; decides if it is a marker
29         self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused)
30         self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph
31         self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
32         self.index=None #integer ; the index of the clicked point with respect to the vector selected
33         self.dest=None #0 or 1 ; 0=top plot 1=bottom plot
34
35
36     def find_graph_coords_old(self, xvector, yvector):
37         '''
38         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
39         corresponds to the clicked point.
40         OLD & DEPRECATED - to be removed
41         '''
42
43         #FIXME: a general algorithm using min() is needed!
44         best_index=0
45         best_dist=10**9 #should be more than enough given the scale
46
47         for index in scipy.arange(1,len(xvector),1):
48             dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2
49                 #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot
50             if dist<best_dist:
51                 best_index=index
52                 best_dist=dist
53
54         self.index=best_index
55         self.graph_coords=(xvector[best_index],yvector[best_index])
56         return
57
58     def find_graph_coords(self,xvector,yvector):
59         '''
60         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
61         corresponds to the clicked point.
62         '''
63         dists=[]
64         for index in scipy.arange(1,len(xvector),1):
65             dists.append(((self.absolute_coords[0]-xvector[index])**2)+((self.absolute_coords[1]-yvector[index])**2))
66
67         self.index=dists.index(min(dists))
68         self.graph_coords=(xvector[self.index],yvector[self.index])