1 /***************************************************************************/
5 /* Routines used to compute vector angles with limited accuracy */
6 /* and very high speed. It also contains sorting routines (body). */
8 /* Copyright 2003, 2004, 2005, 2006 by */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
11 /* This file is part of the FreeType project, and may only be used, */
12 /* modified, and distributed under the terms of the FreeType project */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
17 /***************************************************************************/
25 FT_LOCAL_DEF( FT_Int
)
26 af_corner_is_flat( FT_Pos x_in
,
34 FT_Pos d_in
, d_out
, d_corner
;
59 return ( d_in
+ d_out
- d_corner
) < ( d_corner
>> 4 );
63 FT_LOCAL_DEF( FT_Int
)
64 af_corner_orientation( FT_Pos x_in
,
72 delta
= x_in
* y_out
- y_in
* x_out
;
77 return 1 - 2 * ( delta
< 0 );
84 * We are not using `af_angle_atan' anymore, but we keep the source
85 * code below just in case...
93 * The trick here is to realize that we don't need a very accurate angle
94 * approximation. We are going to use the result of `af_angle_atan' to
95 * only compare the sign of angle differences, or check whether its
96 * magnitude is very small.
100 * dy * PI / (|dx|+|dy|)
102 * should be enough, and much faster to compute.
104 FT_LOCAL_DEF( AF_Angle
)
105 af_angle_atan( FT_Fixed dx
,
124 angle
= ( AF_ANGLE_PI2
* dy
) / ( ax
+ ay
);
128 angle
= AF_ANGLE_PI
- angle
;
130 angle
= -AF_ANGLE_PI
- angle
;
141 /* the following table has been automatically generated with */
142 /* the `mather.py' Python script */
144 #define AF_ATAN_BITS 8
146 static const FT_Byte af_arctan
[1L << AF_ATAN_BITS
] =
148 0, 0, 1, 1, 1, 2, 2, 2,
149 3, 3, 3, 3, 4, 4, 4, 5,
150 5, 5, 6, 6, 6, 7, 7, 7,
151 8, 8, 8, 9, 9, 9, 10, 10,
152 10, 10, 11, 11, 11, 12, 12, 12,
153 13, 13, 13, 14, 14, 14, 14, 15,
154 15, 15, 16, 16, 16, 17, 17, 17,
155 18, 18, 18, 18, 19, 19, 19, 20,
156 20, 20, 21, 21, 21, 21, 22, 22,
157 22, 23, 23, 23, 24, 24, 24, 24,
158 25, 25, 25, 26, 26, 26, 26, 27,
159 27, 27, 28, 28, 28, 28, 29, 29,
160 29, 30, 30, 30, 30, 31, 31, 31,
161 31, 32, 32, 32, 33, 33, 33, 33,
162 34, 34, 34, 34, 35, 35, 35, 35,
163 36, 36, 36, 36, 37, 37, 37, 38,
164 38, 38, 38, 39, 39, 39, 39, 40,
165 40, 40, 40, 41, 41, 41, 41, 42,
166 42, 42, 42, 42, 43, 43, 43, 43,
167 44, 44, 44, 44, 45, 45, 45, 45,
168 46, 46, 46, 46, 46, 47, 47, 47,
169 47, 48, 48, 48, 48, 48, 49, 49,
170 49, 49, 50, 50, 50, 50, 50, 51,
171 51, 51, 51, 51, 52, 52, 52, 52,
172 52, 53, 53, 53, 53, 53, 54, 54,
173 54, 54, 54, 55, 55, 55, 55, 55,
174 56, 56, 56, 56, 56, 57, 57, 57,
175 57, 57, 57, 58, 58, 58, 58, 58,
176 59, 59, 59, 59, 59, 59, 60, 60,
177 60, 60, 60, 61, 61, 61, 61, 61,
178 61, 62, 62, 62, 62, 62, 62, 63,
179 63, 63, 63, 63, 63, 64, 64, 64
183 FT_LOCAL_DEF( AF_Angle
)
184 af_angle_atan( FT_Fixed dx
,
190 /* check trivial cases */
200 angle
= AF_ANGLE_PI2
;
202 angle
= -AF_ANGLE_PI2
;
222 angle
-= AF_ANGLE_PI2
;
225 if ( dx
== 0 && dy
== 0 )
229 angle
+= AF_ANGLE_PI4
;
231 angle
+= af_arctan
[FT_DivFix( dy
, dx
) >> ( 16 - AF_ATAN_BITS
)];
233 angle
+= AF_ANGLE_PI2
-
234 af_arctan
[FT_DivFix( dx
, dy
) >> ( 16 - AF_ATAN_BITS
)];
236 if ( angle
> AF_ANGLE_PI
)
237 angle
-= AF_ANGLE_2PI
;
247 af_sort_pos( FT_UInt count
,
254 for ( i
= 1; i
< count
; i
++ )
256 for ( j
= i
; j
> 0; j
-- )
258 if ( table
[j
] > table
[j
- 1] )
262 table
[j
] = table
[j
- 1];
270 af_sort_widths( FT_UInt count
,
277 for ( i
= 1; i
< count
; i
++ )
279 for ( j
= i
; j
> 0; j
-- )
281 if ( table
[j
].org
> table
[j
- 1].org
)
285 table
[j
] = table
[j
- 1];