(libhooke.py) find_graph_coords now takes finds the point closer to clicked point...
authoralbertogomcas <devnull@localhost>
Fri, 20 Jun 2008 10:36:12 +0000 (10:36 +0000)
committeralbertogomcas <devnull@localhost>
Fri, 20 Jun 2008 10:36:12 +0000 (10:36 +0000)
(macro.py) uses workdir in hooke.conf instead of self.currentdir

libhooke.py
macro.py

index 533cc3e38d8dce1df1347294c63165e4058a30e7..7d1a8874544d82f41c5293decfb531a6bff0648f 100755 (executable)
@@ -254,17 +254,16 @@ class ClickedPoint:
         corresponds to the clicked point.
         '''
                    
-        #Ye Olde sorting algorithm...
-        index=0
         best_index=0
-        best_diff=10^9 #FIXME:hope we never go over this magic number, doing best_diff=max(xvector)-min(xvector) can be better...
-        for point in xvector:
-            diff=abs(point-self.absolute_coords[0])
-            if diff<best_diff:
+        best_dist=10**9 #should be more than enough given the scale
+                
+        for index in scipy.arange(1,len(xvector),1):
+            dist=((self.absolute_coords[0]-xvector[index])**2)+(100*((self.absolute_coords[1]-yvector[index])))**2
+                        #TODO, generalize? y coordinate is multiplied by 100 due to scale differences in the plot
+            if dist<best_dist:
                 best_index=index
-                best_diff=diff
-            index+=1
-            
+                best_dist=dist
+                        
         self.index=best_index
         self.graph_coords=(xvector[best_index],yvector[best_index])
         return
index ec73cf401ff8033a85733c78306797ef06a087cf..bdeafabe7f9f191981116c26320466e8127006dd 100644 (file)
--- a/macro.py
+++ b/macro.py
@@ -23,14 +23,14 @@ class macroCommands:
        def _plug_init(self):
                self.currentmacro=[]
                self.auxprompt=self.prompt
-               self.macrodir=os.curdir
+               self.macrodir=self.config['workdir']
                if not os.path.exists(os.path.join(self.macrodir,'macros')):
                     try:
                         os.mkdir('macros')
                     except:
                         print 'Warning: cannot create macros folder.'
                         print 'Probably you do not have permissions in your Hooke folder, use macro at your own risk.'
-                        self.macrodir=os.path.join(self.macrodir,'macros')
+                self.macrodir=os.path.join(self.macrodir,'macros')
 
        def collect(self):