Updated copyright blurbs in all files to '# Copyright'
[hooke.git] / hooke / ui / gui / point_request.py
1 # Copyright
2
3 class ClickedPoint(object):
4     '''
5     this class defines what a clicked point on the curve plot is
6     '''
7     def __init__(self):
8
9         self.is_marker=None #boolean ; decides if it is a marker
10         self.is_line_edge=None #boolean ; decides if it is the edge of a line (unused)
11         self.absolute_coords=(None,None) #(float,float) ; the absolute coordinates of the clicked point on the graph
12         self.graph_coords=(None,None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
13         self.index=None #integer ; the index of the clicked point with respect to the vector selected
14         self.dest=None #0 or 1 ; 0=top plot 1=bottom plot
15
16
17     def find_graph_coords_old(self, xvector, yvector):
18         '''
19         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
20         corresponds to the clicked point.
21         OLD & DEPRECATED - to be removed
22         '''
23
24         #FIXME: a general algorithm using min() is needed!
25         best_index=0
26         best_dist=10**9 #should be more than enough given the scale
27
28         for index in scipy.arange(1,len(xvector),1):
29             dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2
30                 #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot
31             if dist<best_dist:
32                 best_index=index
33                 best_dist=dist
34
35         self.index=best_index
36         self.graph_coords=(xvector[best_index],yvector[best_index])
37         return
38
39     def find_graph_coords(self,xvector,yvector):
40         '''
41         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
42         corresponds to the clicked point.
43         '''
44         dists=[]
45         for index in scipy.arange(1,len(xvector),1):
46             dists.append(((self.absolute_coords[0]-xvector[index])**2)+((self.absolute_coords[1]-yvector[index])**2))
47
48         self.index=dists.index(min(dists))
49         self.graph_coords=(xvector[self.index],yvector[self.index])