Master merge

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs 2024-10-02 12:09:01 +02:00
parent b4d8b04d9e
commit 336fa9d002
No known key found for this signature in database
21 changed files with 189 additions and 157 deletions

View file

@ -1,31 +1,35 @@
import { line, lineLineIntersectionPoint, lineSegmentIntersectionPoints } from "./line";
import { point } from "./point";
import {
line,
lineLineIntersectionPoint,
lineSegmentIntersectionPoints,
} from "./line";
import { pointFrom } from "./point";
import { segment } from "./segment";
describe("line-line intersections", () => {
it("should correctly detect intersection at origin", () => {
expect(
lineLineIntersectionPoint(
line(point(-5, -5), point(5, 5)),
line(point(5, -5), point(-5, 5)),
line(pointFrom(-5, -5), pointFrom(5, 5)),
line(pointFrom(5, -5), pointFrom(-5, 5)),
),
).toEqual(point(0, 0));
).toEqual(pointFrom(0, 0));
});
it("should correctly detect intersection at non-origin", () => {
expect(
lineLineIntersectionPoint(
line(point(0, 0), point(10, 10)),
line(point(10, 0), point(0, 10)),
line(pointFrom(0, 0), pointFrom(10, 10)),
line(pointFrom(10, 0), pointFrom(0, 10)),
),
).toEqual(point(5, 5));
).toEqual(pointFrom(5, 5));
});
it("should correctly detect parallel lines", () => {
expect(
lineLineIntersectionPoint(
line(point(0, 0), point(0, 10)),
line(point(10, 0), point(10, 10)),
line(pointFrom(0, 0), pointFrom(0, 10)),
line(pointFrom(10, 0), pointFrom(10, 10)),
),
).toBe(null);
});
@ -35,16 +39,16 @@ describe("line-segment intersections", () => {
it("should correctly detect intersection", () => {
expect(
lineSegmentIntersectionPoints(
line(point(0, 0), point(5, 0)),
segment(point(2, -2), point(3, 2)),
line(pointFrom(0, 0), pointFrom(5, 0)),
segment(pointFrom(2, -2), pointFrom(3, 2)),
),
).toEqual(point(2.5, -0));
).toEqual(pointFrom(2.5, -0));
});
it("should correctly detect non-intersection", () => {
expect(
lineSegmentIntersectionPoints(
line(point(0, 0), point(5, 0)),
segment(point(3, 1), point(4, 4)),
line(pointFrom(0, 0), pointFrom(5, 0)),
segment(pointFrom(3, 1), pointFrom(4, 4)),
),
).toEqual(null);
});