src/java.desktop/share/native/libfreetype/src/base/fttrigon.c
changeset 54876 da3834261f0c
parent 49234 3375a8039fde
equal deleted inserted replaced
54875:bcfedddcf4ce 54876:da3834261f0c
     1 /***************************************************************************/
     1 /****************************************************************************
     2 /*                                                                         */
     2  *
     3 /*  fttrigon.c                                                             */
     3  * fttrigon.c
     4 /*                                                                         */
     4  *
     5 /*    FreeType trigonometric functions (body).                             */
     5  *   FreeType trigonometric functions (body).
     6 /*                                                                         */
     6  *
     7 /*  Copyright 2001-2018 by                                                 */
     7  * Copyright (C) 2001-2019 by
     8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
     8  * David Turner, Robert Wilhelm, and Werner Lemberg.
     9 /*                                                                         */
     9  *
    10 /*  This file is part of the FreeType project, and may only be used,       */
    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      */
    11  * modified, and distributed under the terms of the FreeType project
    12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
    12  * license, LICENSE.TXT.  By continuing to use, modify, or distribute
    13 /*  this file you indicate that you have read the license and              */
    13  * this file you indicate that you have read the license and
    14 /*  understand and accept it fully.                                        */
    14  * understand and accept it fully.
    15 /*                                                                         */
    15  *
    16 /***************************************************************************/
    16  */
    17 
    17 
    18   /*************************************************************************/
    18   /**************************************************************************
    19   /*                                                                       */
    19    *
    20   /* This is a fixed-point CORDIC implementation of trigonometric          */
    20    * This is a fixed-point CORDIC implementation of trigonometric
    21   /* functions as well as transformations between Cartesian and polar      */
    21    * functions as well as transformations between Cartesian and polar
    22   /* coordinates.  The angles are represented as 16.16 fixed-point values  */
    22    * coordinates.  The angles are represented as 16.16 fixed-point values
    23   /* in degrees, i.e., the angular resolution is 2^-16 degrees.  Note that */
    23    * in degrees, i.e., the angular resolution is 2^-16 degrees.  Note that
    24   /* only vectors longer than 2^16*180/pi (or at least 22 bits) on a       */
    24    * only vectors longer than 2^16*180/pi (or at least 22 bits) on a
    25   /* discrete Cartesian grid can have the same or better angular           */
    25    * discrete Cartesian grid can have the same or better angular
    26   /* resolution.  Therefore, to maintain this precision, some functions    */
    26    * resolution.  Therefore, to maintain this precision, some functions
    27   /* require an interim upscaling of the vectors, whereas others operate   */
    27    * require an interim upscaling of the vectors, whereas others operate
    28   /* with 24-bit long vectors directly.                                    */
    28    * with 24-bit long vectors directly.
    29   /*                                                                       */
    29    *
    30   /*************************************************************************/
    30    */
    31 
    31 
    32 #include <ft2build.h>
    32 #include <ft2build.h>
    33 #include FT_INTERNAL_OBJECTS_H
    33 #include FT_INTERNAL_OBJECTS_H
    34 #include FT_INTERNAL_CALC_H
    34 #include FT_INTERNAL_CALC_H
    35 #include FT_TRIGONOMETRY_H
    35 #include FT_TRIGONOMETRY_H
   323   /* documentation is in fttrigon.h */
   323   /* documentation is in fttrigon.h */
   324 
   324 
   325   FT_EXPORT_DEF( FT_Fixed )
   325   FT_EXPORT_DEF( FT_Fixed )
   326   FT_Tan( FT_Angle  angle )
   326   FT_Tan( FT_Angle  angle )
   327   {
   327   {
   328     FT_Vector  v;
   328     FT_Vector  v = { 1 << 24, 0 };
   329 
   329 
   330 
   330 
   331     FT_Vector_Unit( &v, angle );
   331     ft_trig_pseudo_rotate( &v, angle );
   332 
   332 
   333     return FT_DivFix( v.y, v.x );
   333     return FT_DivFix( v.y, v.x );
   334   }
   334   }
   335 
   335 
   336 
   336 
   370     vec->x = ( vec->x + 0x80L ) >> 8;
   370     vec->x = ( vec->x + 0x80L ) >> 8;
   371     vec->y = ( vec->y + 0x80L ) >> 8;
   371     vec->y = ( vec->y + 0x80L ) >> 8;
   372   }
   372   }
   373 
   373 
   374 
   374 
   375   /* these macros return 0 for positive numbers,
       
   376      and -1 for negative ones */
       
   377 #define FT_SIGN_LONG( x )   ( (x) >> ( FT_SIZEOF_LONG * 8 - 1 ) )
       
   378 #define FT_SIGN_INT( x )    ( (x) >> ( FT_SIZEOF_INT * 8 - 1 ) )
       
   379 #define FT_SIGN_INT32( x )  ( (x) >> 31 )
       
   380 #define FT_SIGN_INT16( x )  ( (x) >> 15 )
       
   381 
       
   382 
       
   383   /* documentation is in fttrigon.h */
   375   /* documentation is in fttrigon.h */
   384 
   376 
   385   FT_EXPORT_DEF( void )
   377   FT_EXPORT_DEF( void )
   386   FT_Vector_Rotate( FT_Vector*  vec,
   378   FT_Vector_Rotate( FT_Vector*  vec,
   387                     FT_Angle    angle )
   379                     FT_Angle    angle )
   406     if ( shift > 0 )
   398     if ( shift > 0 )
   407     {
   399     {
   408       FT_Int32  half = (FT_Int32)1L << ( shift - 1 );
   400       FT_Int32  half = (FT_Int32)1L << ( shift - 1 );
   409 
   401 
   410 
   402 
   411       vec->x = ( v.x + half + FT_SIGN_LONG( v.x ) ) >> shift;
   403       vec->x = ( v.x + half - ( v.x < 0 ) ) >> shift;
   412       vec->y = ( v.y + half + FT_SIGN_LONG( v.y ) ) >> shift;
   404       vec->y = ( v.y + half - ( v.y < 0 ) ) >> shift;
   413     }
   405     }
   414     else
   406     else
   415     {
   407     {
   416       shift  = -shift;
   408       shift  = -shift;
   417       vec->x = (FT_Pos)( (FT_ULong)v.x << shift );
   409       vec->x = (FT_Pos)( (FT_ULong)v.x << shift );