Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ftcalc.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* ftcalc.c */
4 /* */
5 /* Arithmetic computations (body). */
6 /* */
7 /* Copyright 1996-2006, 2008, 2012-2013 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
17 
18  /*************************************************************************/
19  /* */
20  /* Support for 1-complement arithmetic has been totally dropped in this */
21  /* release. You can still write your own code if you need it. */
22  /* */
23  /*************************************************************************/
24 
25  /*************************************************************************/
26  /* */
27  /* Implementing basic computation routines. */
28  /* */
29  /* FT_MulDiv(), FT_MulFix(), FT_DivFix(), FT_RoundFix(), FT_CeilFix(), */
30  /* and FT_FloorFix() are declared in freetype.h. */
31  /* */
32  /*************************************************************************/
33 
34 
35 #include <ft2build.h>
36 #include FT_GLYPH_H
37 #include FT_TRIGONOMETRY_H
38 #include FT_INTERNAL_CALC_H
39 #include FT_INTERNAL_DEBUG_H
40 #include FT_INTERNAL_OBJECTS_H
41 
42 #ifdef FT_MULFIX_INLINED
43 #undef FT_MulFix
44 #endif
45 
46 /* we need to emulate a 64-bit data type if a real one isn't available */
47 
48 #ifndef FT_LONG64
49 
50  typedef struct FT_Int64_
51  {
52  FT_UInt32 lo;
53  FT_UInt32 hi;
54 
55  } FT_Int64;
56 
57 #endif /* !FT_LONG64 */
58 
59 
60  /*************************************************************************/
61  /* */
62  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
63  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
64  /* messages during execution. */
65  /* */
66 #undef FT_COMPONENT
67 #define FT_COMPONENT trace_calc
68 
69 
70  /* The following three functions are available regardless of whether */
71  /* FT_LONG64 is defined. */
72 
73  /* documentation is in freetype.h */
74 
77  {
78  return ( a >= 0 ) ? ( a + 0x8000L ) & ~0xFFFFL
79  : -((-a + 0x8000L ) & ~0xFFFFL );
80  }
81 
82 
83  /* documentation is in freetype.h */
84 
87  {
88  return ( a >= 0 ) ? ( a + 0xFFFFL ) & ~0xFFFFL
89  : -((-a + 0xFFFFL ) & ~0xFFFFL );
90  }
91 
92 
93  /* documentation is in freetype.h */
94 
97  {
98  return ( a >= 0 ) ? a & ~0xFFFFL
99  : -((-a) & ~0xFFFFL );
100  }
101 
102 
103  FT_BASE_DEF ( FT_Int )
105  {
106  FT_Int shift = 0;
107 
108  /* determine msb bit index in `shift' */
109  if ( z >= ( 1L << 16 ) )
110  {
111  z >>= 16;
112  shift += 16;
113  }
114  if ( z >= ( 1L << 8 ) )
115  {
116  z >>= 8;
117  shift += 8;
118  }
119  if ( z >= ( 1L << 4 ) )
120  {
121  z >>= 4;
122  shift += 4;
123  }
124  if ( z >= ( 1L << 2 ) )
125  {
126  z >>= 2;
127  shift += 2;
128  }
129  if ( z >= ( 1L << 1 ) )
130  {
131  z >>= 1;
132  shift += 1;
133  }
134 
135  return shift;
136  }
137 
138 
139  /* documentation is in ftcalc.h */
140 
143  FT_Fixed y )
144  {
145  FT_Vector v;
146 
147 
148  v.x = x;
149  v.y = y;
150 
151  return FT_Vector_Length( &v );
152  }
153 
154 
155 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
156 
157  /* documentation is in ftcalc.h */
158 
160  FT_Sqrt32( FT_Int32 x )
161  {
162  FT_UInt32 val, root, newroot, mask;
163 
164 
165  root = 0;
166  mask = (FT_UInt32)0x40000000UL;
167  val = (FT_UInt32)x;
168 
169  do
170  {
171  newroot = root + mask;
172  if ( newroot <= val )
173  {
174  val -= newroot;
175  root = newroot + mask;
176  }
177 
178  root >>= 1;
179  mask >>= 2;
180 
181  } while ( mask != 0 );
182 
183  return root;
184  }
185 
186 #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
187 
188 
189 #ifdef FT_LONG64
190 
191 
192  /* documentation is in freetype.h */
193 
196  FT_Long b,
197  FT_Long c )
198  {
199  FT_Int s;
200  FT_Long d;
201 
202 
203  s = 1;
204  if ( a < 0 ) { a = -a; s = -1; }
205  if ( b < 0 ) { b = -b; s = -s; }
206  if ( c < 0 ) { c = -c; s = -s; }
207 
208  d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
209  : 0x7FFFFFFFL );
210 
211  return ( s > 0 ) ? d : -d;
212  }
213 
214 
215  /* documentation is in ftcalc.h */
216 
219  FT_Long b,
220  FT_Long c )
221  {
222  FT_Int s;
223  FT_Long d;
224 
225 
226  s = 1;
227  if ( a < 0 ) { a = -a; s = -1; }
228  if ( b < 0 ) { b = -b; s = -s; }
229  if ( c < 0 ) { c = -c; s = -s; }
230 
231  d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c
232  : 0x7FFFFFFFL );
233 
234  return ( s > 0 ) ? d : -d;
235  }
236 
237 
238  /* documentation is in freetype.h */
239 
242  FT_Long b )
243  {
244 #ifdef FT_MULFIX_ASSEMBLER
245 
246  return FT_MULFIX_ASSEMBLER( a, b );
247 
248 #else
249 
250  FT_Int s = 1;
251  FT_Long c;
252 
253 
254  if ( a < 0 )
255  {
256  a = -a;
257  s = -1;
258  }
259 
260  if ( b < 0 )
261  {
262  b = -b;
263  s = -s;
264  }
265 
266  c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 );
267 
268  return ( s > 0 ) ? c : -c;
269 
270 #endif /* FT_MULFIX_ASSEMBLER */
271  }
272 
273 
274  /* documentation is in freetype.h */
275 
278  FT_Long b )
279  {
280  FT_Int32 s;
281  FT_UInt32 q;
282 
283 
284  s = 1;
285  if ( a < 0 )
286  {
287  a = -a;
288  s = -1;
289  }
290  if ( b < 0 )
291  {
292  b = -b;
293  s = -s;
294  }
295 
296  if ( b == 0 )
297  /* check for division by 0 */
298  q = 0x7FFFFFFFL;
299  else
300  /* compute result directly */
301  q = (FT_UInt32)( ( ( (FT_ULong)a << 16 ) + ( b >> 1 ) ) / b );
302 
303  return ( s < 0 ? -(FT_Long)q : (FT_Long)q );
304  }
305 
306 
307 #else /* !FT_LONG64 */
308 
309 
310  static void
311  ft_multo64( FT_UInt32 x,
312  FT_UInt32 y,
313  FT_Int64 *z )
314  {
315  FT_UInt32 lo1, hi1, lo2, hi2, lo, hi, i1, i2;
316 
317 
318  lo1 = x & 0x0000FFFFU; hi1 = x >> 16;
319  lo2 = y & 0x0000FFFFU; hi2 = y >> 16;
320 
321  lo = lo1 * lo2;
322  i1 = lo1 * hi2;
323  i2 = lo2 * hi1;
324  hi = hi1 * hi2;
325 
326  /* Check carry overflow of i1 + i2 */
327  i1 += i2;
328  hi += (FT_UInt32)( i1 < i2 ) << 16;
329 
330  hi += i1 >> 16;
331  i1 = i1 << 16;
332 
333  /* Check carry overflow of i1 + lo */
334  lo += i1;
335  hi += ( lo < i1 );
336 
337  z->lo = lo;
338  z->hi = hi;
339  }
340 
341 
342  static FT_UInt32
343  ft_div64by32( FT_UInt32 hi,
344  FT_UInt32 lo,
345  FT_UInt32 y )
346  {
347  FT_UInt32 r, q;
348  FT_Int i;
349 
350 
351  q = 0;
352  r = hi;
353 
354  if ( r >= y )
355  return (FT_UInt32)0x7FFFFFFFL;
356 
357  i = 32;
358  do
359  {
360  r <<= 1;
361  q <<= 1;
362  r |= lo >> 31;
363 
364  if ( r >= y )
365  {
366  r -= y;
367  q |= 1;
368  }
369  lo <<= 1;
370  } while ( --i );
371 
372  return q;
373  }
374 
375 
376  static void
377  FT_Add64( FT_Int64* x,
378  FT_Int64* y,
379  FT_Int64 *z )
380  {
381  register FT_UInt32 lo, hi;
382 
383 
384  lo = x->lo + y->lo;
385  hi = x->hi + y->hi + ( lo < x->lo );
386 
387  z->lo = lo;
388  z->hi = hi;
389  }
390 
391 
392  /* documentation is in freetype.h */
393 
394  /* The FT_MulDiv function has been optimized thanks to ideas from */
395  /* Graham Asher. The trick is to optimize computation when everything */
396  /* fits within 32-bits (a rather common case). */
397  /* */
398  /* we compute 'a*b+c/2', then divide it by 'c'. (positive values) */
399  /* */
400  /* 46340 is FLOOR(SQRT(2^31-1)). */
401  /* */
402  /* if ( a <= 46340 && b <= 46340 ) then ( a*b <= 0x7FFEA810 ) */
403  /* */
404  /* 0x7FFFFFFF - 0x7FFEA810 = 0x157F0 */
405  /* */
406  /* if ( c < 0x157F0*2 ) then ( a*b+c/2 <= 0x7FFFFFFF ) */
407  /* */
408  /* and 2*0x157F0 = 176096 */
409  /* */
410 
413  FT_Long b,
414  FT_Long c )
415  {
416  long s;
417 
418 
419  /* XXX: this function does not allow 64-bit arguments */
420  if ( a == 0 || b == c )
421  return a;
422 
423  s = a; a = FT_ABS( a );
424  s ^= b; b = FT_ABS( b );
425  s ^= c; c = FT_ABS( c );
426 
427  if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 )
428  a = ( a * b + ( c >> 1 ) ) / c;
429 
430  else if ( (FT_Int32)c > 0 )
431  {
432  FT_Int64 temp, temp2;
433 
434 
435  ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
436 
437  temp2.hi = 0;
438  temp2.lo = (FT_UInt32)(c >> 1);
439  FT_Add64( &temp, &temp2, &temp );
440  a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );
441  }
442  else
443  a = 0x7FFFFFFFL;
444 
445  return ( s < 0 ? -a : a );
446  }
447 
448 
451  FT_Long b,
452  FT_Long c )
453  {
454  long s;
455 
456 
457  if ( a == 0 || b == c )
458  return a;
459 
460  s = a; a = FT_ABS( a );
461  s ^= b; b = FT_ABS( b );
462  s ^= c; c = FT_ABS( c );
463 
464  if ( a <= 46340L && b <= 46340L && c > 0 )
465  a = a * b / c;
466 
467  else if ( (FT_Int32)c > 0 )
468  {
469  FT_Int64 temp;
470 
471 
472  ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
473  a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );
474  }
475  else
476  a = 0x7FFFFFFFL;
477 
478  return ( s < 0 ? -a : a );
479  }
480 
481 
482  /* documentation is in freetype.h */
483 
486  FT_Long b )
487  {
488 #ifdef FT_MULFIX_ASSEMBLER
489 
490  return FT_MULFIX_ASSEMBLER( a, b );
491 
492 #elif 0
493 
494  /*
495  * This code is nonportable. See comment below.
496  *
497  * However, on a platform where right-shift of a signed quantity fills
498  * the leftmost bits by copying the sign bit, it might be faster.
499  */
500 
501  FT_Long sa, sb;
502  FT_ULong ua, ub;
503 
504 
505  if ( a == 0 || b == 0x10000L )
506  return a;
507 
508  /*
509  * This is a clever way of converting a signed number `a' into its
510  * absolute value (stored back into `a') and its sign. The sign is
511  * stored in `sa'; 0 means `a' was positive or zero, and -1 means `a'
512  * was negative. (Similarly for `b' and `sb').
513  *
514  * Unfortunately, it doesn't work (at least not portably).
515  *
516  * It makes the assumption that right-shift on a negative signed value
517  * fills the leftmost bits by copying the sign bit. This is wrong.
518  * According to K&R 2nd ed, section `A7.8 Shift Operators' on page 206,
519  * the result of right-shift of a negative signed value is
520  * implementation-defined. At least one implementation fills the
521  * leftmost bits with 0s (i.e., it is exactly the same as an unsigned
522  * right shift). This means that when `a' is negative, `sa' ends up
523  * with the value 1 rather than -1. After that, everything else goes
524  * wrong.
525  */
526  sa = ( a >> ( sizeof ( a ) * 8 - 1 ) );
527  a = ( a ^ sa ) - sa;
528  sb = ( b >> ( sizeof ( b ) * 8 - 1 ) );
529  b = ( b ^ sb ) - sb;
530 
531  ua = (FT_ULong)a;
532  ub = (FT_ULong)b;
533 
534  if ( ua <= 2048 && ub <= 1048576L )
535  ua = ( ua * ub + 0x8000U ) >> 16;
536  else
537  {
538  FT_ULong al = ua & 0xFFFFU;
539 
540 
541  ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
542  ( ( al * ( ub & 0xFFFFU ) + 0x8000U ) >> 16 );
543  }
544 
545  sa ^= sb,
546  ua = (FT_ULong)(( ua ^ sa ) - sa);
547 
548  return (FT_Long)ua;
549 
550 #else /* 0 */
551 
552  FT_Long s;
553  FT_ULong ua, ub;
554 
555 
556  if ( a == 0 || b == 0x10000L )
557  return a;
558 
559  s = a; a = FT_ABS( a );
560  s ^= b; b = FT_ABS( b );
561 
562  ua = (FT_ULong)a;
563  ub = (FT_ULong)b;
564 
565  if ( ua <= 2048 && ub <= 1048576L )
566  ua = ( ua * ub + 0x8000UL ) >> 16;
567  else
568  {
569  FT_ULong al = ua & 0xFFFFUL;
570 
571 
572  ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
573  ( ( al * ( ub & 0xFFFFUL ) + 0x8000UL ) >> 16 );
574  }
575 
576  return ( s < 0 ? -(FT_Long)ua : (FT_Long)ua );
577 
578 #endif /* 0 */
579 
580  }
581 
582 
583  /* documentation is in freetype.h */
584 
587  FT_Long b )
588  {
589  FT_Int32 s;
590  FT_UInt32 q;
591 
592 
593  /* XXX: this function does not allow 64-bit arguments */
594  s = (FT_Int32)a; a = FT_ABS( a );
595  s ^= (FT_Int32)b; b = FT_ABS( b );
596 
597  if ( (FT_UInt32)b == 0 )
598  {
599  /* check for division by 0 */
600  q = (FT_UInt32)0x7FFFFFFFL;
601  }
602  else if ( ( a >> 16 ) == 0 )
603  {
604  /* compute result directly */
605  q = (FT_UInt32)( ( (FT_ULong)a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b;
606  }
607  else
608  {
609  /* we need more bits; we have to do it by hand */
610  FT_Int64 temp, temp2;
611 
612 
613  temp.hi = (FT_Int32)( a >> 16 );
614  temp.lo = (FT_UInt32)a << 16;
615  temp2.hi = 0;
616  temp2.lo = (FT_UInt32)( b >> 1 );
617  FT_Add64( &temp, &temp2, &temp );
618  q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );
619  }
620 
621  return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
622  }
623 
624 
625 #if 0
626 
627  /* documentation is in ftcalc.h */
628 
629  FT_EXPORT_DEF( void )
630  FT_MulTo64( FT_Int32 x,
631  FT_Int32 y,
632  FT_Int64 *z )
633  {
634  FT_Int32 s;
635 
636 
637  s = x; x = FT_ABS( x );
638  s ^= y; y = FT_ABS( y );
639 
640  ft_multo64( x, y, z );
641 
642  if ( s < 0 )
643  {
644  z->lo = (FT_UInt32)-(FT_Int32)z->lo;
645  z->hi = ~z->hi + !( z->lo );
646  }
647  }
648 
649 
650  /* apparently, the second version of this code is not compiled correctly */
651  /* on Mac machines with the MPW C compiler.. tsk, tsk, tsk... */
652 
653 #if 1
654 
656  FT_Div64by32( FT_Int64* x,
657  FT_Int32 y )
658  {
659  FT_Int32 s;
660  FT_UInt32 q, r, i, lo;
661 
662 
663  s = x->hi;
664  if ( s < 0 )
665  {
666  x->lo = (FT_UInt32)-(FT_Int32)x->lo;
667  x->hi = ~x->hi + !x->lo;
668  }
669  s ^= y; y = FT_ABS( y );
670 
671  /* Shortcut */
672  if ( x->hi == 0 )
673  {
674  if ( y > 0 )
675  q = x->lo / y;
676  else
677  q = 0x7FFFFFFFL;
678 
679  return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
680  }
681 
682  r = x->hi;
683  lo = x->lo;
684 
685  if ( r >= (FT_UInt32)y ) /* we know y is to be treated as unsigned here */
686  return ( s < 0 ? 0x80000001UL : 0x7FFFFFFFUL );
687  /* Return Max/Min Int32 if division overflow. */
688  /* This includes division by zero! */
689  q = 0;
690  for ( i = 0; i < 32; i++ )
691  {
692  r <<= 1;
693  q <<= 1;
694  r |= lo >> 31;
695 
696  if ( r >= (FT_UInt32)y )
697  {
698  r -= y;
699  q |= 1;
700  }
701  lo <<= 1;
702  }
703 
704  return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
705  }
706 
707 #else /* 0 */
708 
710  FT_Div64by32( FT_Int64* x,
711  FT_Int32 y )
712  {
713  FT_Int32 s;
714  FT_UInt32 q;
715 
716 
717  s = x->hi;
718  if ( s < 0 )
719  {
720  x->lo = (FT_UInt32)-(FT_Int32)x->lo;
721  x->hi = ~x->hi + !x->lo;
722  }
723  s ^= y; y = FT_ABS( y );
724 
725  /* Shortcut */
726  if ( x->hi == 0 )
727  {
728  if ( y > 0 )
729  q = ( x->lo + ( y >> 1 ) ) / y;
730  else
731  q = 0x7FFFFFFFL;
732 
733  return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
734  }
735 
736  q = ft_div64by32( x->hi, x->lo, y );
737 
738  return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
739  }
740 
741 #endif /* 0 */
742 
743 #endif /* 0 */
744 
745 
746 #endif /* FT_LONG64 */
747 
748 
749  /* documentation is in ftglyph.h */
750 
751  FT_EXPORT_DEF( void )
753  FT_Matrix *b )
754  {
755  FT_Fixed xx, xy, yx, yy;
756 
757 
758  if ( !a || !b )
759  return;
760 
761  xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );
762  xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );
763  yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );
764  yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );
765 
766  b->xx = xx; b->xy = xy;
767  b->yx = yx; b->yy = yy;
768  }
769 
770 
771  /* documentation is in ftglyph.h */
772 
775  {
776  FT_Pos delta, xx, yy;
777 
778 
779  if ( !matrix )
780  return FT_THROW( Invalid_Argument );
781 
782  /* compute discriminant */
783  delta = FT_MulFix( matrix->xx, matrix->yy ) -
784  FT_MulFix( matrix->xy, matrix->yx );
785 
786  if ( !delta )
787  return FT_THROW( Invalid_Argument ); /* matrix can't be inverted */
788 
789  matrix->xy = - FT_DivFix( matrix->xy, delta );
790  matrix->yx = - FT_DivFix( matrix->yx, delta );
791 
792  xx = matrix->xx;
793  yy = matrix->yy;
794 
795  matrix->xx = FT_DivFix( yy, delta );
796  matrix->yy = FT_DivFix( xx, delta );
797 
798  return FT_Err_Ok;
799  }
800 
801 
802  /* documentation is in ftcalc.h */
803 
804  FT_BASE_DEF( void )
806  FT_Matrix *b,
807  FT_Long scaling )
808  {
809  FT_Fixed xx, xy, yx, yy;
810 
811  FT_Long val = 0x10000L * scaling;
812 
813 
814  if ( !a || !b )
815  return;
816 
817  xx = FT_MulDiv( a->xx, b->xx, val ) + FT_MulDiv( a->xy, b->yx, val );
818  xy = FT_MulDiv( a->xx, b->xy, val ) + FT_MulDiv( a->xy, b->yy, val );
819  yx = FT_MulDiv( a->yx, b->xx, val ) + FT_MulDiv( a->yy, b->yx, val );
820  yy = FT_MulDiv( a->yx, b->xy, val ) + FT_MulDiv( a->yy, b->yy, val );
821 
822  b->xx = xx; b->xy = xy;
823  b->yx = yx; b->yy = yy;
824  }
825 
826 
827  /* documentation is in ftcalc.h */
828 
829  FT_BASE_DEF( void )
832  FT_Long scaling )
833  {
834  FT_Pos xz, yz;
835 
836  FT_Long val = 0x10000L * scaling;
837 
838 
839  if ( !vector || !matrix )
840  return;
841 
842  xz = FT_MulDiv( vector->x, matrix->xx, val ) +
843  FT_MulDiv( vector->y, matrix->xy, val );
844 
845  yz = FT_MulDiv( vector->x, matrix->yx, val ) +
846  FT_MulDiv( vector->y, matrix->yy, val );
847 
848  vector->x = xz;
849  vector->y = yz;
850  }
851 
852 
853  /* documentation is in ftcalc.h */
854 
857  {
858  FT_UInt32 root, rem_hi, rem_lo, test_div;
859  FT_Int count;
860 
861 
862  root = 0;
863 
864  if ( x > 0 )
865  {
866  rem_hi = 0;
867  rem_lo = x;
868  count = 24;
869  do
870  {
871  rem_hi = ( rem_hi << 2 ) | ( rem_lo >> 30 );
872  rem_lo <<= 2;
873  root <<= 1;
874  test_div = ( root << 1 ) + 1;
875 
876  if ( rem_hi >= test_div )
877  {
878  rem_hi -= test_div;
879  root += 1;
880  }
881  } while ( --count );
882  }
883 
884  return (FT_Int32)root;
885  }
886 
887 
888  /* documentation is in ftcalc.h */
889 
892  FT_Pos in_y,
893  FT_Pos out_x,
894  FT_Pos out_y )
895  {
896  FT_Long result; /* avoid overflow on 16-bit system */
897 
898 
899  /* deal with the trivial cases quickly */
900  if ( in_y == 0 )
901  {
902  if ( in_x >= 0 )
903  result = out_y;
904  else
905  result = -out_y;
906  }
907  else if ( in_x == 0 )
908  {
909  if ( in_y >= 0 )
910  result = -out_x;
911  else
912  result = out_x;
913  }
914  else if ( out_y == 0 )
915  {
916  if ( out_x >= 0 )
917  result = in_y;
918  else
919  result = -in_y;
920  }
921  else if ( out_x == 0 )
922  {
923  if ( out_y >= 0 )
924  result = -in_x;
925  else
926  result = in_x;
927  }
928  else /* general case */
929  {
930 #ifdef FT_LONG64
931 
932  FT_Int64 delta = (FT_Int64)in_x * out_y - (FT_Int64)in_y * out_x;
933 
934 
935  if ( delta == 0 )
936  result = 0;
937  else
938  result = 1 - 2 * ( delta < 0 );
939 
940 #else
941 
942  FT_Int64 z1, z2;
943 
944 
945  /* XXX: this function does not allow 64-bit arguments */
946  ft_multo64( (FT_Int32)in_x, (FT_Int32)out_y, &z1 );
947  ft_multo64( (FT_Int32)in_y, (FT_Int32)out_x, &z2 );
948 
949  if ( z1.hi > z2.hi )
950  result = +1;
951  else if ( z1.hi < z2.hi )
952  result = -1;
953  else if ( z1.lo > z2.lo )
954  result = +1;
955  else if ( z1.lo < z2.lo )
956  result = -1;
957  else
958  result = 0;
959 
960 #endif
961  }
962 
963  /* XXX: only the sign of return value, +1/0/-1 must be used */
964  return (FT_Int)result;
965  }
966 
967 
968  /* documentation is in ftcalc.h */
969 
972  FT_Pos in_y,
973  FT_Pos out_x,
974  FT_Pos out_y )
975  {
976  FT_Pos ax = in_x;
977  FT_Pos ay = in_y;
978 
979  FT_Pos d_in, d_out, d_corner;
980 
981 
982  if ( ax < 0 )
983  ax = -ax;
984  if ( ay < 0 )
985  ay = -ay;
986  d_in = ax + ay;
987 
988  ax = out_x;
989  if ( ax < 0 )
990  ax = -ax;
991  ay = out_y;
992  if ( ay < 0 )
993  ay = -ay;
994  d_out = ax + ay;
995 
996  ax = out_x + in_x;
997  if ( ax < 0 )
998  ax = -ax;
999  ay = out_y + in_y;
1000  if ( ay < 0 )
1001  ay = -ay;
1002  d_corner = ax + ay;
1003 
1004  return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
1005  }
1006 
1007 
1008 /* END */
FT_Matrix_Multiply_Scaled(const FT_Matrix *a, FT_Matrix *b, FT_Long scaling)
Definition: ftcalc.c:805
int FT_Error
Definition: fttypes.h:296
FT_Matrix_Multiply(const FT_Matrix *a, FT_Matrix *b)
Definition: ftcalc.c:752
FT_DivFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:586
signed long FT_Long
Definition: fttypes.h:238
unsigned long FT_ULong
Definition: fttypes.h:249
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:59
ft_corner_orientation(FT_Pos in_x, FT_Pos in_y, FT_Pos out_x, FT_Pos out_y)
Definition: ftcalc.c:891
GLboolean GLboolean GLboolean GLboolean a
FT_FloorFix(FT_Fixed a)
Definition: ftcalc.c:96
GLint GLint GLint GLint GLint GLint y
signed int FT_Int
Definition: fttypes.h:216
GLdouble GLdouble GLdouble GLdouble q
FT_MulDiv_No_Round(FT_Long a, FT_Long b, FT_Long c)
Definition: ftcalc.c:450
#define FT_ABS(a)
Definition: ftobjs.h:73
FT_CeilFix(FT_Fixed a)
Definition: ftcalc.c:86
return FT_THROW(Missing_Property)
unsigned int FT_UInt32
Definition: ftconfig.h:133
GLint GLint GLint GLint GLint x
return FT_Err_Ok
Definition: ftbbox.c:645
GLboolean GLboolean GLboolean b
png_uint_32 i
Definition: png.h:2640
#define const
Definition: zconf.h:91
#define FT_BASE_DEF(x)
Definition: ftconfig.h:258
GLdouble GLdouble z
ft_corner_is_flat(FT_Pos in_x, FT_Pos in_y, FT_Pos out_x, FT_Pos out_y)
Definition: ftcalc.c:971
FT_Vector_Transform_Scaled(FT_Vector *vector, const FT_Matrix *matrix, FT_Long scaling)
Definition: ftcalc.c:830
GLenum GLint GLuint mask
#define FT_EXPORT_DEF(x)
Definition: ftconfig.h:32
const GLdouble * v
FT_Pos x
Definition: ftimage.h:77
GLdouble GLdouble GLdouble r
FT_Matrix_Invert(FT_Matrix *matrix)
Definition: ftcalc.c:774
FT_Hypot(FT_Fixed x, FT_Fixed y)
Definition: ftcalc.c:142
FT_Pos y
Definition: ftimage.h:78
GLuint GLfloat * val
const GLubyte * c
local int root
Definition: enough.c:171
signed int FT_Int32
Definition: ftconfig.h:132
signed long FT_Fixed
Definition: fttypes.h:284
GLuint64EXT * result
FT_SqrtFixed(FT_Int32 x)
Definition: ftcalc.c:856
GLdouble s
FT_Vector_Length(FT_Vector *vec)
Definition: fttrigon.c:400
FT_RoundFix(FT_Fixed a)
Definition: ftcalc.c:76
GLuint GLuint GLsizei count
FT_MulDiv(FT_Long a, FT_Long b, FT_Long c)
Definition: ftcalc.c:412
struct FT_Int64_ FT_Int64
FT_MulFix(FT_Long a, FT_Long b)
Definition: ftcalc.c:485
FT_MSB(FT_UInt32 z)
Definition: ftcalc.c:104
GLuint GLenum matrix