mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Rectangle distance and tests
This commit is contained in:
parent
9a8aabbeca
commit
47cc842415
5 changed files with 72 additions and 25 deletions
39
packages/math/rectangle.test.ts
Normal file
39
packages/math/rectangle.test.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { point } from "./point";
|
||||
import { rectangle, rectangleDistanceFromPoint } from "./rectangle";
|
||||
|
||||
describe("rectangle distance", () => {
|
||||
it("finds the shortest distance", () => {
|
||||
expect(
|
||||
rectangleDistanceFromPoint(
|
||||
rectangle(point(-1, -1), point(1, 1)),
|
||||
point(2, 0),
|
||||
),
|
||||
).toBe(1);
|
||||
expect(
|
||||
rectangleDistanceFromPoint(
|
||||
rectangle(point(-1, -1), point(1, 1)),
|
||||
point(0, 2),
|
||||
),
|
||||
).toBe(1);
|
||||
expect(
|
||||
rectangleDistanceFromPoint(
|
||||
rectangle(point(-1, -1), point(1, 1)),
|
||||
point(-2, 0),
|
||||
),
|
||||
).toBe(1);
|
||||
expect(
|
||||
rectangleDistanceFromPoint(
|
||||
rectangle(point(-1, -1), point(1, 1)),
|
||||
point(0, -2),
|
||||
),
|
||||
).toBe(1);
|
||||
});
|
||||
it("finds the corner as closest point", () => {
|
||||
expect(
|
||||
rectangleDistanceFromPoint(
|
||||
rectangle(point(-1, -1), point(1, 1)),
|
||||
point(2, 2),
|
||||
),
|
||||
).toBe(Math.sqrt(2));
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue