Ran update_copyright.py
[hooke.git] / hooke / ui / gui / clickedpoint.py
1 #!/usr/bin/env python
2
3 '''
4 clickedpoint.py
5
6 ClickedPoint class for Hooke.
7
8 Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)
9
10 This program is released under the GNU General Public License version 2.
11 '''
12
13 from scipy import arange
14
15 class ClickedPoint(object):
16     '''
17     This class defines what a clicked point on the curve plot is.
18     '''
19     def __init__(self):
20
21         self.is_marker = None #boolean ; decides if it is a marker
22         self.is_line_edge = None #boolean ; decides if it is the edge of a line (unused)
23         self.absolute_coords = (None, None) #(float,float) ; the absolute coordinates of the clicked point on the graph
24         self.graph_coords = (None, None) #(float,float) ; the coordinates of the plot that are nearest in X to the clicked point
25         self.index = None #integer ; the index of the clicked point with respect to the vector selected
26         self.dest = None #0 or 1 ; 0=top plot 1=bottom plot
27
28     def find_graph_coords(self, xvector, yvector):
29         '''
30         Given a clicked point on the plot, finds the nearest point in the dataset (in X) that
31         corresponds to the clicked point.
32         '''
33         dists = []
34         for index in arange(1, len(xvector), 1):
35             dists.append(((self.absolute_coords[0] - xvector[index]) ** 2)+((self.absolute_coords[1] - yvector[index]) ** 2))
36
37         self.index=dists.index(min(dists))
38         self.graph_coords=(xvector[self.index], yvector[self.index])