misc.ts 816 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. export function degToRad (deg: number) {
  7. return deg * 0.01745 // deg * Math.PI / 180
  8. }
  9. export function radToDeg (rad: number) {
  10. return rad * 57.29578 // rad * 180 / Math.PI
  11. }
  12. export function isPowerOfTwo (x: number) {
  13. return (x !== 0) && (x & (x - 1)) === 0
  14. }
  15. /** return the value that has the largest absolute value */
  16. export function absMax(...values: number[]) {
  17. let max = 0
  18. let absMax = 0
  19. for (let i = 0, il = values.length; i < il; ++i) {
  20. const value = values[i]
  21. const abs = Math.abs(value)
  22. if (abs > absMax) {
  23. max = value
  24. absMax = abs
  25. }
  26. }
  27. return max
  28. }