Commit 32a7d87050bf891d476892d441a56921eda299b0

Alexei Podtelezhnikov 2013-08-17T22:19:21

[base] Clean up BBox_Conic_Check. * src/base/ftbbox.c (BBox_Conic_Check): Remove redundant checks for extremum at the segment ends, which are already within the bbox. Slightly modify calculations.

diff --git a/ChangeLog b/ChangeLog
index 0098354..c79b8c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-08-17  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	[base] Clean up BBox_Conic_Check.
+
+	* src/base/ftbbox.c (BBox_Conic_Check): Remove redundant checks for
+	extremum at the segment ends, which are already within the bbox.
+	Slightly modify calculations. 
+
 2013-08-15  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
 	[base] Finish experimental (disabled) BBox_Cubic_Check implementation.
diff --git a/src/base/ftbbox.c b/src/base/ftbbox.c
index 3fe0a7d..c4bd027 100644
--- a/src/base/ftbbox.c
+++ b/src/base/ftbbox.c
@@ -108,30 +108,19 @@
                     FT_Pos*  min,
                     FT_Pos*  max )
   {
-    if ( y1 <= y3 && y2 == y1 )     /* flat arc */
-      goto Suite;
-
-    if ( y1 < y3 )
-    {
-      if ( y2 >= y1 && y2 <= y3 )   /* ascending arc */
-        goto Suite;
-    }
-    else
-    {
-      if ( y2 >= y3 && y2 <= y1 )   /* descending arc */
-      {
-        y2 = y1;
-        y1 = y3;
-        y3 = y2;
-        goto Suite;
-      }
-    }
-
-    y1 = y3 = y1 - FT_MulDiv( y2 - y1, y2 - y1, y1 - 2*y2 + y3 );
-
-  Suite:
-    if ( y1 < *min ) *min = y1;
-    if ( y3 > *max ) *max = y3;
+    /* This function is only called when a control off-point is outside  */
+    /* the bbox. This also means there must be a local extremum within   */
+    /* the segment with the value of (y1*y3 - y2*y2)/(y1 - 2*y2 + y3).   */
+    /* Offsetting from the closest point to the extermum, y2, we get     */
+
+    y1 -= y2;
+    y3 -= y2;
+    y2 += FT_MulDiv( y1, y3, y1 + y3 );
+
+    if ( y2 < *min )
+      *min = y2;
+    if ( y2 > *max )
+      *max = y2;
   }