Virtual whiteboard for sketching hand-drawn like diagrams
fix(math): correctly validate second point in isLineSegment (#11007)
Kundan1c292e493679
diff --git a/packages/math/src/segment.ts b/packages/math/src/segment.tsindex ae282bfee5..7523ef3f2f 100644--- a/packages/math/src/segment.ts+++ b/packages/math/src/segment.ts@@ -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 radiansdiff --git a/packages/math/tests/segment.test.ts b/packages/math/tests/segment.test.tsindex 6b29bba591..a7091521df 100644--- a/packages/math/tests/segment.test.ts+++ b/packages/math/tests/segment.test.ts@@ -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);+ });+});