-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
edges.ts
53 lines (49 loc) · 1.44 KB
/
edges.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { MultiFn1O } from "@thi.ng/defmulti";
import { defmulti } from "@thi.ng/defmulti/defmulti";
import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
import type { VecPair } from "@thi.ng/vectors";
import type { AABB } from "./api/aabb.js";
import type { Polygon } from "./api/polygon.js";
import type { Polyline } from "./api/polyline.js";
import type { Rect } from "./api/rect.js";
import { __dispatch } from "./internal/dispatch.js";
import { __edges } from "./internal/edges.js";
import { vertices } from "./vertices.js";
export const edges: MultiFn1O<
IShape,
number | Partial<SamplingOpts>,
Iterable<VecPair>
> = defmulti<
any,
number | Partial<SamplingOpts> | undefined,
Iterable<VecPair>
>(
__dispatch,
{
line: "polyline",
quad: "poly",
tri: "poly",
},
{
aabb: ($: AABB) => {
const [a, b, c, d, e, f, g, h] = vertices($);
return [
[a, b],
[b, c],
[c, d],
[d, a], // bottom
[e, f],
[f, g],
[g, h],
[h, e], // top
[a, e],
[b, f], // left
[c, g],
[d, h], // right
];
},
poly: ($: Polygon) => __edges($.points, true),
polyline: ($: Polyline) => __edges($.points),
rect: ($: Rect) => __edges(vertices($), true),
}
);