small fix to pupil coordinate calculation
authormaemo <maemo@maemo-desktop.(none)>
Sun, 27 Sep 2009 16:18:01 +0000 (17:18 +0100)
committermaemo <maemo@maemo-desktop.(none)>
Sun, 27 Sep 2009 16:18:01 +0000 (17:18 +0100)
src/eyes.c

index a735b92..d213234 100644 (file)
@@ -81,13 +81,6 @@ calculate_pupil_xy (EyesPluginContent *eyes_applet,
 
   h = hypot (nx, ny);
 
-  if ( nx*nx/((eyes_applet->eye_width/2.0 - eyes_applet->pupil_width / 2)*(eyes_applet->eye_width/2.0 - eyes_applet->pupil_width/2)) + ny*ny/((eyes_applet->eye_height/2 - eyes_applet->pupil_height/2)*(eyes_applet->eye_height/2 - eyes_applet->pupil_height/2)) < 1 )
-    {
-      *pupil_x = nx + eyes_applet->eye_width / 2;
-      *pupil_y = ny + eyes_applet->eye_height / 2;
-      return;
-    }
-
   sina = nx / h;
   cosa = ny / h;
 
@@ -95,8 +88,16 @@ calculate_pupil_xy (EyesPluginContent *eyes_applet,
   temp -= hypot ((eyes_applet->pupil_width / 2) * sina, (eyes_applet->pupil_height / 2) * cosa);
   temp -= hypot ((eyes_applet->wall_thickness / 2) * sina, (eyes_applet->wall_thickness / 2) * cosa);
 
-  *pupil_x = temp * sina + (eyes_applet->eye_width / 2);
-  *pupil_y = temp * cosa + (eyes_applet->eye_height / 2);
+  if ( hypot(temp*sina, temp*cosa) > hypot( nx , ny ) )
+    {
+      *pupil_x = nx + eyes_applet->eye_width / 2;
+      *pupil_y = ny + eyes_applet->eye_height / 2;
+    }
+  else 
+    {
+      *pupil_x = temp * sina + (eyes_applet->eye_width / 2);
+      *pupil_y = temp * cosa + (eyes_applet->eye_height / 2);
+    }
 }
 
 static void