2
0

segment.test.ts 685 B

123456789101112131415161718192021
  1. import { pointFrom } from "../src/point";
  2. import { lineSegment, lineSegmentIntersectionPoints } from "../src/segment";
  3. describe("line-segment intersections", () => {
  4. it("should correctly detect intersection", () => {
  5. expect(
  6. lineSegmentIntersectionPoints(
  7. lineSegment(pointFrom(0, 0), pointFrom(5, 0)),
  8. lineSegment(pointFrom(2, -2), pointFrom(3, 2)),
  9. ),
  10. ).toEqual(pointFrom(2.5, 0));
  11. });
  12. it("should correctly detect non-intersection", () => {
  13. expect(
  14. lineSegmentIntersectionPoints(
  15. lineSegment(pointFrom(0, 0), pointFrom(5, 0)),
  16. lineSegment(pointFrom(3, 1), pointFrom(4, 4)),
  17. ),
  18. ).toEqual(null);
  19. });
  20. });