math.test.ts 483 B

123456789101112131415
  1. import { rotate } from "./math";
  2. describe("rotate", () => {
  3. it("should rotate over (x2, y2) and return the rotated coordinates for (x1, y1)", () => {
  4. const x1 = 10;
  5. const y1 = 20;
  6. const x2 = 20;
  7. const y2 = 30;
  8. const angle = Math.PI / 2;
  9. const [rotatedX, rotatedY] = rotate(x1, y1, x2, y2, angle);
  10. expect([rotatedX, rotatedY]).toEqual([30, 20]);
  11. const res2 = rotate(rotatedX, rotatedY, x2, y2, -angle);
  12. expect(res2).toEqual([x1, x2]);
  13. });
  14. });