fix(math): correctly validate second point in isLineSegment (#11007)
Co-authored-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
@@ -40,7 +40,7 @@ export const isLineSegment = <Point extends GlobalPoint | LocalPoint>(
|
||||
Array.isArray(segment) &&
|
||||
segment.length === 2 &&
|
||||
isPoint(segment[0]) &&
|
||||
isPoint(segment[0]);
|
||||
isPoint(segment[1]);
|
||||
|
||||
/**
|
||||
* Return the coordinates resulting from rotating the given line about an origin by an angle in radians
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { pointFrom } from "../src/point";
|
||||
import { lineSegment, lineSegmentIntersectionPoints } from "../src/segment";
|
||||
import {
|
||||
lineSegment,
|
||||
lineSegmentIntersectionPoints,
|
||||
isLineSegment,
|
||||
} from "../src/segment";
|
||||
|
||||
describe("line-segment intersections", () => {
|
||||
it("should correctly detect intersection", () => {
|
||||
@@ -19,3 +23,23 @@ describe("line-segment intersections", () => {
|
||||
).toEqual(null);
|
||||
});
|
||||
});
|
||||
describe("isLineSegment validation", () => {
|
||||
it("should return true for a valid segment", () => {
|
||||
expect(
|
||||
isLineSegment([
|
||||
[0, 0],
|
||||
[1, 1],
|
||||
]),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if second element is not a point", () => {
|
||||
const invalidSegment = [[0, 0], "not-a-point"] as any;
|
||||
|
||||
expect(isLineSegment(invalidSegment)).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false for wrong length", () => {
|
||||
expect(isLineSegment([[0, 0]])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user