Skip to content

Commit 92e54ea

Browse files
feat(geom): add 2d line impl for classifyPoint()
1 parent 3bde7ba commit 92e54ea

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/geom/src/classify-point.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import type { IShape } from "@thi.ng/geom-api";
55
import {
66
classifyPointInCircle,
77
classifyPointInTriangle2,
8+
classifyPointSegment2,
89
} from "@thi.ng/geom-isec/point";
910
import { sign } from "@thi.ng/math/abs";
1011
import { EPS } from "@thi.ng/math/api";
1112
import type { ReadonlyVec } from "@thi.ng/vectors";
1213
import { dot } from "@thi.ng/vectors/dot";
1314
import type { Circle } from "./api/circle.js";
15+
import type { Line } from "./api/line.js";
1416
import type { Plane } from "./api/plane.js";
1517
import type { Triangle } from "./api/triangle.js";
1618
import { __dispatch } from "./internal/dispatch.js";
@@ -24,6 +26,7 @@ import { __dispatch } from "./internal/dispatch.js";
2426
* Currently only implemented for:
2527
*
2628
* - {@link Circle}
29+
* - {@link Line} (-1 = right/clockwise, +1 = left/counterclockwise)
2730
* - {@link Plane} (-1 = below, +1 = above)
2831
* - {@link Sphere}
2932
* - {@link Triangle}
@@ -49,7 +52,11 @@ export const classifyPoint: MultiFn2O<IShape, ReadonlyVec, number, number> =
4952
circle: ($: Circle, p, eps = EPS) =>
5053
classifyPointInCircle(p, $.pos, $.r, eps),
5154

52-
plane: ($: Plane, p, eps) => sign(dot($.normal, p) - $.w, eps),
55+
line: ({ points: [a, b] }: Line, p, eps = EPS) =>
56+
classifyPointSegment2(p, a, b, eps),
57+
58+
plane: ($: Plane, p, eps = EPS) =>
59+
sign(dot($.normal, p) - $.w, eps),
5360

5461
tri: ({ points }: Triangle, p: ReadonlyVec, eps = EPS) =>
5562
classifyPointInTriangle2(

0 commit comments

Comments
 (0)