shithub: freetype+ttf2subf

Download patch

ref: 09dbb059e1d5397ec468b1539d0fabaa6ecd066d
parent: 5dd9657fe8bc8d70d1119ed0dbd5de1545688239
author: Alexei Podtelezhnikov <[email protected]>
date: Tue Jan 8 18:29:44 EST 2013

[base] Clean up trigonometric core.

* src/base/fttrigon.c: Document the algorithm in a large comment.
(FT_TRIG_COSCALE): Remove macro.
(FT_Tan: Use `FT_TRIG_SCALE' instead.
(FT_Cos, FT_Vector_Unit): Ditto and round the return values.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-01-08  Alexei Podtelezhnikov  <[email protected]>
+
+	[base] Clean up trigonometric core.
+
+	* src/base/fttrigon.c: Document the algorithm in a large comment.
+	(FT_TRIG_COSCALE): Remove macro.
+	(FT_Tan: Use `FT_TRIG_SCALE' instead.
+	(FT_Cos, FT_Vector_Unit): Ditto and round the return values.
+
 2013-01-02  Alexei Podtelezhnikov  <[email protected]>
 
 	[base] Use rounding in CORDIC iterations.
--- a/src/base/fttrigon.c
+++ b/src/base/fttrigon.c
@@ -15,6 +15,19 @@
 /*                                                                         */
 /***************************************************************************/
 
+  /*************************************************************************/
+  /*                                                                       */
+  /* This is a fixed-point CORDIC implementation of trigonometric          */
+  /* functions as well as transformations between Cartesian and polar      */
+  /* coordinates. The angles are represented as a 16.16 fixed-point value  */
+  /* in degrees, i.e., the angular resolution is 2^-16 degrees. Note that   */
+  /* only vectors longer than 2^16*180/pi (or at least 22 bits) on a       */
+  /* discrete Cartesian greed can have the same or better angular          */
+  /* resolution. Therefore, to maintain this precision, some functions     */
+  /* require the interim upscaling of the vectors, whereas others operate  */
+  /* with 24-bit long vectors from the start.                              */
+  /*                                                                       */
+  /*************************************************************************/
 
 #include <ft2build.h>
 #include FT_INTERNAL_OBJECTS_H
@@ -29,9 +42,6 @@
   /* the Cordic shrink factor 0.858785336480436 * 2^32 */
 #define FT_TRIG_SCALE    0xDBD95B16UL
 
-  /* the following is 0.858785336480436 * 2^30 */
-#define FT_TRIG_COSCALE  0x36F656C6UL
-
   /* this table was generated for FT_PI = 180L << 16, i.e. degrees */
 #define FT_TRIG_MAX_ITERS  23
 
@@ -326,11 +336,11 @@
     FT_Vector  v;
 
 
-    v.x = FT_TRIG_COSCALE >> 2;
+    v.x = FT_TRIG_SCALE >> 8;
     v.y = 0;
     ft_trig_pseudo_rotate( &v, angle );
 
-    return v.x / ( 1 << 12 );
+    return ( v.x + 0x80L ) >> 8;
   }
 
 
@@ -351,7 +361,7 @@
     FT_Vector  v;
 
 
-    v.x = FT_TRIG_COSCALE >> 2;
+    v.x = FT_TRIG_SCALE >> 8;
     v.y = 0;
     ft_trig_pseudo_rotate( &v, angle );
 
@@ -386,11 +396,11 @@
   FT_Vector_Unit( FT_Vector*  vec,
                   FT_Angle    angle )
   {
-    vec->x = FT_TRIG_COSCALE >> 2;
+    vec->x = FT_TRIG_SCALE >> 8;
     vec->y = 0;
     ft_trig_pseudo_rotate( vec, angle );
-    vec->x >>= 12;
-    vec->y >>= 12;
+    vec->x = ( vec->x + 0x80L ) >> 8;
+    vec->y = ( vec->y + 0x80L ) >> 8;
   }