mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { line, lineIntersectsLine, lineIntersectsSegment } from "./line";
|
|
import { point } from "./point";
|
|
import { segment } from "./segment";
|
|
|
|
describe("line-line intersections", () => {
|
|
it("should correctly detect intersection at origin", () => {
|
|
expect(
|
|
lineIntersectsLine(
|
|
line(point(-5, -5), point(5, 5)),
|
|
line(point(5, -5), point(-5, 5)),
|
|
),
|
|
).toEqual(point(0, 0));
|
|
});
|
|
|
|
it("should correctly detect intersection at non-origin", () => {
|
|
expect(
|
|
lineIntersectsLine(
|
|
line(point(0, 0), point(10, 10)),
|
|
line(point(10, 0), point(0, 10)),
|
|
),
|
|
).toEqual(point(5, 5));
|
|
});
|
|
|
|
it("should correctly detect parallel lines", () => {
|
|
expect(
|
|
lineIntersectsLine(
|
|
line(point(0, 0), point(0, 10)),
|
|
line(point(10, 0), point(10, 10)),
|
|
),
|
|
).toBe(null);
|
|
});
|
|
});
|
|
|
|
describe("line-segment intersections", () => {
|
|
it("should correctly detect intersection", () => {
|
|
expect(
|
|
lineIntersectsSegment(
|
|
line(point(0, 0), point(5, 0)),
|
|
segment(point(2, -2), point(3, 2)),
|
|
),
|
|
).toEqual(point(2.5, -0));
|
|
});
|
|
it("should correctly detect non-intersection", () => {
|
|
expect(
|
|
lineIntersectsSegment(
|
|
line(point(0, 0), point(5, 0)),
|
|
segment(point(3, 1), point(4, 4)),
|
|
),
|
|
).toEqual(null);
|
|
});
|
|
});
|