@expofp/wayfinding-geometry 0.0.0-bootstrap.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/lib/building-outlines.d.ts +13 -0
- package/dist/lib/building-outlines.js +126 -0
- package/dist/lib/closures.d.ts +32 -0
- package/dist/lib/closures.js +254 -0
- package/dist/lib/corners.d.ts +19 -0
- package/dist/lib/corners.js +129 -0
- package/dist/lib/walks.d.ts +86 -0
- package/dist/lib/walks.js +179 -0
- package/dist/lib/wall-graph.d.ts +134 -0
- package/dist/lib/wall-graph.js +305 -0
- package/dist/lib/wall-groups.d.ts +33 -0
- package/dist/lib/wall-groups.js +97 -0
- package/package.json +37 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type WallGraph } from './wall-graph.js';
|
|
2
|
+
/** A connected group of the graph and the walk round its outside. */
|
|
3
|
+
export interface Group {
|
|
4
|
+
/** Its index among the groups. */
|
|
5
|
+
readonly id: number;
|
|
6
|
+
/** Its edges. */
|
|
7
|
+
readonly edges: number[];
|
|
8
|
+
/** Nodes round the outside; the edge at position `k` runs to position `k + 1`. */
|
|
9
|
+
readonly outer: number[];
|
|
10
|
+
/** Twice the signed area of the outer walk: zero for an open group, negative otherwise. */
|
|
11
|
+
readonly outerSum: number;
|
|
12
|
+
/** Whether it encloses an area. */
|
|
13
|
+
readonly building: boolean;
|
|
14
|
+
/** Whether it lies inside another group's building: a room, a wall in a hall. */
|
|
15
|
+
nested: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The connected groups with the walk round each one's outside: its area is zero for an open group,
|
|
19
|
+
* negative for a closed one (a face walk is positive).
|
|
20
|
+
* @param graph - the wall graph
|
|
21
|
+
* @returns the groups, and each node's group
|
|
22
|
+
*/
|
|
23
|
+
export declare function groupsOf(graph: WallGraph): {
|
|
24
|
+
groups: Group[];
|
|
25
|
+
groupOf: number[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Marks the groups lying inside another group's building as nested in it.
|
|
29
|
+
* @param graph - the wall graph
|
|
30
|
+
* @param groups - its groups
|
|
31
|
+
*/
|
|
32
|
+
export declare function markNested(graph: WallGraph, groups: readonly Group[]): void;
|
|
33
|
+
//# sourceMappingURL=wall-groups.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Box, lineAngle, ringContainsPoint } from '@expofp/geometry';
|
|
2
|
+
import { cross, otherEnd } from './wall-graph.js';
|
|
3
|
+
/**
|
|
4
|
+
* The connected groups with the walk round each one's outside: its area is zero for an open group,
|
|
5
|
+
* negative for a closed one (a face walk is positive).
|
|
6
|
+
* @param graph - the wall graph
|
|
7
|
+
* @returns the groups, and each node's group
|
|
8
|
+
*/
|
|
9
|
+
export function groupsOf(graph) {
|
|
10
|
+
const { nodes, edges, at } = graph;
|
|
11
|
+
// Each node's edges by direction, as the neighbor and the edge.
|
|
12
|
+
const order = at.map((list, node) => list
|
|
13
|
+
.map((edge) => {
|
|
14
|
+
const next = otherEnd(edges[edge], node);
|
|
15
|
+
return { next, edge, angle: lineAngle(nodes[node], nodes[next]) };
|
|
16
|
+
})
|
|
17
|
+
.sort((p, q) => p.angle - q.angle));
|
|
18
|
+
const groupOf = nodes.map(() => -1);
|
|
19
|
+
let count = 0;
|
|
20
|
+
nodes.forEach((_, start) => {
|
|
21
|
+
if (groupOf[start] !== -1 || !at[start].length)
|
|
22
|
+
return;
|
|
23
|
+
const stack = [start];
|
|
24
|
+
groupOf[start] = count;
|
|
25
|
+
while (stack.length) {
|
|
26
|
+
for (const { next } of order[stack.pop()]) {
|
|
27
|
+
if (groupOf[next] !== -1)
|
|
28
|
+
continue;
|
|
29
|
+
groupOf[next] = count;
|
|
30
|
+
stack.push(next);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
count++;
|
|
34
|
+
});
|
|
35
|
+
const groupEdges = Array.from({ length: count }, () => []);
|
|
36
|
+
edges.forEach((edge, index) => groupEdges[groupOf[edge.a]].push(index));
|
|
37
|
+
// Per edge, whether it was walked from `a` (bit 1) and from `b` (bit 2).
|
|
38
|
+
const walked = new Uint8Array(edges.length);
|
|
39
|
+
const side = (edge, from) => (edges[edge].a === from ? 1 : 2);
|
|
40
|
+
const outer = Array.from({ length: count }, () => ({ walk: [], sum: Infinity }));
|
|
41
|
+
const walks = Array.from({ length: count }, () => 0);
|
|
42
|
+
edges.forEach((edge, index) => {
|
|
43
|
+
for (const from of [edge.a, edge.b]) {
|
|
44
|
+
if (walked[index] & side(index, from))
|
|
45
|
+
continue;
|
|
46
|
+
const walk = [];
|
|
47
|
+
let sum = 0;
|
|
48
|
+
let u = from;
|
|
49
|
+
let through = index;
|
|
50
|
+
while (!(walked[through] & side(through, u))) {
|
|
51
|
+
const v = otherEnd(edges[through], u);
|
|
52
|
+
const list = order[v];
|
|
53
|
+
const k = list.findIndex((entry) => entry.edge === through);
|
|
54
|
+
walked[through] |= side(through, u);
|
|
55
|
+
walk.push(u);
|
|
56
|
+
sum += cross(nodes[u], nodes[v]);
|
|
57
|
+
through = list[(k - 1 + list.length) % list.length].edge;
|
|
58
|
+
u = v;
|
|
59
|
+
}
|
|
60
|
+
const group = groupOf[from];
|
|
61
|
+
walks[group]++;
|
|
62
|
+
if (sum < outer[group].sum)
|
|
63
|
+
outer[group] = { walk, sum };
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
groups: outer.map(({ walk, sum }, id) => ({
|
|
68
|
+
id,
|
|
69
|
+
edges: groupEdges[id],
|
|
70
|
+
outer: walk,
|
|
71
|
+
outerSum: sum,
|
|
72
|
+
building: walks[id] > 1,
|
|
73
|
+
nested: false,
|
|
74
|
+
})),
|
|
75
|
+
groupOf,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Marks the groups lying inside another group's building as nested in it.
|
|
80
|
+
* @param graph - the wall graph
|
|
81
|
+
* @param groups - its groups
|
|
82
|
+
*/
|
|
83
|
+
export function markNested(graph, groups) {
|
|
84
|
+
const rings = groups.map((group) => {
|
|
85
|
+
if (!group.building)
|
|
86
|
+
return null;
|
|
87
|
+
const ring = group.outer.map((node) => graph.nodes[node]);
|
|
88
|
+
return { ring, box: Box.fromPoints(ring) };
|
|
89
|
+
});
|
|
90
|
+
for (const group of groups) {
|
|
91
|
+
const point = graph.nodes[group.outer[0]];
|
|
92
|
+
group.nested = rings.some((found, index) => found !== null &&
|
|
93
|
+
index !== group.id &&
|
|
94
|
+
found.box.containsPoint(point) &&
|
|
95
|
+
ringContainsPoint(found.ring, point));
|
|
96
|
+
}
|
|
97
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@expofp/wayfinding-geometry",
|
|
3
|
+
"version": "0.0.0-bootstrap.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/expofp/efp-app.git",
|
|
7
|
+
"directory": "packages/wayfinding-geometry"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"description": "ExpoFP SDK internal: wayfinding geometry over plan data",
|
|
11
|
+
"homepage": "https://developer.expofp.com/",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
".": {
|
|
22
|
+
"@expofp/source": "./src/index.ts",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"tslib": "^2.3.0",
|
|
30
|
+
"@expofp/geometry": "3.45.14"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"!**/*.tsbuildinfo",
|
|
35
|
+
"!**/*.map"
|
|
36
|
+
]
|
|
37
|
+
}
|