point.test.ts 660 B

123456789101112131415161718192021222324
  1. import { point, pointRotateRads } from "./point";
  2. import type { Radians } from "./types";
  3. describe("rotate", () => {
  4. it("should rotate over (x2, y2) and return the rotated coordinates for (x1, y1)", () => {
  5. const x1 = 10;
  6. const y1 = 20;
  7. const x2 = 20;
  8. const y2 = 30;
  9. const angle = (Math.PI / 2) as Radians;
  10. const [rotatedX, rotatedY] = pointRotateRads(
  11. point(x1, y1),
  12. point(x2, y2),
  13. angle,
  14. );
  15. expect([rotatedX, rotatedY]).toEqual([30, 20]);
  16. const res2 = pointRotateRads(
  17. point(rotatedX, rotatedY),
  18. point(x2, y2),
  19. -angle as Radians,
  20. );
  21. expect(res2).toEqual([x1, x2]);
  22. });
  23. });