misc/libfreetype/src/autofit/afangles.c
author nemo
Thu, 28 Feb 2013 23:15:33 -0500
changeset 8617 e7bea88096d2
parent 5172 88f2e05288ba
permissions -rw-r--r--
So. A while ago, while trying to prevent hogs blowtorching getting turned around, unc0rr altered the old range of blowtorch from 1/8th of 180° up or down, to a 4° gain in upwards and a -4° loss in downwards. He also made it so that starting tunnels could fail to erase sufficient terrain, trapping hogs. Here are a couple of workarounds to more closely approximate old behaviour (do some initial erasure, adjust min/max angles)
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
/*  afangles.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
/*    Routines used to compute vector angles with limited accuracy         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*    and very high speed.  It also contains sorting routines (body).      */
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
/*  Copyright 2003-2006, 2011 by                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
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
/*  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
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  understand and accept it fully.                                        */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "aftypes.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
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
#if 0
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
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
  af_corner_is_flat( FT_Pos  x_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
                     FT_Pos  y_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
                     FT_Pos  x_out,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
                     FT_Pos  y_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
    FT_Pos  ax = x_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
    FT_Pos  ay = y_in;
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
    FT_Pos  d_in, d_out, d_corner;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
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
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
    d_in = ax + ay;
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
    ax = x_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    ay = y_out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    d_out = ax + ay;
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
    ax = x_out + x_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    ay = y_out + y_in;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
      ay = -ay;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    d_corner = ax + ay;
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
    return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
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
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
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
  af_corner_orientation( FT_Pos  x_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
                         FT_Pos  y_in,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
                         FT_Pos  x_out,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
                         FT_Pos  y_out )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    FT_Pos  delta;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    delta = x_in * y_out - y_in * x_out;
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
    if ( delta == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      return 1 - 2 * ( delta < 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  }
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
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
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
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
   *  We are not using `af_angle_atan' anymore, but we keep the source
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
   *  code below just in case...
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
#if 0
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
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
   *  The trick here is to realize that we don't need a very accurate angle
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
   *  approximation.  We are going to use the result of `af_angle_atan' to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
   *  only compare the sign of angle differences, or check whether its
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
   *  magnitude is very small.
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
   *  The approximation
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
   *    dy * PI / (|dx|+|dy|)
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
   *  should be enough, and much faster to compute.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
  FT_LOCAL_DEF( AF_Angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  af_angle_atan( FT_Fixed  dx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
                 FT_Fixed  dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    AF_Angle  angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    FT_Fixed  ax = dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    FT_Fixed  ay = dy;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    if ( ax < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      ax = -ax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    if ( ay < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
      ay = -ay;
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
    ax += ay;
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
    if ( ax == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      angle = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    else
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
      angle = ( AF_ANGLE_PI2 * dy ) / ( ax + ay );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      if ( dx < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
        if ( angle >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
          angle = AF_ANGLE_PI - angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
          angle = -AF_ANGLE_PI - angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    }
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
    return angle;
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
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
#elif 0
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
  /* the following table has been automatically generated with */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  /* the `mather.py' Python script                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
#define AF_ATAN_BITS  8
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
  static const FT_Byte  af_arctan[1L << AF_ATAN_BITS] =
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
     0,  0,  1,  1,  1,  2,  2,  2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
     3,  3,  3,  3,  4,  4,  4,  5,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
     5,  5,  6,  6,  6,  7,  7,  7,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
     8,  8,  8,  9,  9,  9, 10, 10,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    10, 10, 11, 11, 11, 12, 12, 12,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    13, 13, 13, 14, 14, 14, 14, 15,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    15, 15, 16, 16, 16, 17, 17, 17,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    18, 18, 18, 18, 19, 19, 19, 20,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    20, 20, 21, 21, 21, 21, 22, 22,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    22, 23, 23, 23, 24, 24, 24, 24,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    25, 25, 25, 26, 26, 26, 26, 27,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    27, 27, 28, 28, 28, 28, 29, 29,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    29, 30, 30, 30, 30, 31, 31, 31,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    31, 32, 32, 32, 33, 33, 33, 33,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    34, 34, 34, 34, 35, 35, 35, 35,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    36, 36, 36, 36, 37, 37, 37, 38,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    38, 38, 38, 39, 39, 39, 39, 40,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    40, 40, 40, 41, 41, 41, 41, 42,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    42, 42, 42, 42, 43, 43, 43, 43,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    44, 44, 44, 44, 45, 45, 45, 45,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
    46, 46, 46, 46, 46, 47, 47, 47,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
    47, 48, 48, 48, 48, 48, 49, 49,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    49, 49, 50, 50, 50, 50, 50, 51,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    51, 51, 51, 51, 52, 52, 52, 52,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    52, 53, 53, 53, 53, 53, 54, 54,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    54, 54, 54, 55, 55, 55, 55, 55,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    56, 56, 56, 56, 56, 57, 57, 57,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    57, 57, 57, 58, 58, 58, 58, 58,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    59, 59, 59, 59, 59, 59, 60, 60,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    60, 60, 60, 61, 61, 61, 61, 61,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    61, 62, 62, 62, 62, 62, 62, 63,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
    63, 63, 63, 63, 63, 64, 64, 64
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
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
  FT_LOCAL_DEF( AF_Angle )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  af_angle_atan( FT_Fixed  dx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
                 FT_Fixed  dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    AF_Angle  angle;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    /* check trivial cases */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    if ( dy == 0 )
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
      angle = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      if ( dx < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        angle = AF_ANGLE_PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
      return angle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    else if ( dx == 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
      angle = AF_ANGLE_PI2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      if ( dy < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        angle = -AF_ANGLE_PI2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      return angle;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
    angle = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    if ( dx < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      dx = -dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      dy = -dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
      angle = AF_ANGLE_PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    if ( dy < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
      FT_Pos  tmp;
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
      tmp = dx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
      dx  = -dy;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
      dy  = tmp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
      angle -= AF_ANGLE_PI2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    if ( dx == 0 && dy == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    if ( dx == dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      angle += AF_ANGLE_PI4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    else if ( dx > dy )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      angle += af_arctan[FT_DivFix( dy, dx ) >> ( 16 - AF_ATAN_BITS )];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      angle += AF_ANGLE_PI2 -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
               af_arctan[FT_DivFix( dx, dy ) >> ( 16 - AF_ATAN_BITS )];
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
    if ( angle > AF_ANGLE_PI )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      angle -= AF_ANGLE_2PI;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    return angle;
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
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
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  af_sort_pos( FT_UInt  count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
               FT_Pos*  table )
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
    FT_UInt  i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    FT_Pos   swap;
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
    for ( i = 1; i < count; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
      for ( j = i; j > 0; j-- )
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
        if ( table[j] > table[j - 1] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
        swap         = table[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
        table[j]     = table[j - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
        table[j - 1] = swap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
    }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
  af_sort_widths( FT_UInt   count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
                  AF_Width  table )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
    FT_UInt      i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    AF_WidthRec  swap;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    for ( i = 1; i < count; i++ )
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
      for ( j = i; j > 0; j-- )
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 ( table[j].org > table[j - 1].org )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
        swap         = table[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
        table[j]     = table[j - 1];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
        table[j - 1] = swap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
      }
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
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
/* END */