misc/libfreetype/src/tools/test_trig.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
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
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
#include FT_TRIGONOMETRY_H
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
#include <math.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
#include <stdio.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
#define  PI   3.14159265358979323846
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
#define  SPI  (PI/FT_ANGLE_PI)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/* the precision in 16.16 fixed float points of the checks. Expect */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/* between 2 and 5 noise LSB bits during operations, due to        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/* rounding errors..                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
#define  THRESHOLD  64
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
  static  error = 0;
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
  test_cos( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
    FT_Fixed  f1, f2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
    double    d1, d2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
    int       i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
    for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
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
      f1 = FT_Cos(i);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
      d1 = f1/65536.0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
      d2 = cos( i*SPI );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
      f2 = (FT_Fixed)(d2*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
      if ( abs( f2-f1 ) > THRESHOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
        error = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
        printf( "FT_Cos[%3d] = %.7f  cos[%3d] = %.7f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
                (i >> 16), f1/65536.0, (i >> 16), d2 );
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  test_sin( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_Fixed  f1, f2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    double    d1, d2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    int       i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
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
      f1 = FT_Sin(i);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
      d1 = f1/65536.0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
      d2 = sin( i*SPI );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
      f2 = (FT_Fixed)(d2*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
      if ( abs( f2-f1 ) > THRESHOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
        error = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
        printf( "FT_Sin[%3d] = %.7f  sin[%3d] = %.7f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
                (i >> 16), f1/65536.0, (i >> 16), d2 );
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  test_tan( void )
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
    FT_Fixed  f1, f2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    double    d1, d2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    int       i;
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
    for ( i = 0; i < FT_ANGLE_PI2-0x2000000; i += 0x10000 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
      f1 = FT_Tan(i);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      d1 = f1/65536.0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
      d2 = tan( i*SPI );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      f2 = (FT_Fixed)(d2*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      if ( abs( f2-f1 ) > THRESHOLD )
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
        error = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
        printf( "FT_Tan[%3d] = %.7f  tan[%3d] = %.7f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
                (i >> 16), f1/65536.0, (i >> 16), d2 );
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
  test_atan2( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    FT_Fixed  c2, s2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    double    l, a, c1, s1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    int       i, j;
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
    for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
      l  = 5.0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      a  = i*SPI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
      c1 = l * cos(a);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
      s1 = l * sin(a);
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
      c2 = (FT_Fixed)(c1*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
      s2 = (FT_Fixed)(s1*65536.0);
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
      j  = FT_Atan2( c2, s2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
      if ( j < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
        j += FT_ANGLE_2PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      if ( abs( i - j ) > 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
        printf( "FT_Atan2( %.7f, %.7f ) = %.5f, atan = %.5f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
                c2/65536.0, s2/65536.0, j/65536.0, i/65536.0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
      }
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
  }
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  test_unit( void )
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
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    double     a, c1, s1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    FT_Fixed   c2, s2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    int        i;
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
    for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
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
      FT_Vector_Unit( &v, i );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
      a  = ( i*SPI );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
      c1 = cos(a);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      s1 = sin(a);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      c2 = (FT_Fixed)(c1*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      s2 = (FT_Fixed)(s1*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
      if ( abs( v.x-c2 ) > THRESHOLD ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
           abs( v.y-s2 ) > THRESHOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
        error = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
        printf( "FT_Vector_Unit[%3d] = ( %.7f, %.7f )  vec = ( %.7f, %.7f )\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
                (i >> 16),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
                v.x/65536.0, v.y/65536.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
                c1, s1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      }
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
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
  test_length( void )
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
    FT_Vector  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    FT_Fixed   l, l2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    int        i;
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
    for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
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
      l   = (FT_Fixed)(500.0*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      v.x = (FT_Fixed)( l * cos( i*SPI ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      v.y = (FT_Fixed)( l * sin( i*SPI ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      l2  = FT_Vector_Length( &v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      if ( abs( l2-l ) > THRESHOLD )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
        error = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
        printf( "FT_Length( %.7f, %.7f ) = %.5f, length = %.5f\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
                v.x/65536.0, v.y/65536.0, l2/65536.0, l/65536.0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
  test_rotate( void )
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
    FT_Fixed  c2, s2, c4, s4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    FT_Vector v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    double    l, ra, a, c1, s1, cra, sra, c3, s3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
    int       i, j, rotate;
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
    for ( rotate = 0; rotate < FT_ANGLE_2PI; rotate += 0x10000 )
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
      ra  = rotate*SPI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
      cra = cos( ra );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
      sra = sin( ra );
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
      for ( i = 0; i < FT_ANGLE_2PI; i += 0x10000 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
        l  = 500.0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
        a  = i*SPI;
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
        c1 = l * cos(a);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        s1 = l * sin(a);
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
        v.x = c2 = (FT_Fixed)(c1*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
        v.y = s2 = (FT_Fixed)(s1*65536.0);
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
        FT_Vector_Rotate( &v, rotate );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        c3 = c1 * cra - s1 * sra;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
        s3 = c1 * sra + s1 * cra;
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
        c4 = (FT_Fixed)(c3*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
        s4 = (FT_Fixed)(s3*65536.0);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
        if ( abs( c4 - v.x ) > THRESHOLD ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
             abs( s4 - v.y ) > THRESHOLD )
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
          error = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
          printf( "FT_Rotate( (%.7f,%.7f), %.5f ) = ( %.7f, %.7f ), rot = ( %.7f, %.7f )\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
                  c1, s1, ra,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
                  c2/65536.0, s2/65536.0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
                  c4/65536.0, s4/65536.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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
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
  int main( void )
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
    test_cos();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    test_sin();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
    test_tan();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
    test_atan2();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    test_unit();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    test_length();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    test_rotate();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    if (!error)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      printf( "trigonometry test ok !\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    return !error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
  }