misc/libfreetype/src/base/fttrigon.c
author Xeli
Fri, 24 Jun 2011 13:13:31 +0200
branchhedgeroid
changeset 5347 a34995ecf90e
parent 5172 88f2e05288ba
permissions -rw-r--r--
Added test parameter which end up at hwengine::Game(PChar)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  fttrigon.c                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType trigonometric functions (body).                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2001, 2002, 2003, 2004, 2005 by                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_TRIGONOMETRY_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /* the following is 0.2715717684432231 * 2^30 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#define FT_TRIG_COSCALE  0x11616E8EUL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  /* this table was generated for FT_PI = 180L << 16, i.e. degrees */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#define FT_TRIG_MAX_ITERS  23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  static const FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  ft_trig_arctan_table[24] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    4157273L, 2949120L, 1740967L, 919879L, 466945L, 234379L, 117304L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
    58666L, 29335L, 14668L, 7334L, 3667L, 1833L, 917L, 458L, 229L, 115L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    57L, 29L, 14L, 7L, 4L, 2L, 1L
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /* the Cordic shrink factor, multiplied by 2^32 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#define FT_TRIG_SCALE    1166391785UL  /* 0x4585BA38UL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#ifdef FT_CONFIG_HAS_INT64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /* multiply a given value by the CORDIC shrink factor */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  ft_trig_downscale( FT_Fixed  val )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    FT_Fixed  s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_Int64  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    s   = val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    val = ( val >= 0 ) ? val : -val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    v   = ( val * (FT_Int64)FT_TRIG_SCALE ) + 0x100000000UL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    val = (FT_Fixed)( v >> 32 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    return ( s >= 0 ) ? val : -val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
#else /* !FT_CONFIG_HAS_INT64 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  /* multiply a given value by the CORDIC shrink factor */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  ft_trig_downscale( FT_Fixed  val )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    FT_Fixed   s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    FT_UInt32  v1, v2, k1, k2, hi, lo1, lo2, lo3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    s   = val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    val = ( val >= 0 ) ? val : -val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    v1 = (FT_UInt32)val >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    v2 = (FT_UInt32)(val & 0xFFFFL);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    k1 = (FT_UInt32)FT_TRIG_SCALE >> 16;       /* constant */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    k2 = (FT_UInt32)(FT_TRIG_SCALE & 0xFFFFL);   /* constant */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    hi   = k1 * v1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    lo1  = k1 * v2 + k2 * v1;       /* can't overflow */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    lo2  = ( k2 * v2 ) >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    lo3  = ( lo1 >= lo2 ) ? lo1 : lo2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    lo1 += lo2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    hi  += lo1 >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    if ( lo1 < lo3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      hi += (FT_UInt32)0x10000UL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    val  = (FT_Fixed)hi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    return ( s >= 0 ) ? val : -val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
#endif /* !FT_CONFIG_HAS_INT64 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  static FT_Int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
  ft_trig_prenorm( FT_Vector*  vec )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    FT_Fixed  x, y, z;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    FT_Int    shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    y = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    z     = ( ( x >= 0 ) ? x : - x ) | ( (y >= 0) ? y : -y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    shift = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    /* determine msb bit index in `shift' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    if ( z >= ( 1L << 16 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
      z     >>= 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      shift  += 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    if ( z >= ( 1L << 8 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      z     >>= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      shift  += 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    if ( z >= ( 1L << 4 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      z     >>= 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      shift  += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    if ( z >= ( 1L << 2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
      z     >>= 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
      shift  += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    if ( z >= ( 1L << 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      z    >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
      shift += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    if ( shift <= 27 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      shift  = 27 - shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
      vec->x = x << shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
      vec->y = y << shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
      shift -= 27;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      vec->x = x >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
      vec->y = y >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
      shift  = -shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
#else /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    if ( z < ( 1L << 27 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
        shift++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
        z <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      } while ( z < ( 1L << 27 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      vec->x = x << shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      vec->y = y << shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    else if ( z > ( 1L << 28 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
        shift++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
        z >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      } while ( z > ( 1L << 28 ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      vec->x = x >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      vec->y = y >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      shift  = -shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    return shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  ft_trig_pseudo_rotate( FT_Vector*  vec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
                         FT_Angle    theta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
    FT_Int           i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    FT_Fixed         x, y, xtemp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    const FT_Fixed  *arctanptr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    y = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    /* Get angle between -90 and 90 degrees */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    while ( theta <= -FT_ANGLE_PI2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
      x = -x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      y = -y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      theta += FT_ANGLE_PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    while ( theta > FT_ANGLE_PI2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      x = -x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
      y = -y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      theta -= FT_ANGLE_PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
    /* Initial pseudorotation, with left shift */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
    arctanptr = ft_trig_arctan_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    if ( theta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      xtemp  = x + ( y << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
      y      = y - ( x << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
      x      = xtemp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      theta += *arctanptr++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      xtemp  = x - ( y << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      y      = y + ( x << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      x      = xtemp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      theta -= *arctanptr++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    /* Subsequent pseudorotations, with right shifts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    i = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
      if ( theta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
        xtemp  = x + ( y >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
        y      = y - ( x >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        x      = xtemp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
        theta += *arctanptr++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        xtemp  = x - ( y >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
        y      = y + ( x >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
        x      = xtemp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
        theta -= *arctanptr++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    } while ( ++i < FT_TRIG_MAX_ITERS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    vec->x = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    vec->y = y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
  ft_trig_pseudo_polarize( FT_Vector*  vec )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
    FT_Fixed         theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
    FT_Fixed         yi, i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    FT_Fixed         x, y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    const FT_Fixed  *arctanptr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    x = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    y = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    /* Get the vector into the right half plane */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    theta = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    if ( x < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      x = -x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      y = -y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      theta = 2 * FT_ANGLE_PI2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    if ( y > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
      theta = - theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
    arctanptr = ft_trig_arctan_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    if ( y < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
      /* Rotate positive */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
      yi     = y + ( x << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      x      = x - ( y << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
      y      = yi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
      theta -= *arctanptr++;  /* Subtract angle */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
      /* Rotate negative */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      yi     = y - ( x << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      x      = x + ( y << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      y      = yi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      theta += *arctanptr++;  /* Add angle */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    i = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      if ( y < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
        /* Rotate positive */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
        yi     = y + ( x >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
        x      = x - ( y >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        y      = yi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
        theta -= *arctanptr++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        /* Rotate negative */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
        yi     = y - ( x >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
        x      = x + ( y >> i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
        y      = yi;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
        theta += *arctanptr++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    } while ( ++i < FT_TRIG_MAX_ITERS );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
    /* round theta */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
    if ( theta >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
      theta = FT_PAD_ROUND( theta, 32 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
      theta = -FT_PAD_ROUND( -theta, 32 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    vec->x = x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    vec->y = theta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  FT_Cos( FT_Angle  angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
    v.x = FT_TRIG_COSCALE >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
    v.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
    ft_trig_pseudo_rotate( &v, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    return v.x / ( 1 << 12 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
  FT_Sin( FT_Angle  angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    return FT_Cos( FT_ANGLE_PI2 - angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  FT_Tan( FT_Angle  angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    v.x = FT_TRIG_COSCALE >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    v.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    ft_trig_pseudo_rotate( &v, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    return FT_DivFix( v.y, v.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  FT_EXPORT_DEF( FT_Angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  FT_Atan2( FT_Fixed  dx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
            FT_Fixed  dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    if ( dx == 0 && dy == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    v.x = dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    v.y = dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    ft_trig_prenorm( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    ft_trig_pseudo_polarize( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    return v.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
  FT_Vector_Unit( FT_Vector*  vec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
                  FT_Angle    angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
    vec->x = FT_TRIG_COSCALE >> 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    vec->y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
    ft_trig_pseudo_rotate( vec, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
    vec->x >>= 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    vec->y >>= 12;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
  /* these macros return 0 for positive numbers,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
     and -1 for negative ones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
#define FT_SIGN_LONG( x )   ( (x) >> ( FT_SIZEOF_LONG * 8 - 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
#define FT_SIGN_INT( x )    ( (x) >> ( FT_SIZEOF_INT * 8 - 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
#define FT_SIGN_INT32( x )  ( (x) >> 31 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
#define FT_SIGN_INT16( x )  ( (x) >> 15 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
  FT_Vector_Rotate( FT_Vector*  vec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
                    FT_Angle    angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    FT_Int     shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    v.x   = vec->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    v.y   = vec->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
    if ( angle && ( v.x != 0 || v.y != 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      shift = ft_trig_prenorm( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      ft_trig_pseudo_rotate( &v, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      v.x = ft_trig_downscale( v.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
      v.y = ft_trig_downscale( v.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      if ( shift > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        FT_Int32  half = (FT_Int32)1L << ( shift - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
        vec->x = ( v.x + half + FT_SIGN_LONG( v.x ) ) >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        vec->y = ( v.y + half + FT_SIGN_LONG( v.y ) ) >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
        shift  = -shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        vec->x = v.x << shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
        vec->y = v.y << shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
  FT_EXPORT_DEF( FT_Fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
  FT_Vector_Length( FT_Vector*  vec )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
    FT_Int     shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
    v = *vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
    /* handle trivial cases */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    if ( v.x == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
      return ( v.y >= 0 ) ? v.y : -v.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
    else if ( v.y == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
      return ( v.x >= 0 ) ? v.x : -v.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    /* general case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
    shift = ft_trig_prenorm( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
    ft_trig_pseudo_polarize( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
    v.x = ft_trig_downscale( v.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    if ( shift > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      return ( v.x + ( 1 << ( shift - 1 ) ) ) >> shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    return v.x << -shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
  FT_Vector_Polarize( FT_Vector*  vec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
                      FT_Fixed   *length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
                      FT_Angle   *angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    FT_Int     shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    v = *vec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    if ( v.x == 0 && v.y == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    shift = ft_trig_prenorm( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
    ft_trig_pseudo_polarize( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    v.x = ft_trig_downscale( v.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
    *length = ( shift >= 0 ) ? ( v.x >> shift ) : ( v.x << -shift );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    *angle  = v.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
  FT_EXPORT_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
  FT_Vector_From_Polar( FT_Vector*  vec,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
                        FT_Fixed    length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
                        FT_Angle    angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    vec->x = length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
    vec->y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
    FT_Vector_Rotate( vec, angle );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
  /* documentation is in fttrigon.h */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
  FT_EXPORT_DEF( FT_Angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
  FT_Angle_Diff( FT_Angle  angle1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
                 FT_Angle  angle2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    FT_Angle  delta = angle2 - angle1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    delta %= FT_ANGLE_2PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
    if ( delta < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
      delta += FT_ANGLE_2PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    if ( delta > FT_ANGLE_PI )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
      delta -= FT_ANGLE_2PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    return delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
/* END */