fttrigon.h 8.2 KB

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