utils_spec.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. local vec3 = require "modules.vec3"
  2. local utils = require "modules.utils"
  3. local constants = require "modules.constants"
  4. local function tolerance(v, t)
  5. return math.abs(v - t) < 1e-6
  6. end
  7. describe("utils:", function()
  8. it("interpolates between two numbers", function()
  9. assert.is_true(tolerance(utils.lerp(0, 1, 0.5), 0.5))
  10. end)
  11. it("interpolates between two vectors", function()
  12. local a = vec3(0, 0, 0)
  13. local b = vec3(1, 1, 1)
  14. local c = vec3(0.5, 0.5, 0.5)
  15. assert.is.equal(utils.lerp(a, b, 0.5), c)
  16. a = vec3(5, 5, 5)
  17. b = vec3(0, 0, 0)
  18. c = vec3(2.5, 2.5, 2.5)
  19. assert.is.equal(utils.lerp(a, b, 0.5), c)
  20. end)
  21. it("decays exponentially", function()
  22. local v = utils.decay(0, 1, 0.5, 1)
  23. assert.is_true(tolerance(v, 0.39346934028737))
  24. end)
  25. end)
  26. --[[
  27. clamp(value, min, max)
  28. deadzone(value, size)
  29. threshold(value, threshold)
  30. tolerance(value, threshold)
  31. map(value, min_in, max_in, min_out, max_out)
  32. lerp(progress, low, high)
  33. smoothstep(progress, low, high)
  34. round(value, precision)
  35. wrap(value, limit)
  36. is_pot(value)
  37. project_on(out, a, b)
  38. project_from(out, a, b)
  39. mirror_on(out, a, b)
  40. reflect(out, i, n)
  41. refract(out, i, n, ior)
  42. angle_to(a, b)
  43. angle_between(a, b)
  44. --]]