Arc tests

This commit is contained in:
Mark Tolmacs 2024-09-25 14:22:32 +02:00
parent f79fb899fc
commit 3fe73e79a6
No known key found for this signature in database
9 changed files with 80 additions and 76 deletions

View file

@ -1,6 +1,7 @@
import { radians } from "./angle";
import { arc, arcIncludesPoint } from "./arc";
import { arc, arcIncludesPoint, arcSegmentInterceptPoint } from "./arc";
import { point } from "./point";
import { segment } from "./segment";
describe("point on arc", () => {
it("should detect point on simple arc", () => {
@ -28,3 +29,26 @@ describe("point on arc", () => {
).toBe(false);
});
});
describe("intersection", () => {
it("should report correct interception point", () => {
expect(
arcSegmentInterceptPoint(
arc(point(0, 0), 1, radians(-Math.PI / 4), radians(Math.PI / 4)),
segment(point(2, 1), point(0, 0)),
),
).toEqual([point(0.894427190999916, 0.447213595499958)]);
});
it("should report both interception points when present", () => {
expect(
arcSegmentInterceptPoint(
arc(point(0, 0), 1, radians(-Math.PI / 4), radians(Math.PI / 4)),
segment(point(0.9, -2), point(0.9, 2)),
),
).toEqual([
point(0.9, -0.4358898943540668),
point(0.9, 0.4358898943540668),
]);
});
});