math.scalar.d.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * Scalar computation library
  3. */
  4. export declare class Scalar {
  5. /**
  6. * Two pi constants convenient for computation.
  7. */
  8. static TwoPi: number;
  9. /**
  10. * Boolean : true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)
  11. * @param a number
  12. * @param b number
  13. * @param epsilon (default = 1.401298E-45)
  14. * @returns true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)
  15. */
  16. static WithinEpsilon: (a: number, b: number, epsilon?: number) => boolean;
  17. /**
  18. * Returns a string : the upper case translation of the number i to hexadecimal.
  19. * @param i number
  20. * @returns the upper case translation of the number i to hexadecimal.
  21. */
  22. static ToHex: (i: number) => string;
  23. /**
  24. * Returns -1 if value is negative and +1 is value is positive.
  25. * @param value the value
  26. * @returns the value itself if it's equal to zero.
  27. */
  28. static Sign(value: number): number;
  29. /**
  30. * Returns the value itself if it's between min and max.
  31. * Returns min if the value is lower than min.
  32. * Returns max if the value is greater than max.
  33. * @param value the value to clmap
  34. * @param min the min value to clamp to (default: 0)
  35. * @param max the max value to clamp to (default: 1)
  36. * @returns the clamped value
  37. */
  38. static Clamp: (value: number, min?: number, max?: number) => number;
  39. /**
  40. * the log2 of value.
  41. * @param value the value to compute log2 of
  42. * @returns the log2 of value.
  43. */
  44. static Log2(value: number): number;
  45. /**
  46. * the floor part of a log2 value.
  47. * @param value the value to compute log2 of
  48. * @returns the log2 of value.
  49. */
  50. static ILog2(value: number): number;
  51. /**
  52. * Loops the value, so that it is never larger than length and never smaller than 0.
  53. *
  54. * This is similar to the modulo operator but it works with floating point numbers.
  55. * For example, using 3.0 for t and 2.5 for length, the result would be 0.5.
  56. * With t = 5 and length = 2.5, the result would be 0.0.
  57. * Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
  58. * @param value the value
  59. * @param length the length
  60. * @returns the looped value
  61. */
  62. static Repeat(value: number, length: number): number;
  63. /**
  64. * Normalize the value between 0.0 and 1.0 using min and max values
  65. * @param value value to normalize
  66. * @param min max to normalize between
  67. * @param max min to normalize between
  68. * @returns the normalized value
  69. */
  70. static Normalize(value: number, min: number, max: number): number;
  71. /**
  72. * Denormalize the value from 0.0 and 1.0 using min and max values
  73. * @param normalized value to denormalize
  74. * @param min max to denormalize between
  75. * @param max min to denormalize between
  76. * @returns the denormalized value
  77. */
  78. static Denormalize(normalized: number, min: number, max: number): number;
  79. /**
  80. * Calculates the shortest difference between two given angles given in degrees.
  81. * @param current current angle in degrees
  82. * @param target target angle in degrees
  83. * @returns the delta
  84. */
  85. static DeltaAngle(current: number, target: number): number;
  86. /**
  87. * PingPongs the value t, so that it is never larger than length and never smaller than 0.
  88. * @param tx value
  89. * @param length length
  90. * @returns The returned value will move back and forth between 0 and length
  91. */
  92. static PingPong(tx: number, length: number): number;
  93. /**
  94. * Interpolates between min and max with smoothing at the limits.
  95. *
  96. * This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up
  97. * from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.
  98. * @param from from
  99. * @param to to
  100. * @param tx value
  101. * @returns the smooth stepped value
  102. */
  103. static SmoothStep(from: number, to: number, tx: number): number;
  104. /**
  105. * Moves a value current towards target.
  106. *
  107. * This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.
  108. * Negative values of maxDelta pushes the value away from target.
  109. * @param current current value
  110. * @param target target value
  111. * @param maxDelta max distance to move
  112. * @returns resulting value
  113. */
  114. static MoveTowards(current: number, target: number, maxDelta: number): number;
  115. /**
  116. * Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
  117. *
  118. * Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta
  119. * are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.
  120. * @param current current value
  121. * @param target target value
  122. * @param maxDelta max distance to move
  123. * @returns resulting angle
  124. */
  125. static MoveTowardsAngle(current: number, target: number, maxDelta: number): number;
  126. /**
  127. * Creates a new scalar with values linearly interpolated of "amount" between the start scalar and the end scalar.
  128. * @param start start value
  129. * @param end target value
  130. * @param amount amount to lerp between
  131. * @returns the lerped value
  132. */
  133. static Lerp: (start: number, end: number, amount: number) => number;
  134. /**
  135. * Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees.
  136. * The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.
  137. * @param start start value
  138. * @param end target value
  139. * @param amount amount to lerp between
  140. * @returns the lerped value
  141. */
  142. static LerpAngle(start: number, end: number, amount: number): number;
  143. /**
  144. * Calculates the linear parameter t that produces the interpolant value within the range [a, b].
  145. * @param a start value
  146. * @param b target value
  147. * @param value value between a and b
  148. * @returns the inverseLerp value
  149. */
  150. static InverseLerp(a: number, b: number, value: number): number;
  151. /**
  152. * Returns a new scalar located for "amount" (float) on the Hermite spline defined by the scalars "value1", "value3", "tangent1", "tangent2".
  153. * @see http://mathworld.wolfram.com/HermitePolynomial.html
  154. * @param value1 defines the first control point
  155. * @param tangent1 defines the first tangent
  156. * @param value2 defines the second control point
  157. * @param tangent2 defines the second tangent
  158. * @param amount defines the amount on the interpolation spline (between 0 and 1)
  159. * @returns hermite result
  160. */
  161. static Hermite(value1: number, tangent1: number, value2: number, tangent2: number, amount: number): number;
  162. /**
  163. * Returns a new scalar which is the 1st derivative of the Hermite spline defined by the scalars "value1", "value2", "tangent1", "tangent2".
  164. * @param value1 defines the first control point
  165. * @param tangent1 defines the first tangent
  166. * @param value2 defines the second control point
  167. * @param tangent2 defines the second tangent
  168. * @param time define where the derivative must be done
  169. * @returns 1st derivative
  170. */
  171. static Hermite1stDerivative(value1: number, tangent1: number, value2: number, tangent2: number, time: number): number;
  172. /**
  173. * Returns a random float number between and min and max values
  174. * @param min min value of random
  175. * @param max max value of random
  176. * @returns random value
  177. */
  178. static RandomRange: (min: number, max: number) => number;
  179. /**
  180. * This function returns percentage of a number in a given range.
  181. *
  182. * RangeToPercent(40,20,60) will return 0.5 (50%)
  183. * RangeToPercent(34,0,100) will return 0.34 (34%)
  184. * @param number to convert to percentage
  185. * @param min min range
  186. * @param max max range
  187. * @returns the percentage
  188. */
  189. static RangeToPercent(number: number, min: number, max: number): number;
  190. /**
  191. * This function returns number that corresponds to the percentage in a given range.
  192. *
  193. * PercentToRange(0.34,0,100) will return 34.
  194. * @param percent to convert to number
  195. * @param min min range
  196. * @param max max range
  197. * @returns the number
  198. */
  199. static PercentToRange(percent: number, min: number, max: number): number;
  200. /**
  201. * Returns the angle converted to equivalent value between -Math.PI and Math.PI radians.
  202. * @param angle The angle to normalize in radian.
  203. * @returns The converted angle.
  204. */
  205. static NormalizeRadians: (angle: number) => number;
  206. /**
  207. * Returns the highest common factor of two integers.
  208. * @param a first parameter
  209. * @param b second parameter
  210. * @returns HCF of a and b
  211. */
  212. static HCF(a: number, b: number): number;
  213. }