* include/freetype/ftbbox.h: FTBBOX_H -> __FTBBOX_H__.
* include/freetype/fttrigon.h: __FT_TRIGONOMETRY_H__ -> __FTTRIGON_H__. Include FT_FREETYPE_H. Beautified; added copyright. * src/base/fttrigon.c: Beautified; added copyright.
This commit is contained in:
parent
3bf46a41b9
commit
c634580a51
|
@ -1,3 +1,12 @@
|
||||||
|
2001-05-12 Werner Lemberg <wl@gnu.org>
|
||||||
|
|
||||||
|
* include/freetype/ftbbox.h: FTBBOX_H -> __FTBBOX_H__.
|
||||||
|
* include/freetype/fttrigon.h: __FT_TRIGONOMETRY_H__ ->
|
||||||
|
__FTTRIGON_H__.
|
||||||
|
Include FT_FREETYPE_H.
|
||||||
|
Beautified; added copyright.
|
||||||
|
* src/base/fttrigon.c: Beautified; added copyright.
|
||||||
|
|
||||||
2001-05-11 David Turner <david@freetype.org>
|
2001-05-11 David Turner <david@freetype.org>
|
||||||
|
|
||||||
* src/cff/cffparse.c (cff_parse_font_matrix), src/cid/cidload.c
|
* src/cff/cffparse.c (cff_parse_font_matrix), src/cid/cidload.c
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef FTBBOX_H
|
#ifndef __FTBBOX_H__
|
||||||
#define FTBBOX_H
|
#define __FTBBOX_H__
|
||||||
|
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
|
@ -76,7 +76,7 @@ FT_BEGIN_HEADER
|
||||||
|
|
||||||
FT_END_HEADER
|
FT_END_HEADER
|
||||||
|
|
||||||
#endif /* FTBBOX_H */
|
#endif /* __FTBBOX_H__ */
|
||||||
|
|
||||||
|
|
||||||
/* END */
|
/* END */
|
||||||
|
|
|
@ -1,213 +1,265 @@
|
||||||
#ifndef __FT_TRIGONOMETRY_H__
|
/***************************************************************************/
|
||||||
#define __FT_TRIGONOMETRY_H__
|
/* */
|
||||||
|
/* fttrigon.h */
|
||||||
|
/* */
|
||||||
|
/* FreeType trigonometric functions (specification). */
|
||||||
|
/* */
|
||||||
|
/* Copyright 2001 by */
|
||||||
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||||
|
/* */
|
||||||
|
/* This file is part of the FreeType project, and may only be used, */
|
||||||
|
/* modified, and distributed under the terms of the FreeType project */
|
||||||
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||||
|
/* this file you indicate that you have read the license and */
|
||||||
|
/* understand and accept it fully. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __FTTRIGON_H__
|
||||||
|
#define __FTTRIGON_H__
|
||||||
|
|
||||||
|
#include FT_FREETYPE_H
|
||||||
|
|
||||||
|
|
||||||
FT_BEGIN_HEADER
|
FT_BEGIN_HEADER
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @section: computations
|
* @section:
|
||||||
|
* computations
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @type: FT_Angle
|
* @type:
|
||||||
|
* FT_Angle
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* this type is used to model angle values in FreeType. Note that
|
* This type is used to model angle values in FreeType. Note that
|
||||||
* the angle is a 16.16 fixed float value expressed in _degrees_
|
* the angle is a 16.16 fixed float value expressed in degrees.
|
||||||
*/
|
*/
|
||||||
typedef FT_Fixed FT_Angle;
|
typedef FT_Fixed FT_Angle;
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @macro: FT_ANGLE_PI
|
* @macro:
|
||||||
|
* FT_ANGLE_PI
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* the angle pi expressed in @FT_Angle units
|
* The angle pi expressed in @FT_Angle units.
|
||||||
*/
|
*/
|
||||||
#define FT_ANGLE_PI (180L << 16)
|
#define FT_ANGLE_PI ( 180L << 16 )
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @macro: FT_ANGLE_2PI
|
* @macro:
|
||||||
|
* FT_ANGLE_2PI
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* the angle 2pi expressed in @FT_Angle units
|
* The angle 2*pi expressed in @FT_Angle units.
|
||||||
*/
|
*/
|
||||||
#define FT_ANGLE_2PI (FT_ANGLE_PI*2)
|
#define FT_ANGLE_2PI ( FT_ANGLE_PI * 2 )
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @macro: FT_ANGLE_PI2
|
* @macro:
|
||||||
|
* FT_ANGLE_PI2
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* the angle pi/2 expressed in @FT_Angle units
|
* The angle pi/2 expressed in @FT_Angle units.
|
||||||
*/
|
*/
|
||||||
#define FT_ANGLE_PI2 (FT_ANGLE_PI/2)
|
#define FT_ANGLE_PI2 ( FT_ANGLE_PI / 2 )
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @macro: FT_ANGLE_PI4
|
* @macro:
|
||||||
|
* FT_ANGLE_PI4
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* the angle pi/4 expressed in @FT_Angle units
|
* The angle pi/4 expressed in @FT_Angle units.
|
||||||
*/
|
*/
|
||||||
#define FT_ANGLE_PI4 (FT_ANGLE_PI/4)
|
#define FT_ANGLE_PI4 ( FT_ANGLE_PI / 4 )
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Sin
|
* @function:
|
||||||
|
* FT_Sin
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* return the sinus of a given angle in fixed point format
|
* Return the sinus of a given angle in fixed point format.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* angle :: input angle
|
* angle :: The input angle.
|
||||||
*
|
*
|
||||||
* @return:
|
* @return:
|
||||||
* sinus value
|
* The sinus value.
|
||||||
*
|
*
|
||||||
* @note:
|
* @note:
|
||||||
* if you need both the sinus and cosinus for a given angle, you'd
|
* If you need both the sinus and cosinus for a given angle, use the
|
||||||
* better use the function @FT_Vector_Unit
|
* function @FT_Vector_Unit.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(FT_Fixed) FT_Sin( FT_Angle angle );
|
FT_EXPORT( FT_Fixed ) FT_Sin( FT_Angle angle );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Cos
|
* @function:
|
||||||
|
* FT_Cos
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* return the cosinus of a given angle in fixed point format
|
* Return the cosinus of a given angle in fixed point format.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* angle :: input angle
|
* angle :: The input angle.
|
||||||
*
|
*
|
||||||
* @return:
|
* @return:
|
||||||
* cosinus value
|
* The cosinus value.
|
||||||
*
|
*
|
||||||
* @note:
|
* @note:
|
||||||
* if you need both the sinus and cosinus for a given angle, you'd
|
* If you need both the sinus and cosinus for a given angle, use the
|
||||||
* better use the function @FT_Vector_Unit
|
* function @FT_Vector_Unit.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(FT_Fixed) FT_Cos( FT_Angle angle );
|
FT_EXPORT( FT_Fixed ) FT_Cos( FT_Angle angle );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Tan
|
* @function:
|
||||||
|
* FT_Tan
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* return the tangent of a given angle in fixed point format
|
* Return the tangent of a given angle in fixed point format.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* angle :: input angle
|
* angle :: The input angle.
|
||||||
*
|
*
|
||||||
* @return:
|
* @return:
|
||||||
* tangent value
|
* The tangent value.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(FT_Fixed) FT_Tan( FT_Angle angle );
|
FT_EXPORT( FT_Fixed ) FT_Tan( FT_Angle angle );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Atan2
|
* @function:
|
||||||
|
* FT_Atan2
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* return the arc-tangent corresponding to a given vector (x,y) in
|
* Return the arc-tangent corresponding to a given vector (x,y) in
|
||||||
* the 2d plane
|
* the 2d plane.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* x :: horizontal vector coordinate
|
* x :: The horizontal vector coordinate.
|
||||||
* y :: vertical vector coordinate
|
* y :: The vertical vector coordinate.
|
||||||
*
|
*
|
||||||
* @return:
|
* @return:
|
||||||
* arc-tangent value (i.e. angle)
|
* The arc-tangent value (i.e. angle).
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(FT_Angle) FT_Atan2( FT_Fixed x, FT_Fixed y );
|
FT_EXPORT( FT_Angle ) FT_Atan2( FT_Fixed x, FT_Fixed y );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Vector_Unit
|
* @function:
|
||||||
|
* FT_Vector_Unit
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* return the unit vector corresponding to a given angle. After the call,
|
* Return the unit vector corresponding to a given angle. After the call,
|
||||||
* the value of "vec.x" will be "sin(theta)", and the value of "vec.y"
|
* the value of "vec.x" will be "sin(theta)", and the value of "vec.y"
|
||||||
* will be "cos(angle)"
|
* will be "cos(angle)".
|
||||||
*
|
*
|
||||||
* this function is useful to retrieve both the sinus and cosinus
|
* This function is useful to retrieve both the sinus and cosinus of a
|
||||||
* of a given angle quickly
|
* given angle quickly.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* vec :: address of target vector
|
* vec :: The address of target vector.
|
||||||
* angle :: address of angle
|
* angle :: The address of angle.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(void) FT_Vector_Unit( FT_Vector* vec,
|
FT_EXPORT( void ) FT_Vector_Unit( FT_Vector* vec,
|
||||||
FT_Angle angle );
|
FT_Angle angle );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Vector_Rotate
|
* @function:
|
||||||
|
* FT_Vector_Rotate
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* rotate a given vector by a given angle
|
* Rotate a vector by a given angle.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* vec :: address of target vector
|
* vec :: The address of target vector.
|
||||||
* angle :: address of angle
|
* angle :: The address of angle.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(void) FT_Vector_Rotate( FT_Vector* vec,
|
FT_EXPORT( void ) FT_Vector_Rotate( FT_Vector* vec,
|
||||||
FT_Angle angle );
|
FT_Angle angle );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Vector_Length
|
* @function:
|
||||||
|
* FT_Vector_Length
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* returns the length of a given vector
|
* Return the length of a given vector.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* vec :: address of target vector
|
* vec :: The address of target vector.
|
||||||
*
|
*
|
||||||
* @return:
|
* @return:
|
||||||
* vector length, expressed in the same units that the original
|
* The vector length, expressed in the same units that the original
|
||||||
* vector coordinates !!
|
* vector coordinates.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(FT_Fixed) FT_Vector_Length( FT_Vector* vec );
|
FT_EXPORT( FT_Fixed ) FT_Vector_Length( FT_Vector* vec );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Vector_Normalize
|
* @function:
|
||||||
|
* FT_Vector_Normalize
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* normalize a given vector (i.e. compute the equivalent unit vector)
|
* Normalize a given vector (i.e. compute the equivalent unit vector).
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* vec :: address of target vector
|
* vec :: The address of target vector.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(void) FT_Vector_Normalize( FT_Vector* vec );
|
FT_EXPORT( void ) FT_Vector_Normalize( FT_Vector* vec );
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
*
|
*
|
||||||
* @function: FT_Vector_Polarize
|
* @function:
|
||||||
|
* FT_Vector_Polarize
|
||||||
*
|
*
|
||||||
* @description:
|
* @description:
|
||||||
* compute both the length and angle of a given vector
|
* Compute both the length and angle of a given vector.
|
||||||
*
|
*
|
||||||
* @input:
|
* @input:
|
||||||
* vec :: address of source vector
|
* vec :: The address of source vector.
|
||||||
*
|
*
|
||||||
* @output:
|
* @output:
|
||||||
* length :: vector length
|
* length :: The vector length.
|
||||||
* angle :: vector angle
|
* angle :: The vector angle.
|
||||||
*/
|
*/
|
||||||
FT_EXPORT(void) FT_Vector_Polarize( FT_Vector* vec,
|
FT_EXPORT( void ) FT_Vector_Polarize( FT_Vector* vec,
|
||||||
FT_Fixed *length,
|
FT_Fixed *length,
|
||||||
FT_Angle *angle );
|
FT_Angle *angle );
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
|
|
||||||
FT_END_HEADER
|
FT_END_HEADER
|
||||||
|
|
||||||
#endif /* __FT_TRIGONOMETRY_H__ */
|
#endif /* __FTTRIGON_H__ */
|
||||||
|
|
||||||
|
|
||||||
|
/* END */
|
||||||
|
|
|
@ -1,70 +1,89 @@
|
||||||
|
/***************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* fttrigon.c */
|
||||||
|
/* */
|
||||||
|
/* FreeType trigonometric functions (body). */
|
||||||
|
/* */
|
||||||
|
/* Copyright 2001 by */
|
||||||
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
||||||
|
/* */
|
||||||
|
/* This file is part of the FreeType project, and may only be used, */
|
||||||
|
/* modified, and distributed under the terms of the FreeType project */
|
||||||
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||||
|
/* this file you indicate that you have read the license and */
|
||||||
|
/* understand and accept it fully. */
|
||||||
|
/* */
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_TRIGONOMETRY_H
|
#include FT_TRIGONOMETRY_H
|
||||||
|
|
||||||
/* the following is 0.2715717684432231 * 2^30 */
|
|
||||||
#define FT_TRIG_COSCALE 0x11616E8E /* 291597966 = 0.2715717684432241 * 2^30, valid for j>13 */
|
/* the following is 0.2715717684432231 * 2^30 */
|
||||||
|
#define FT_TRIG_COSCALE 0x11616E8EUL
|
||||||
|
|
||||||
/* this table was generated for FT_PI = 180L << 16, i.e. degrees */
|
/* this table was generated for FT_PI = 180L << 16, i.e. degrees */
|
||||||
#define FT_TRIG_MAX_ITERS 23
|
#define FT_TRIG_MAX_ITERS 23
|
||||||
|
|
||||||
static const FT_Fixed
|
static const FT_Fixed
|
||||||
ft_trig_arctan_table[ 24 ] =
|
ft_trig_arctan_table[24] =
|
||||||
{
|
{
|
||||||
4157273, 2949120, 1740967, 919879, 466945, 234379, 117304, 58666,
|
4157273, 2949120, 1740967, 919879, 466945, 234379, 117304, 58666,
|
||||||
29335, 14668, 7334, 3667, 1833, 917, 458, 229, 115, 57, 29, 14, 7,
|
29335, 14668, 7334, 3667, 1833, 917, 458, 229, 115, 57, 29, 14, 7,
|
||||||
4, 2, 1
|
4, 2, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* the Cordic shrink factor, multiplied by 2^32 */
|
||||||
|
#define FT_TRIG_SCALE 1166391785UL /* 0x4585BA38UL */
|
||||||
|
|
||||||
/* the Cordic shrink factor, multiplied by 2^32 */
|
|
||||||
#define FT_TRIG_SCALE 1166391785 /* 0x4585BA38U */
|
|
||||||
|
|
||||||
#ifdef FT_CONFIG_HAS_INT64
|
#ifdef FT_CONFIG_HAS_INT64
|
||||||
|
|
||||||
/* multiply a given value by the CORDIC shrink factor */
|
/* multiply a given value by the CORDIC shrink factor */
|
||||||
static FT_Fixed
|
static FT_Fixed ft_trig_downscale( FT_Fixed val )
|
||||||
ft_trig_downscale( FT_Fixed val )
|
|
||||||
{
|
{
|
||||||
FT_Fixed s;
|
FT_Fixed s;
|
||||||
FT_Int64 v;
|
FT_Int64 v;
|
||||||
|
|
||||||
|
|
||||||
s = val;
|
s = val;
|
||||||
val = (val >= 0) ? val : -val;
|
val = ( val >= 0 ) ? val : -val;
|
||||||
|
|
||||||
v = (val * (FT_Int64)FT_TRIG_SCALE) + 0x100000000L;
|
v = ( val * (FT_Int64)FT_TRIG_SCALE ) + 0x100000000UL;
|
||||||
val = (FT_Fixed)(v >> 32);
|
val = (FT_Fixed)( v >> 32 );
|
||||||
|
|
||||||
return ( s >= 0 ) ? val : -val;
|
return ( s >= 0 ) ? val : -val;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* !FT_CONFIG_HAS_INT64 */
|
#else /* !FT_CONFIG_HAS_INT64 */
|
||||||
|
|
||||||
/* multiply a given value by the CORDIC shrink factor */
|
/* multiply a given value by the CORDIC shrink factor */
|
||||||
static FT_Fixed
|
static FT_Fixed ft_trig_downscale( FT_Fixed val )
|
||||||
ft_trig_downscale( FT_Fixed val )
|
|
||||||
{
|
{
|
||||||
FT_Fixed s;
|
FT_Fixed s;
|
||||||
FT_UInt32 v1, v2, k1, k2, hi, lo1, lo2, lo3;
|
FT_UInt32 v1, v2, k1, k2, hi, lo1, lo2, lo3;
|
||||||
|
|
||||||
|
|
||||||
s = val;
|
s = val;
|
||||||
val = ( val >= 0 ) ? val : -val;
|
val = ( val >= 0 ) ? val : -val;
|
||||||
|
|
||||||
v1 = (FT_UInt32)val >> 16;
|
v1 = (FT_UInt32)val >> 16;
|
||||||
v2 = (FT_UInt32)val & 0xFFFF;
|
v2 = (FT_UInt32)val & 0xFFFF;
|
||||||
|
|
||||||
k1 = FT_TRIG_SCALE >> 16; /* constant */
|
k1 = FT_TRIG_SCALE >> 16; /* constant */
|
||||||
k2 = FT_TRIG_SCALE & 0xFFFF; /* constant */
|
k2 = FT_TRIG_SCALE & 0xFFFF; /* constant */
|
||||||
|
|
||||||
hi = k1*v1;
|
hi = k1 * v1;
|
||||||
lo1 = k1*v2 + k2*v1; /* can't overflow */
|
lo1 = k1 * v2 + k2 * v1; /* can't overflow */
|
||||||
|
|
||||||
lo2 = k2*v2 >> 16;
|
lo2 = ( k2 * v2 ) >> 16;
|
||||||
lo3 = ( lo1 >= lo2 ) ? lo1 : lo2;
|
lo3 = ( lo1 >= lo2 ) ? lo1 : lo2;
|
||||||
lo1 += lo2;
|
lo1 += lo2;
|
||||||
|
|
||||||
hi += lo1 >> 16;
|
hi += lo1 >> 16;
|
||||||
if (lo1 < lo3)
|
if ( lo1 < lo3 )
|
||||||
hi += 0x10000U;
|
hi += 0x10000UL;
|
||||||
|
|
||||||
val = (FT_Fixed)hi;
|
val = (FT_Fixed)hi;
|
||||||
|
|
||||||
|
@ -74,67 +93,65 @@
|
||||||
#endif /* !FT_CONFIG_HAS_INT64 */
|
#endif /* !FT_CONFIG_HAS_INT64 */
|
||||||
|
|
||||||
|
|
||||||
static FT_Int
|
static FT_Int ft_trig_prenorm( FT_Vector* vec )
|
||||||
ft_trig_prenorm( FT_Vector* vec )
|
|
||||||
{
|
{
|
||||||
FT_Fixed x, y, z;
|
FT_Fixed x, y, z;
|
||||||
FT_Int shift;
|
FT_Int shift;
|
||||||
|
|
||||||
|
|
||||||
x = vec->x;
|
x = vec->x;
|
||||||
y = vec->y;
|
y = vec->y;
|
||||||
|
|
||||||
z = (( x >= 0 ) ? x : - x) | ((y >= 0) ? y : -y);
|
z = ( ( x >= 0 ) ? x : - x ) | ( (y >= 0) ? y : -y );
|
||||||
shift = 0;
|
shift = 0;
|
||||||
|
|
||||||
if ( z < (1L << 27) )
|
if ( z < ( 1L << 27 ) )
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
shift++;
|
shift++;
|
||||||
z <<= 1;
|
z <<= 1;
|
||||||
}
|
} while ( z < ( 1L << 27 ) );
|
||||||
while ( z < (1L << 27) );
|
|
||||||
|
|
||||||
vec->x = (x << shift);
|
vec->x = x << shift;
|
||||||
vec->y = (y << shift);
|
vec->y = y << shift;
|
||||||
}
|
}
|
||||||
else if ( z > (1L << 28 ) )
|
else if ( z > ( 1L << 28 ) )
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
shift++;
|
shift++;
|
||||||
z >>= 1;
|
z >>= 1;
|
||||||
}
|
} while ( z > ( 1L << 28 ) );
|
||||||
while ( z > (1L << 28) );
|
|
||||||
|
|
||||||
vec->x = (x >> shift);
|
vec->x = x >> shift;
|
||||||
vec->y = (y >> shift);
|
vec->y = y >> shift;
|
||||||
shift = -shift;
|
shift = -shift;
|
||||||
}
|
}
|
||||||
return shift;
|
return shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void ft_trig_pseudo_rotate( FT_Vector* vec,
|
||||||
static void
|
FT_Angle theta )
|
||||||
ft_trig_pseudo_rotate( FT_Vector* vec, FT_Angle theta )
|
|
||||||
{
|
{
|
||||||
FT_Int i;
|
FT_Int i;
|
||||||
FT_Fixed x, y, xtemp;
|
FT_Fixed x, y, xtemp;
|
||||||
const FT_Fixed *arctanptr;
|
const FT_Fixed *arctanptr;
|
||||||
|
|
||||||
|
|
||||||
x = vec->x;
|
x = vec->x;
|
||||||
y = vec->y;
|
y = vec->y;
|
||||||
|
|
||||||
/* Get angle between -90 and 90 degrees */
|
/* Get angle between -90 and 90 degrees */
|
||||||
while (theta <= -FT_ANGLE_PI2)
|
while ( theta <= -FT_ANGLE_PI2 )
|
||||||
{
|
{
|
||||||
x = -x;
|
x = -x;
|
||||||
y = -y;
|
y = -y;
|
||||||
theta += FT_ANGLE_PI;
|
theta += FT_ANGLE_PI;
|
||||||
}
|
}
|
||||||
while (theta > FT_ANGLE_PI2)
|
|
||||||
|
while ( theta > FT_ANGLE_PI2 )
|
||||||
{
|
{
|
||||||
x = -x;
|
x = -x;
|
||||||
y = -y;
|
y = -y;
|
||||||
|
@ -143,17 +160,18 @@
|
||||||
|
|
||||||
/* Initial pseudorotation, with left shift */
|
/* Initial pseudorotation, with left shift */
|
||||||
arctanptr = ft_trig_arctan_table;
|
arctanptr = ft_trig_arctan_table;
|
||||||
if (theta < 0)
|
|
||||||
|
if ( theta < 0 )
|
||||||
{
|
{
|
||||||
xtemp = x + (y << 1);
|
xtemp = x + ( y << 1 );
|
||||||
y = y - (x << 1);
|
y = y - ( x << 1 );
|
||||||
x = xtemp;
|
x = xtemp;
|
||||||
theta += *arctanptr++;
|
theta += *arctanptr++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xtemp = x - (y << 1);
|
xtemp = x - ( y << 1 );
|
||||||
y = y + (x << 1);
|
y = y + ( x << 1 );
|
||||||
x = xtemp;
|
x = xtemp;
|
||||||
theta -= *arctanptr++;
|
theta -= *arctanptr++;
|
||||||
}
|
}
|
||||||
|
@ -162,90 +180,89 @@
|
||||||
i = 0;
|
i = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (theta < 0)
|
if ( theta < 0 )
|
||||||
{
|
{
|
||||||
xtemp = x + (y >> i);
|
xtemp = x + ( y >> i );
|
||||||
y = y - (x >> i);
|
y = y - ( x >> i );
|
||||||
x = xtemp;
|
x = xtemp;
|
||||||
theta += *arctanptr++;
|
theta += *arctanptr++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
xtemp = x - (y >> i);
|
xtemp = x - ( y >> i );
|
||||||
y = y + (x >> i);
|
y = y + ( x >> i );
|
||||||
x = xtemp;
|
x = xtemp;
|
||||||
theta -= *arctanptr++;
|
theta -= *arctanptr++;
|
||||||
}
|
}
|
||||||
}
|
} while ( ++i < FT_TRIG_MAX_ITERS );
|
||||||
while ( ++i < FT_TRIG_MAX_ITERS );
|
|
||||||
|
|
||||||
vec->x = x;
|
vec->x = x;
|
||||||
vec->y = y;
|
vec->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void ft_trig_pseudo_polarize( FT_Vector* vec )
|
||||||
ft_trig_pseudo_polarize( FT_Vector* vec )
|
|
||||||
{
|
{
|
||||||
FT_Fixed theta;
|
FT_Fixed theta;
|
||||||
FT_Fixed yi, i;
|
FT_Fixed yi, i;
|
||||||
FT_Fixed x, y;
|
FT_Fixed x, y;
|
||||||
const FT_Fixed *arctanptr;
|
const FT_Fixed *arctanptr;
|
||||||
|
|
||||||
|
|
||||||
x = vec->x;
|
x = vec->x;
|
||||||
y = vec->y;
|
y = vec->y;
|
||||||
|
|
||||||
/* Get the vector into the right half plane */
|
/* Get the vector into the right half plane */
|
||||||
theta = 0;
|
theta = 0;
|
||||||
if (x < 0)
|
if ( x < 0 )
|
||||||
{
|
{
|
||||||
x = -x;
|
x = -x;
|
||||||
y = -y;
|
y = -y;
|
||||||
theta = 2 * FT_ANGLE_PI2;
|
theta = 2 * FT_ANGLE_PI2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y > 0)
|
if ( y > 0 )
|
||||||
theta = - theta;
|
theta = - theta;
|
||||||
|
|
||||||
arctanptr = ft_trig_arctan_table;
|
arctanptr = ft_trig_arctan_table;
|
||||||
if (y < 0)
|
|
||||||
|
if ( y < 0 )
|
||||||
{
|
{
|
||||||
/* Rotate positive */
|
/* Rotate positive */
|
||||||
yi = y + (x << 1);
|
yi = y + ( x << 1 );
|
||||||
x = x - (y << 1);
|
x = x - ( y << 1 );
|
||||||
y = yi;
|
y = yi;
|
||||||
theta -= *arctanptr++; /* Subtract angle */
|
theta -= *arctanptr++; /* Subtract angle */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Rotate negative */
|
/* Rotate negative */
|
||||||
yi = y - (x << 1);
|
yi = y - ( x << 1 );
|
||||||
x = x + (y << 1);
|
x = x + ( y << 1 );
|
||||||
y = yi;
|
y = yi;
|
||||||
theta += *arctanptr++; /* Add angle */
|
theta += *arctanptr++; /* Add angle */
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (y < 0)
|
if ( y < 0 )
|
||||||
{
|
{
|
||||||
/* Rotate positive */
|
/* Rotate positive */
|
||||||
yi = y + (x >> i);
|
yi = y + ( x >> i );
|
||||||
x = x - (y >> i);
|
x = x - ( y >> i );
|
||||||
y = yi;
|
y = yi;
|
||||||
theta -= *arctanptr++;
|
theta -= *arctanptr++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Rotate negative */
|
/* Rotate negative */
|
||||||
yi = y - (x >> i);
|
yi = y - ( x >> i );
|
||||||
x = x + (y >> i);
|
x = x + ( y >> i );
|
||||||
y = yi;
|
y = yi;
|
||||||
theta += *arctanptr++;
|
theta += *arctanptr++;
|
||||||
}
|
}
|
||||||
}
|
} while ( ++i < FT_TRIG_MAX_ITERS );
|
||||||
while (++i < FT_TRIG_MAX_ITERS);
|
|
||||||
|
|
||||||
/* round theta */
|
/* round theta */
|
||||||
if ( theta >= 0 )
|
if ( theta >= 0 )
|
||||||
|
@ -258,11 +275,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(FT_Fixed)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Cos( FT_Angle angle )
|
|
||||||
|
FT_EXPORT_DEF( FT_Fixed ) FT_Cos( FT_Angle angle )
|
||||||
{
|
{
|
||||||
FT_Vector v;
|
FT_Vector v;
|
||||||
|
|
||||||
|
|
||||||
v.x = FT_TRIG_COSCALE >> 2;
|
v.x = FT_TRIG_COSCALE >> 2;
|
||||||
v.y = 0;
|
v.y = 0;
|
||||||
ft_trig_pseudo_rotate( &v, angle );
|
ft_trig_pseudo_rotate( &v, angle );
|
||||||
|
@ -271,18 +290,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(FT_Fixed)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Sin( FT_Angle angle )
|
|
||||||
|
FT_EXPORT_DEF( FT_Fixed ) FT_Sin( FT_Angle angle )
|
||||||
{
|
{
|
||||||
return FT_Cos( FT_ANGLE_PI2-angle );
|
return FT_Cos( FT_ANGLE_PI2 - angle );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(FT_Fixed)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Tan( FT_Angle angle )
|
|
||||||
|
FT_EXPORT_DEF( FT_Fixed ) FT_Tan( FT_Angle angle )
|
||||||
{
|
{
|
||||||
FT_Vector v;
|
FT_Vector v;
|
||||||
|
|
||||||
|
|
||||||
v.x = FT_TRIG_COSCALE >> 2;
|
v.x = FT_TRIG_COSCALE >> 2;
|
||||||
v.y = 0;
|
v.y = 0;
|
||||||
ft_trig_pseudo_rotate( &v, angle );
|
ft_trig_pseudo_rotate( &v, angle );
|
||||||
|
@ -291,13 +313,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* documentation is in fttrigon.h */
|
||||||
|
|
||||||
FT_EXPORT_DEF(FT_Angle)
|
FT_EXPORT_DEF( FT_Angle ) FT_Atan2( FT_Fixed dx,
|
||||||
FT_Atan2( FT_Fixed dx,
|
FT_Fixed dy )
|
||||||
FT_Fixed dy )
|
|
||||||
{
|
{
|
||||||
FT_Vector v;
|
FT_Vector v;
|
||||||
|
|
||||||
|
|
||||||
if ( dx == 0 && dy == 0 )
|
if ( dx == 0 && dy == 0 )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -305,31 +328,36 @@
|
||||||
v.y = dy;
|
v.y = dy;
|
||||||
ft_trig_prenorm( &v );
|
ft_trig_prenorm( &v );
|
||||||
ft_trig_pseudo_polarize( &v );
|
ft_trig_pseudo_polarize( &v );
|
||||||
|
|
||||||
return v.y;
|
return v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(void)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Vector_Unit( FT_Vector* vec,
|
|
||||||
FT_Angle angle )
|
FT_EXPORT_DEF( void ) FT_Vector_Unit( FT_Vector* vec,
|
||||||
|
FT_Angle angle )
|
||||||
{
|
{
|
||||||
vec->x = FT_TRIG_COSCALE >> 2;
|
vec->x = FT_TRIG_COSCALE >> 2;
|
||||||
vec->y = 0;
|
vec->y = 0;
|
||||||
ft_trig_pseudo_rotate( vec, angle );
|
ft_trig_pseudo_rotate( vec, angle );
|
||||||
vec->x >>= 12;
|
vec->x >>= 12;
|
||||||
vec->y >>= 12;
|
vec->y >>= 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(void)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Vector_Rotate( FT_Vector* vec,
|
|
||||||
FT_Angle angle )
|
FT_EXPORT_DEF( void ) FT_Vector_Rotate( FT_Vector* vec,
|
||||||
|
FT_Angle angle )
|
||||||
{
|
{
|
||||||
FT_Int shift;
|
FT_Int shift;
|
||||||
FT_Vector v;
|
FT_Vector v;
|
||||||
|
|
||||||
|
|
||||||
v.x = vec->x;
|
v.x = vec->x;
|
||||||
v.y = vec->y;
|
v.y = vec->y;
|
||||||
|
|
||||||
if ( angle && ( v.x != 0 || v.y != 0 ) )
|
if ( angle && ( v.x != 0 || v.y != 0 ) )
|
||||||
{
|
{
|
||||||
shift = ft_trig_prenorm( &v );
|
shift = ft_trig_prenorm( &v );
|
||||||
|
@ -352,12 +380,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(FT_Fixed)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Vector_Length( FT_Vector* vec )
|
|
||||||
|
FT_EXPORT_DEF( FT_Fixed ) FT_Vector_Length( FT_Vector* vec )
|
||||||
{
|
{
|
||||||
FT_Int shift;
|
FT_Int shift;
|
||||||
FT_Vector v;
|
FT_Vector v;
|
||||||
|
|
||||||
|
|
||||||
v = *vec;
|
v = *vec;
|
||||||
|
|
||||||
/* handle trivial cases */
|
/* handle trivial cases */
|
||||||
|
@ -375,17 +405,19 @@
|
||||||
ft_trig_pseudo_polarize( &v );
|
ft_trig_pseudo_polarize( &v );
|
||||||
|
|
||||||
v.x = ft_trig_downscale( v.x );
|
v.x = ft_trig_downscale( v.x );
|
||||||
return ( shift >= 0 ) ? (v.x >> shift) : (v.x << -shift);
|
return ( shift >= 0 ) ? ( v.x >> shift ) : ( v.x << -shift );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_EXPORT_DEF(void)
|
/* documentation is in fttrigon.h */
|
||||||
FT_Vector_Polarize( FT_Vector* vec,
|
|
||||||
FT_Fixed *length,
|
FT_EXPORT_DEF( void ) FT_Vector_Polarize( FT_Vector* vec,
|
||||||
FT_Angle *angle )
|
FT_Fixed *length,
|
||||||
|
FT_Angle *angle )
|
||||||
{
|
{
|
||||||
FT_Int shift;
|
FT_Int shift;
|
||||||
FT_Vector v;
|
FT_Vector v;
|
||||||
|
|
||||||
|
|
||||||
v = *vec;
|
v = *vec;
|
||||||
|
|
||||||
|
@ -397,8 +429,9 @@
|
||||||
|
|
||||||
v.x = ft_trig_downscale( v.x );
|
v.x = ft_trig_downscale( v.x );
|
||||||
|
|
||||||
*length = ( shift >= 0 ) ? (v.x >> shift) : (v.x << -shift);
|
*length = ( shift >= 0 ) ? ( v.x >> shift ) : ( v.x << -shift );
|
||||||
*angle = v.y;
|
*angle = v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* END */
|
||||||
|
|
Loading…
Reference in New Issue