Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /***************************************************************************/ |
michael@0 | 2 | /* */ |
michael@0 | 3 | /* fttrigon.h */ |
michael@0 | 4 | /* */ |
michael@0 | 5 | /* FreeType trigonometric functions (specification). */ |
michael@0 | 6 | /* */ |
michael@0 | 7 | /* Copyright 2001, 2003, 2005, 2007, 2013 by */ |
michael@0 | 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
michael@0 | 9 | /* */ |
michael@0 | 10 | /* This file is part of the FreeType project, and may only be used, */ |
michael@0 | 11 | /* modified, and distributed under the terms of the FreeType project */ |
michael@0 | 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
michael@0 | 13 | /* this file you indicate that you have read the license and */ |
michael@0 | 14 | /* understand and accept it fully. */ |
michael@0 | 15 | /* */ |
michael@0 | 16 | /***************************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | #ifndef __FTTRIGON_H__ |
michael@0 | 20 | #define __FTTRIGON_H__ |
michael@0 | 21 | |
michael@0 | 22 | #include FT_FREETYPE_H |
michael@0 | 23 | |
michael@0 | 24 | #ifdef FREETYPE_H |
michael@0 | 25 | #error "freetype.h of FreeType 1 has been loaded!" |
michael@0 | 26 | #error "Please fix the directory search order for header files" |
michael@0 | 27 | #error "so that freetype.h of FreeType 2 is found first." |
michael@0 | 28 | #endif |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | FT_BEGIN_HEADER |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | /*************************************************************************/ |
michael@0 | 35 | /* */ |
michael@0 | 36 | /* <Section> */ |
michael@0 | 37 | /* computations */ |
michael@0 | 38 | /* */ |
michael@0 | 39 | /*************************************************************************/ |
michael@0 | 40 | |
michael@0 | 41 | |
michael@0 | 42 | /************************************************************************* |
michael@0 | 43 | * |
michael@0 | 44 | * @type: |
michael@0 | 45 | * FT_Angle |
michael@0 | 46 | * |
michael@0 | 47 | * @description: |
michael@0 | 48 | * This type is used to model angle values in FreeType. Note that the |
michael@0 | 49 | * angle is a 16.16 fixed-point value expressed in degrees. |
michael@0 | 50 | * |
michael@0 | 51 | */ |
michael@0 | 52 | typedef FT_Fixed FT_Angle; |
michael@0 | 53 | |
michael@0 | 54 | |
michael@0 | 55 | /************************************************************************* |
michael@0 | 56 | * |
michael@0 | 57 | * @macro: |
michael@0 | 58 | * FT_ANGLE_PI |
michael@0 | 59 | * |
michael@0 | 60 | * @description: |
michael@0 | 61 | * The angle pi expressed in @FT_Angle units. |
michael@0 | 62 | * |
michael@0 | 63 | */ |
michael@0 | 64 | #define FT_ANGLE_PI ( 180L << 16 ) |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | /************************************************************************* |
michael@0 | 68 | * |
michael@0 | 69 | * @macro: |
michael@0 | 70 | * FT_ANGLE_2PI |
michael@0 | 71 | * |
michael@0 | 72 | * @description: |
michael@0 | 73 | * The angle 2*pi expressed in @FT_Angle units. |
michael@0 | 74 | * |
michael@0 | 75 | */ |
michael@0 | 76 | #define FT_ANGLE_2PI ( FT_ANGLE_PI * 2 ) |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | /************************************************************************* |
michael@0 | 80 | * |
michael@0 | 81 | * @macro: |
michael@0 | 82 | * FT_ANGLE_PI2 |
michael@0 | 83 | * |
michael@0 | 84 | * @description: |
michael@0 | 85 | * The angle pi/2 expressed in @FT_Angle units. |
michael@0 | 86 | * |
michael@0 | 87 | */ |
michael@0 | 88 | #define FT_ANGLE_PI2 ( FT_ANGLE_PI / 2 ) |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | /************************************************************************* |
michael@0 | 92 | * |
michael@0 | 93 | * @macro: |
michael@0 | 94 | * FT_ANGLE_PI4 |
michael@0 | 95 | * |
michael@0 | 96 | * @description: |
michael@0 | 97 | * The angle pi/4 expressed in @FT_Angle units. |
michael@0 | 98 | * |
michael@0 | 99 | */ |
michael@0 | 100 | #define FT_ANGLE_PI4 ( FT_ANGLE_PI / 4 ) |
michael@0 | 101 | |
michael@0 | 102 | |
michael@0 | 103 | /************************************************************************* |
michael@0 | 104 | * |
michael@0 | 105 | * @function: |
michael@0 | 106 | * FT_Sin |
michael@0 | 107 | * |
michael@0 | 108 | * @description: |
michael@0 | 109 | * Return the sinus of a given angle in fixed-point format. |
michael@0 | 110 | * |
michael@0 | 111 | * @input: |
michael@0 | 112 | * angle :: |
michael@0 | 113 | * The input angle. |
michael@0 | 114 | * |
michael@0 | 115 | * @return: |
michael@0 | 116 | * The sinus value. |
michael@0 | 117 | * |
michael@0 | 118 | * @note: |
michael@0 | 119 | * If you need both the sinus and cosinus for a given angle, use the |
michael@0 | 120 | * function @FT_Vector_Unit. |
michael@0 | 121 | * |
michael@0 | 122 | */ |
michael@0 | 123 | FT_EXPORT( FT_Fixed ) |
michael@0 | 124 | FT_Sin( FT_Angle angle ); |
michael@0 | 125 | |
michael@0 | 126 | |
michael@0 | 127 | /************************************************************************* |
michael@0 | 128 | * |
michael@0 | 129 | * @function: |
michael@0 | 130 | * FT_Cos |
michael@0 | 131 | * |
michael@0 | 132 | * @description: |
michael@0 | 133 | * Return the cosinus of a given angle in fixed-point format. |
michael@0 | 134 | * |
michael@0 | 135 | * @input: |
michael@0 | 136 | * angle :: |
michael@0 | 137 | * The input angle. |
michael@0 | 138 | * |
michael@0 | 139 | * @return: |
michael@0 | 140 | * The cosinus value. |
michael@0 | 141 | * |
michael@0 | 142 | * @note: |
michael@0 | 143 | * If you need both the sinus and cosinus for a given angle, use the |
michael@0 | 144 | * function @FT_Vector_Unit. |
michael@0 | 145 | * |
michael@0 | 146 | */ |
michael@0 | 147 | FT_EXPORT( FT_Fixed ) |
michael@0 | 148 | FT_Cos( FT_Angle angle ); |
michael@0 | 149 | |
michael@0 | 150 | |
michael@0 | 151 | /************************************************************************* |
michael@0 | 152 | * |
michael@0 | 153 | * @function: |
michael@0 | 154 | * FT_Tan |
michael@0 | 155 | * |
michael@0 | 156 | * @description: |
michael@0 | 157 | * Return the tangent of a given angle in fixed-point format. |
michael@0 | 158 | * |
michael@0 | 159 | * @input: |
michael@0 | 160 | * angle :: |
michael@0 | 161 | * The input angle. |
michael@0 | 162 | * |
michael@0 | 163 | * @return: |
michael@0 | 164 | * The tangent value. |
michael@0 | 165 | * |
michael@0 | 166 | */ |
michael@0 | 167 | FT_EXPORT( FT_Fixed ) |
michael@0 | 168 | FT_Tan( FT_Angle angle ); |
michael@0 | 169 | |
michael@0 | 170 | |
michael@0 | 171 | /************************************************************************* |
michael@0 | 172 | * |
michael@0 | 173 | * @function: |
michael@0 | 174 | * FT_Atan2 |
michael@0 | 175 | * |
michael@0 | 176 | * @description: |
michael@0 | 177 | * Return the arc-tangent corresponding to a given vector (x,y) in |
michael@0 | 178 | * the 2d plane. |
michael@0 | 179 | * |
michael@0 | 180 | * @input: |
michael@0 | 181 | * x :: |
michael@0 | 182 | * The horizontal vector coordinate. |
michael@0 | 183 | * |
michael@0 | 184 | * y :: |
michael@0 | 185 | * The vertical vector coordinate. |
michael@0 | 186 | * |
michael@0 | 187 | * @return: |
michael@0 | 188 | * The arc-tangent value (i.e. angle). |
michael@0 | 189 | * |
michael@0 | 190 | */ |
michael@0 | 191 | FT_EXPORT( FT_Angle ) |
michael@0 | 192 | FT_Atan2( FT_Fixed x, |
michael@0 | 193 | FT_Fixed y ); |
michael@0 | 194 | |
michael@0 | 195 | |
michael@0 | 196 | /************************************************************************* |
michael@0 | 197 | * |
michael@0 | 198 | * @function: |
michael@0 | 199 | * FT_Angle_Diff |
michael@0 | 200 | * |
michael@0 | 201 | * @description: |
michael@0 | 202 | * Return the difference between two angles. The result is always |
michael@0 | 203 | * constrained to the ]-PI..PI] interval. |
michael@0 | 204 | * |
michael@0 | 205 | * @input: |
michael@0 | 206 | * angle1 :: |
michael@0 | 207 | * First angle. |
michael@0 | 208 | * |
michael@0 | 209 | * angle2 :: |
michael@0 | 210 | * Second angle. |
michael@0 | 211 | * |
michael@0 | 212 | * @return: |
michael@0 | 213 | * Constrained value of `value2-value1'. |
michael@0 | 214 | * |
michael@0 | 215 | */ |
michael@0 | 216 | FT_EXPORT( FT_Angle ) |
michael@0 | 217 | FT_Angle_Diff( FT_Angle angle1, |
michael@0 | 218 | FT_Angle angle2 ); |
michael@0 | 219 | |
michael@0 | 220 | |
michael@0 | 221 | /************************************************************************* |
michael@0 | 222 | * |
michael@0 | 223 | * @function: |
michael@0 | 224 | * FT_Vector_Unit |
michael@0 | 225 | * |
michael@0 | 226 | * @description: |
michael@0 | 227 | * Return the unit vector corresponding to a given angle. After the |
michael@0 | 228 | * call, the value of `vec.x' will be `sin(angle)', and the value of |
michael@0 | 229 | * `vec.y' will be `cos(angle)'. |
michael@0 | 230 | * |
michael@0 | 231 | * This function is useful to retrieve both the sinus and cosinus of a |
michael@0 | 232 | * given angle quickly. |
michael@0 | 233 | * |
michael@0 | 234 | * @output: |
michael@0 | 235 | * vec :: |
michael@0 | 236 | * The address of target vector. |
michael@0 | 237 | * |
michael@0 | 238 | * @input: |
michael@0 | 239 | * angle :: |
michael@0 | 240 | * The address of angle. |
michael@0 | 241 | * |
michael@0 | 242 | */ |
michael@0 | 243 | FT_EXPORT( void ) |
michael@0 | 244 | FT_Vector_Unit( FT_Vector* vec, |
michael@0 | 245 | FT_Angle angle ); |
michael@0 | 246 | |
michael@0 | 247 | |
michael@0 | 248 | /************************************************************************* |
michael@0 | 249 | * |
michael@0 | 250 | * @function: |
michael@0 | 251 | * FT_Vector_Rotate |
michael@0 | 252 | * |
michael@0 | 253 | * @description: |
michael@0 | 254 | * Rotate a vector by a given angle. |
michael@0 | 255 | * |
michael@0 | 256 | * @inout: |
michael@0 | 257 | * vec :: |
michael@0 | 258 | * The address of target vector. |
michael@0 | 259 | * |
michael@0 | 260 | * @input: |
michael@0 | 261 | * angle :: |
michael@0 | 262 | * The address of angle. |
michael@0 | 263 | * |
michael@0 | 264 | */ |
michael@0 | 265 | FT_EXPORT( void ) |
michael@0 | 266 | FT_Vector_Rotate( FT_Vector* vec, |
michael@0 | 267 | FT_Angle angle ); |
michael@0 | 268 | |
michael@0 | 269 | |
michael@0 | 270 | /************************************************************************* |
michael@0 | 271 | * |
michael@0 | 272 | * @function: |
michael@0 | 273 | * FT_Vector_Length |
michael@0 | 274 | * |
michael@0 | 275 | * @description: |
michael@0 | 276 | * Return the length of a given vector. |
michael@0 | 277 | * |
michael@0 | 278 | * @input: |
michael@0 | 279 | * vec :: |
michael@0 | 280 | * The address of target vector. |
michael@0 | 281 | * |
michael@0 | 282 | * @return: |
michael@0 | 283 | * The vector length, expressed in the same units that the original |
michael@0 | 284 | * vector coordinates. |
michael@0 | 285 | * |
michael@0 | 286 | */ |
michael@0 | 287 | FT_EXPORT( FT_Fixed ) |
michael@0 | 288 | FT_Vector_Length( FT_Vector* vec ); |
michael@0 | 289 | |
michael@0 | 290 | |
michael@0 | 291 | /************************************************************************* |
michael@0 | 292 | * |
michael@0 | 293 | * @function: |
michael@0 | 294 | * FT_Vector_Polarize |
michael@0 | 295 | * |
michael@0 | 296 | * @description: |
michael@0 | 297 | * Compute both the length and angle of a given vector. |
michael@0 | 298 | * |
michael@0 | 299 | * @input: |
michael@0 | 300 | * vec :: |
michael@0 | 301 | * The address of source vector. |
michael@0 | 302 | * |
michael@0 | 303 | * @output: |
michael@0 | 304 | * length :: |
michael@0 | 305 | * The vector length. |
michael@0 | 306 | * |
michael@0 | 307 | * angle :: |
michael@0 | 308 | * The vector angle. |
michael@0 | 309 | * |
michael@0 | 310 | */ |
michael@0 | 311 | FT_EXPORT( void ) |
michael@0 | 312 | FT_Vector_Polarize( FT_Vector* vec, |
michael@0 | 313 | FT_Fixed *length, |
michael@0 | 314 | FT_Angle *angle ); |
michael@0 | 315 | |
michael@0 | 316 | |
michael@0 | 317 | /************************************************************************* |
michael@0 | 318 | * |
michael@0 | 319 | * @function: |
michael@0 | 320 | * FT_Vector_From_Polar |
michael@0 | 321 | * |
michael@0 | 322 | * @description: |
michael@0 | 323 | * Compute vector coordinates from a length and angle. |
michael@0 | 324 | * |
michael@0 | 325 | * @output: |
michael@0 | 326 | * vec :: |
michael@0 | 327 | * The address of source vector. |
michael@0 | 328 | * |
michael@0 | 329 | * @input: |
michael@0 | 330 | * length :: |
michael@0 | 331 | * The vector length. |
michael@0 | 332 | * |
michael@0 | 333 | * angle :: |
michael@0 | 334 | * The vector angle. |
michael@0 | 335 | * |
michael@0 | 336 | */ |
michael@0 | 337 | FT_EXPORT( void ) |
michael@0 | 338 | FT_Vector_From_Polar( FT_Vector* vec, |
michael@0 | 339 | FT_Fixed length, |
michael@0 | 340 | FT_Angle angle ); |
michael@0 | 341 | |
michael@0 | 342 | /* */ |
michael@0 | 343 | |
michael@0 | 344 | |
michael@0 | 345 | FT_END_HEADER |
michael@0 | 346 | |
michael@0 | 347 | #endif /* __FTTRIGON_H__ */ |
michael@0 | 348 | |
michael@0 | 349 | |
michael@0 | 350 | /* END */ |