@ifc-lite/drawing-2d 4.4.0 → 5.1.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.
Files changed (83) hide show
  1. package/dist/cut-layer.d.ts +12 -0
  2. package/dist/cut-layer.d.ts.map +1 -0
  3. package/dist/cut-layer.js +16 -0
  4. package/dist/cut-layer.js.map +1 -0
  5. package/dist/drawing-generator.d.ts.map +1 -1
  6. package/dist/drawing-generator.js +8 -13
  7. package/dist/drawing-generator.js.map +1 -1
  8. package/dist/dxf/convert.d.ts.map +1 -1
  9. package/dist/dxf/convert.js +8 -13
  10. package/dist/dxf/convert.js.map +1 -1
  11. package/dist/dxf/index.d.ts +1 -0
  12. package/dist/dxf/index.d.ts.map +1 -1
  13. package/dist/dxf/index.js +1 -0
  14. package/dist/dxf/index.js.map +1 -1
  15. package/dist/dxf/parser-text.d.ts +8 -0
  16. package/dist/dxf/parser-text.d.ts.map +1 -0
  17. package/dist/dxf/parser-text.js +189 -0
  18. package/dist/dxf/parser-text.js.map +1 -0
  19. package/dist/dxf/parser-util.d.ts +6 -0
  20. package/dist/dxf/parser-util.d.ts.map +1 -0
  21. package/dist/dxf/parser-util.js +49 -0
  22. package/dist/dxf/parser-util.js.map +1 -0
  23. package/dist/dxf/parser.d.ts +1 -4
  24. package/dist/dxf/parser.d.ts.map +1 -1
  25. package/dist/dxf/parser.js +3 -192
  26. package/dist/dxf/parser.js.map +1 -1
  27. package/dist/dxf/text-layout.d.ts +20 -0
  28. package/dist/dxf/text-layout.d.ts.map +1 -0
  29. package/dist/dxf/text-layout.js +29 -0
  30. package/dist/dxf/text-layout.js.map +1 -0
  31. package/dist/dxf/types.d.ts +16 -0
  32. package/dist/dxf/types.d.ts.map +1 -1
  33. package/dist/dxf/types.js.map +1 -1
  34. package/dist/dxf/writer.d.ts +3 -0
  35. package/dist/dxf/writer.d.ts.map +1 -1
  36. package/dist/dxf/writer.js +7 -6
  37. package/dist/dxf/writer.js.map +1 -1
  38. package/dist/dxf-exporter.d.ts +45 -0
  39. package/dist/dxf-exporter.d.ts.map +1 -1
  40. package/dist/dxf-exporter.js +78 -5
  41. package/dist/dxf-exporter.js.map +1 -1
  42. package/dist/gpu-section-cutter.d.ts.map +1 -1
  43. package/dist/gpu-section-cutter.js +4 -7
  44. package/dist/gpu-section-cutter.js.map +1 -1
  45. package/dist/half-space-clip.js +2 -0
  46. package/dist/half-space-clip.js.map +1 -1
  47. package/dist/index.d.ts +4 -4
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +3 -3
  50. package/dist/index.js.map +1 -1
  51. package/dist/line-classification.d.ts +9 -0
  52. package/dist/line-classification.d.ts.map +1 -0
  53. package/dist/line-classification.js +5 -0
  54. package/dist/line-classification.js.map +1 -0
  55. package/dist/line-merger.js +1 -1
  56. package/dist/line-merger.js.map +1 -1
  57. package/dist/open-chains.d.ts +17 -0
  58. package/dist/open-chains.d.ts.map +1 -0
  59. package/dist/open-chains.js +130 -0
  60. package/dist/open-chains.js.map +1 -0
  61. package/dist/open-surface.d.ts +25 -0
  62. package/dist/open-surface.d.ts.map +1 -0
  63. package/dist/open-surface.js +97 -0
  64. package/dist/open-surface.js.map +1 -0
  65. package/dist/polygon-builder.d.ts +21 -20
  66. package/dist/polygon-builder.d.ts.map +1 -1
  67. package/dist/polygon-builder.js +58 -66
  68. package/dist/polygon-builder.js.map +1 -1
  69. package/dist/polygon-helpers.d.ts +26 -0
  70. package/dist/polygon-helpers.d.ts.map +1 -0
  71. package/dist/polygon-helpers.js +93 -0
  72. package/dist/polygon-helpers.js.map +1 -0
  73. package/dist/section-cutter.d.ts.map +1 -1
  74. package/dist/section-cutter.js +10 -10
  75. package/dist/section-cutter.js.map +1 -1
  76. package/dist/svg-exporter.d.ts.map +1 -1
  77. package/dist/svg-exporter.js +10 -3
  78. package/dist/svg-exporter.js.map +1 -1
  79. package/dist/types.d.ts +20 -17
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/types.js +7 -0
  82. package/dist/types.js.map +1 -1
  83. package/package.json +5 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-chains.d.ts","sourceRoot":"","sources":["../src/open-chains.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,YAAY,CAAC;AAetD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CA2EzG"}
@@ -0,0 +1,130 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ import { point2DDistance } from './math.js';
5
+ const CRACK_RATIO = 0.03;
6
+ const CRACK_MAX_GAP = 0.01; // metres
7
+ export function findOpenChainSegments(segments, tolerance) {
8
+ const points = [];
9
+ const cells = new Map();
10
+ const cellKey = (cx, cy) => `${cx},${cy}`;
11
+ const nodeAt = (p) => {
12
+ const cx = Math.round(p.x / tolerance);
13
+ const cy = Math.round(p.y / tolerance);
14
+ // Neighbouring cells too: noise must not split a vertex lying on a cell boundary.
15
+ for (let dx = -1; dx <= 1; dx++) {
16
+ for (let dy = -1; dy <= 1; dy++) {
17
+ for (const id of cells.get(cellKey(cx + dx, cy + dy)) ?? []) {
18
+ if (point2DDistance(points[id], p) < tolerance)
19
+ return id;
20
+ }
21
+ }
22
+ }
23
+ const id = points.length;
24
+ points.push(p);
25
+ const key = cellKey(cx, cy);
26
+ const cell = cells.get(key);
27
+ if (cell)
28
+ cell.push(id);
29
+ else
30
+ cells.set(key, [id]);
31
+ return id;
32
+ };
33
+ const edges = [];
34
+ const byNodes = new Map();
35
+ for (const segment of segments) {
36
+ const a = nodeAt(segment.p0_2d);
37
+ const b = nodeAt(segment.p1_2d);
38
+ if (a === b)
39
+ continue; // shorter than the weld: no topology, and invisible either way
40
+ const key = a < b ? `${a},${b}` : `${b},${a}`;
41
+ const twin = byNodes.get(key);
42
+ if (twin) {
43
+ // A duplicated face on a solid, or a sheet folded back on itself: one edge either
44
+ // way, so the copies share its fate rather than cancel and open a solid's outline.
45
+ twin.segments.push(segment);
46
+ continue;
47
+ }
48
+ const edge = { a, b, segments: [segment], length: point2DDistance(segment.p0_2d, segment.p1_2d), removed: false };
49
+ byNodes.set(key, edge);
50
+ edges.push(edge);
51
+ }
52
+ const incident = points.map(() => []);
53
+ for (const edge of edges) {
54
+ incident[edge.a].push(edge);
55
+ incident[edge.b].push(edge);
56
+ }
57
+ bridgeCracks(points, incident, edges);
58
+ const open = new Set();
59
+ // Prune dangling paths, cascading until each stops at a junction or is gone.
60
+ const liveDegree = incident.map((list) => list.length);
61
+ const leaves = [];
62
+ liveDegree.forEach((degree, node) => { if (degree === 1)
63
+ leaves.push(node); });
64
+ while (leaves.length > 0) {
65
+ const node = leaves.pop();
66
+ if (liveDegree[node] !== 1)
67
+ continue;
68
+ const edge = incident[node].find((e) => !e.removed);
69
+ edge.removed = true;
70
+ for (const segment of edge.segments)
71
+ open.add(segment);
72
+ liveDegree[node] = 0;
73
+ const other = edge.a === node ? edge.b : edge.a;
74
+ if (--liveDegree[other] === 1)
75
+ leaves.push(other);
76
+ }
77
+ for (const component of components(points.length, edges)) {
78
+ const gaps = component.reduce((sum, e) => sum + (e.segments.length > 0 ? 0 : e.length), 0);
79
+ const length = component.reduce((sum, e) => sum + (e.segments.length > 0 ? e.length : 0), 0);
80
+ if (gaps <= length * CRACK_RATIO)
81
+ continue;
82
+ for (const edge of component)
83
+ for (const segment of edge.segments)
84
+ open.add(segment);
85
+ }
86
+ return open;
87
+ }
88
+ /** Bridges every pair of chain ends within a crack of each other. */
89
+ function bridgeCracks(points, incident, edges) {
90
+ const ends = points.flatMap((_, node) => (incident[node].length === 1 ? [node] : []));
91
+ ends.sort((p, q) => points[p].x - points[q].x || p - q);
92
+ for (let i = 0; i < ends.length; i++) {
93
+ for (let j = i + 1; j < ends.length && points[ends[j]].x - points[ends[i]].x <= CRACK_MAX_GAP; j++) {
94
+ const [a, b] = [ends[i], ends[j]];
95
+ const gap = point2DDistance(points[a], points[b]);
96
+ if (gap > CRACK_MAX_GAP)
97
+ continue;
98
+ const bridge = { a, b, segments: [], length: gap, removed: false };
99
+ edges.push(bridge);
100
+ incident[a].push(bridge);
101
+ incident[b].push(bridge);
102
+ }
103
+ }
104
+ }
105
+ /** Surviving edges, grouped by connected component. */
106
+ function components(nodeCount, edges) {
107
+ const parent = Array.from({ length: nodeCount }, (_, i) => i);
108
+ const find = (node) => {
109
+ let root = node;
110
+ while (parent[root] !== root)
111
+ root = parent[root];
112
+ while (parent[node] !== root)
113
+ [node, parent[node]] = [parent[node], root];
114
+ return root;
115
+ };
116
+ const live = edges.filter((e) => !e.removed);
117
+ for (const { a, b } of live)
118
+ parent[find(a)] = find(b);
119
+ const groups = new Map();
120
+ for (const edge of live) {
121
+ const root = find(edge.a);
122
+ const group = groups.get(root);
123
+ if (group)
124
+ group.push(edge);
125
+ else
126
+ groups.set(root, [edge]);
127
+ }
128
+ return [...groups.values()];
129
+ }
130
+ //# sourceMappingURL=open-chains.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-chains.js","sourceRoot":"","sources":["../src/open-chains.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAkB/D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,aAAa,GAAG,IAAI,CAAC,CAAC,SAAS;AAWrC,MAAM,UAAU,qBAAqB,CAAC,QAA+B,EAAE,SAAiB;IACtF,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC1C,MAAM,OAAO,GAAG,CAAC,EAAU,EAAE,EAAU,EAAE,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;IAC1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C;QAChB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC7C,KAAK,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,IAAI;QAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;YACvB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Which entities' meshes have free edges, i.e. are surfaces rather than solids (#8664).
3
+ *
4
+ * Why the mesh and not the IFC representation: of 439 IfcFaceBasedSurfaceModel
5
+ * products measured on a real corpus, 318 mesh perfectly closed and are volumes in
6
+ * all but name, so the representation type alone would hollow them out.
7
+ *
8
+ * Why the whole entity and not each MeshData: one material layer's band is open by
9
+ * design (the slicer leaves the interface planes uncapped), and only the union of
10
+ * an entity's sub-meshes is watertight.
11
+ */
12
+ import type { MeshData } from '@ifc-lite/geometry';
13
+ import type { CutSegment, EntityKey } from './types.js';
14
+ export declare class OpenSurfaceIndex {
15
+ private readonly meshes;
16
+ private byEntity;
17
+ private readonly known;
18
+ constructor(meshes: readonly MeshData[]);
19
+ /** Whether this cut crosses a real boundary of the entity: chain ends left, and free edges. */
20
+ cutsOpen(key: EntityKey, segments: readonly CutSegment[]): boolean;
21
+ /** Lazy per entity, memoised: most entities never get here (see {@link cutsOpen}). */
22
+ has(key: EntityKey): boolean;
23
+ private entityMeshes;
24
+ }
25
+ //# sourceMappingURL=open-surface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-surface.d.ts","sourceRoot":"","sources":["../src/open-surface.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQxD,qBAAa,gBAAgB;IAIf,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,QAAQ,CAA2C;IAC3D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;gBAE1B,MAAM,EAAE,SAAS,QAAQ,EAAE;IAExD,+FAA+F;IAC/F,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO;IAIlE,sFAAsF;IACtF,GAAG,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO;IAS5B,OAAO,CAAC,YAAY;CAYrB"}
@@ -0,0 +1,97 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+ import { makeEntityKey } from './types.js';
5
+ /** Vertex weld grid in metres. Faces are not guaranteed to share vertices. */
6
+ const WELD_GRID = 1e-3;
7
+ /** Two welded ids pack into one safe integer below this count (2^26 squared is 2^52). */
8
+ const ID_RADIX = 0x4000000;
9
+ export class OpenSurfaceIndex {
10
+ meshes;
11
+ byEntity = null;
12
+ known = new Map();
13
+ constructor(meshes) {
14
+ this.meshes = meshes;
15
+ }
16
+ /** Whether this cut crosses a real boundary of the entity: chain ends left, and free edges. */
17
+ cutsOpen(key, segments) {
18
+ return hasChainEnd(segments) && this.has(key);
19
+ }
20
+ /** Lazy per entity, memoised: most entities never get here (see {@link cutsOpen}). */
21
+ has(key) {
22
+ let open = this.known.get(key);
23
+ if (open === undefined) {
24
+ open = hasFreeEdge(this.entityMeshes().get(key) ?? []);
25
+ this.known.set(key, open);
26
+ }
27
+ return open;
28
+ }
29
+ entityMeshes() {
30
+ if (this.byEntity)
31
+ return this.byEntity;
32
+ const byEntity = new Map();
33
+ for (const mesh of this.meshes) {
34
+ const key = makeEntityKey(mesh.modelIndex || 0, mesh.expressId);
35
+ const bucket = byEntity.get(key);
36
+ if (bucket)
37
+ bucket.push(mesh);
38
+ else
39
+ byEntity.set(key, [mesh]);
40
+ }
41
+ this.byEntity = byEntity;
42
+ return byEntity;
43
+ }
44
+ }
45
+ /** Parity over welded endpoints: a section of a closed mesh has no chain ends. */
46
+ function hasChainEnd(segments) {
47
+ const oddEnds = new Set();
48
+ for (const { p0_2d, p1_2d } of segments) {
49
+ for (const { x, y } of [p0_2d, p1_2d]) {
50
+ const end = `${Math.round(x / WELD_GRID)},${Math.round(y / WELD_GRID)}`;
51
+ if (!oddEnds.delete(end))
52
+ oddEnds.add(end);
53
+ }
54
+ }
55
+ return oddEnds.size > 0;
56
+ }
57
+ /**
58
+ * Parity over welded edges: a closed mesh uses every edge an even number of times,
59
+ * so toggling each use leaves only the free ones. World space, since sub-meshes of
60
+ * one entity need not share an origin.
61
+ */
62
+ function hasFreeEdge(meshes) {
63
+ const weldIds = new Map();
64
+ const oddEdges = new Set();
65
+ for (const { positions, indices, origin } of meshes) {
66
+ const vertexIds = new Int32Array(positions.length / 3).fill(-1);
67
+ const weldedId = (vertex) => {
68
+ if (vertexIds[vertex] !== -1)
69
+ return vertexIds[vertex];
70
+ const base = vertex * 3;
71
+ const key = [0, 1, 2]
72
+ .map((axis) => Math.round((positions[base + axis] + (origin?.[axis] ?? 0)) / WELD_GRID))
73
+ .join(',');
74
+ let id = weldIds.get(key);
75
+ if (id === undefined) {
76
+ id = weldIds.size;
77
+ weldIds.set(key, id);
78
+ }
79
+ vertexIds[vertex] = id;
80
+ return id;
81
+ };
82
+ for (let t = 0; t + 2 < indices.length; t += 3) {
83
+ const a = weldedId(indices[t]);
84
+ const b = weldedId(indices[t + 1]);
85
+ const c = weldedId(indices[t + 2]);
86
+ if (a === b || b === c || c === a)
87
+ continue; // collapsed by the weld: has no edges
88
+ for (const [p, q] of [[a, b], [b, c], [c, a]]) {
89
+ const edge = Math.min(p, q) * ID_RADIX + Math.max(p, q);
90
+ if (!oddEdges.delete(edge))
91
+ oddEdges.add(edge);
92
+ }
93
+ }
94
+ }
95
+ return oddEdges.size > 0;
96
+ }
97
+ //# sourceMappingURL=open-surface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-surface.js","sourceRoot":"","sources":["../src/open-surface.ts"],"names":[],"mappings":"AAAA;;+DAE+D;AAgB/D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,8EAA8E;AAC9E,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,yFAAyF;AACzF,MAAM,QAAQ,GAAG,SAAS,CAAC;AAE3B,MAAM,OAAO,gBAAgB;IAIE;IAHrB,QAAQ,GAAsC,IAAI,CAAC;IAC1C,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEvD,YAA6B,MAA2B;QAA3B,WAAM,GAAN,MAAM,CAAqB;IAAG,CAAC;IAE5D,+FAA+F;IAC/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AAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;oBAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC;AAC3B,CAAC"}
@@ -7,10 +7,17 @@
7
7
  * - Holes (inner boundaries)
8
8
  * - Floating point tolerance for vertex matching
9
9
  */
10
- import type { Point2D, CutSegment, DrawingPolygon } from './types.js';
10
+ import type { CutSegment, DrawingPolygon } from './types.js';
11
+ import type { OpenSurfaceIndex } from './open-surface.js';
12
+ export { simplifyPolygon, polygonBounds } from './polygon-helpers.js';
11
13
  export declare class PolygonBuilder {
12
14
  /** Tolerance for vertex matching */
13
15
  private tolerance;
16
+ /**
17
+ * Float32 rounding noise of the entity being processed (`maxAbs · 2⁻²²`,
18
+ * set by `withScaleAwareTolerance`). Floors the collinear-vertex tolerance.
19
+ */
20
+ private float32NoiseFloor;
14
21
  constructor(tolerance?: number);
15
22
  /**
16
23
  * Run `fn` with `this.tolerance` floored to the float32 noise floor of
@@ -46,8 +53,12 @@ export declare class PolygonBuilder {
46
53
  /**
47
54
  * Build polygons from cut segments
48
55
  * Groups segments by entity and reconstructs closed loops
56
+ *
57
+ * `openSurfaces` names the entities whose mesh has free edges (#8664). Their open
58
+ * chains bound no area, so they are routed into `openSurfaceSegments`, to be drawn
59
+ * as lines, and everything else builds as usual.
49
60
  */
50
- buildPolygons(segments: CutSegment[]): DrawingPolygon[];
61
+ buildPolygons(segments: CutSegment[], openSurfaces?: OpenSurfaceIndex, openSurfaceSegments?: Set<CutSegment>): DrawingPolygon[];
51
62
  /**
52
63
  * Build the OPAQUE BASE cross-section for every MULTI-material entity — its
53
64
  * full solid section, ignoring the per-layer colour split.
@@ -61,16 +72,17 @@ export declare class PolygonBuilder {
61
72
  * hollow even where the per-layer reconstruction has to fall back. Single-
62
73
  * material entities are skipped — their normal `cutPolygons` already fill solid.
63
74
  */
64
- buildBasePolygons(segments: CutSegment[]): DrawingPolygon[];
75
+ buildBasePolygons(segments: CutSegment[], openSurfaces?: OpenSurfaceIndex): DrawingPolygon[];
76
+ /** An entity's segments without those on chains through an open surface (#8664). */
77
+ private routeOpenChains;
65
78
  /**
66
79
  * Build polygons for a single entity.
67
80
  *
68
- * Sub-groups the entity's segments by material colour so an
69
- * `IfcMaterialLayerSet` wall/slab — sliced into one sub-mesh (hence one
70
- * colour) per layer — reconstructs as one polygon set per layer, each
71
- * carrying that layer's colour. A single-material entity yields exactly one
72
- * colour group and is built identically to before, with no colour stamped
73
- * (so renderers keep their per-`ifcType` / per-entity fill for it).
81
+ * Sub-groups the entity's segments by layer (colour and `IfcMaterial`), so an
82
+ * `IfcMaterialLayerSet` wall/slab (one sub-mesh per layer) reconstructs as one
83
+ * polygon set per layer carrying its colour and material, even when two layers
84
+ * share a colour. A single-material entity yields exactly one group and is built
85
+ * as before, with no fill colour stamped (renderers keep their per-`ifcType` / per-entity fill).
74
86
  */
75
87
  private buildEntityPolygons;
76
88
  /**
@@ -175,15 +187,4 @@ export declare class PolygonBuilder {
175
187
  */
176
188
  private pointInPolygon;
177
189
  }
178
- /**
179
- * Simplify polygon by removing collinear points
180
- */
181
- export declare function simplifyPolygon(points: Point2D[], tolerance?: number): Point2D[];
182
- /**
183
- * Compute polygon bounds
184
- */
185
- export declare function polygonBounds(points: Point2D[]): {
186
- min: Point2D;
187
- max: Point2D;
188
- };
189
190
  //# sourceMappingURL=polygon-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"polygon-builder.d.ts","sourceRoot":"","sources":["../src/polygon-builder.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAa,UAAU,EAAE,cAAc,EAAa,MAAM,YAAY,CAAC;AA8B5F,qBAAa,cAAc;IACzB,oCAAoC;IACpC,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,GAAE,MAAe;IAItC;;;;;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form is subject to the terms of the Mozilla Public
2
2
  * License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
- import { makeEntityKey, colorKey } from './types.js';
4
+ import { makeEntityKey } from './types.js';
5
+ import { findOpenChainSegments } from './open-chains.js';
6
+ import { layerKey, layerStamp } from './cut-layer.js';
5
7
  import { EPSILON, point2DDistance, polygonSignedArea, ensureCCW, ensureCW, } from './math.js';
8
+ import { removeCollinearRingVertices } from './polygon-helpers.js';
9
+ export { simplifyPolygon, polygonBounds } from './polygon-helpers.js';
6
10
  // ═══════════════════════════════════════════════════════════════════════════
7
11
  // POLYGON BUILDER CLASS
8
12
  // ═══════════════════════════════════════════════════════════════════════════
9
13
  export class PolygonBuilder {
10
14
  /** Tolerance for vertex matching */
11
15
  tolerance;
16
+ /**
17
+ * Float32 rounding noise of the entity being processed (`maxAbs · 2⁻²²`,
18
+ * set by `withScaleAwareTolerance`). Floors the collinear-vertex tolerance.
19
+ */
20
+ float32NoiseFloor = 0;
12
21
  constructor(tolerance = 0.0001) {
13
22
  this.tolerance = tolerance;
14
23
  }
@@ -62,19 +71,26 @@ export class PolygonBuilder {
62
71
  maxAbs = Math.abs(b.y);
63
72
  }
64
73
  const original = this.tolerance;
65
- this.tolerance = Math.max(original, maxAbs * 2 ** -22);
74
+ const originalFloor = this.float32NoiseFloor;
75
+ this.float32NoiseFloor = maxAbs * 2 ** -22;
76
+ this.tolerance = Math.max(original, this.float32NoiseFloor);
66
77
  try {
67
78
  return fn();
68
79
  }
69
80
  finally {
70
81
  this.tolerance = original;
82
+ this.float32NoiseFloor = originalFloor;
71
83
  }
72
84
  }
73
85
  /**
74
86
  * Build polygons from cut segments
75
87
  * Groups segments by entity and reconstructs closed loops
88
+ *
89
+ * `openSurfaces` names the entities whose mesh has free edges (#8664). Their open
90
+ * chains bound no area, so they are routed into `openSurfaceSegments`, to be drawn
91
+ * as lines, and everything else builds as usual.
76
92
  */
77
- buildPolygons(segments) {
93
+ buildPolygons(segments, openSurfaces, openSurfaceSegments = new Set()) {
78
94
  // Group segments by entity
79
95
  const byEntity = new Map();
80
96
  for (const seg of segments) {
@@ -87,7 +103,7 @@ export class PolygonBuilder {
87
103
  // Build polygons for each entity - collect arrays for efficient flattening
88
104
  const polygonArrays = [];
89
105
  for (const [key, entitySegments] of byEntity) {
90
- const entityPolygons = this.withScaleAwareTolerance(entitySegments, () => this.buildEntityPolygons(entitySegments));
106
+ const entityPolygons = this.withScaleAwareTolerance(entitySegments, () => this.buildEntityPolygons(this.routeOpenChains(key, entitySegments, openSurfaces, openSurfaceSegments)));
91
107
  polygonArrays.push(entityPolygons);
92
108
  }
93
109
  return polygonArrays.flat();
@@ -105,7 +121,7 @@ export class PolygonBuilder {
105
121
  * hollow even where the per-layer reconstruction has to fall back. Single-
106
122
  * material entities are skipped — their normal `cutPolygons` already fill solid.
107
123
  */
108
- buildBasePolygons(segments) {
124
+ buildBasePolygons(segments, openSurfaces) {
109
125
  const byEntity = new Map();
110
126
  for (const seg of segments) {
111
127
  const key = makeEntityKey(seg.modelIndex, seg.entityId);
@@ -117,34 +133,43 @@ export class PolygonBuilder {
117
133
  bucket.push(seg);
118
134
  }
119
135
  const out = [];
120
- for (const entitySegments of byEntity.values()) {
136
+ for (const [key, allSegments] of byEntity) {
137
+ const entitySegments = this.withScaleAwareTolerance(allSegments, () => this.routeOpenChains(key, allSegments, openSurfaces, new Set()));
121
138
  // Only entities that cut into >1 material get per-layer fills (hence a base).
122
- const colors = new Set(entitySegments.map((s) => colorKey(s.color)));
139
+ const colors = new Set(entitySegments.map(layerKey));
123
140
  if (colors.size < 2)
124
141
  continue;
125
142
  // Colourless build ⇒ closed-loop path (the combined section is closed).
126
- const base = this.withScaleAwareTolerance(entitySegments, () => this.buildColorGroupPolygons(entitySegments, undefined)).map((p) => ({ ...p, isLayerBase: true }));
143
+ const base = this.withScaleAwareTolerance(allSegments, () => this.buildColorGroupPolygons(entitySegments, undefined)).map((p) => ({ ...p, isLayerBase: true }));
127
144
  if (base.length > 0)
128
145
  out.push(base);
129
146
  }
130
147
  return out.flat();
131
148
  }
149
+ /** An entity's segments without those on chains through an open surface (#8664). */
150
+ routeOpenChains(key, segments, openSurfaces, openOut) {
151
+ if (!openSurfaces?.cutsOpen(key, segments))
152
+ return segments;
153
+ const open = findOpenChainSegments(segments, this.tolerance);
154
+ for (const seg of open)
155
+ openOut.add(seg);
156
+ return segments.filter((seg) => !open.has(seg));
157
+ }
132
158
  /**
133
159
  * Build polygons for a single entity.
134
160
  *
135
- * Sub-groups the entity's segments by material colour so an
136
- * `IfcMaterialLayerSet` wall/slab — sliced into one sub-mesh (hence one
137
- * colour) per layer — reconstructs as one polygon set per layer, each
138
- * carrying that layer's colour. A single-material entity yields exactly one
139
- * colour group and is built identically to before, with no colour stamped
140
- * (so renderers keep their per-`ifcType` / per-entity fill for it).
161
+ * Sub-groups the entity's segments by layer (colour and `IfcMaterial`), so an
162
+ * `IfcMaterialLayerSet` wall/slab (one sub-mesh per layer) reconstructs as one
163
+ * polygon set per layer carrying its colour and material, even when two layers
164
+ * share a colour. A single-material entity yields exactly one group and is built
165
+ * as before, with no fill colour stamped (renderers keep their per-`ifcType` / per-entity fill).
141
166
  */
142
167
  buildEntityPolygons(segments) {
143
168
  if (segments.length === 0)
144
169
  return [];
145
170
  const byColor = new Map();
146
171
  for (const seg of segments) {
147
- const key = colorKey(seg.color);
172
+ const key = layerKey(seg);
148
173
  let bucket = byColor.get(key);
149
174
  if (!bucket) {
150
175
  bucket = [];
@@ -152,14 +177,14 @@ export class PolygonBuilder {
152
177
  }
153
178
  bucket.push(seg);
154
179
  }
155
- // Only a genuinely multi-material cut (≥2 colours) gets per-layer fills;
180
+ // Only a genuinely multi-layer cut (≥2 colour/material keys) gets per-layer fills;
156
181
  // ordinary elements stay colourless so existing fill rules apply.
157
182
  const multiMaterial = byColor.size > 1;
158
183
  const out = [];
159
184
  for (const groupSegments of byColor.values()) {
160
- const groupColor = multiMaterial ? groupSegments[0].color : undefined;
161
- for (const p of this.buildColorGroupPolygons(groupSegments, groupColor))
162
- out.push(groupSegments[0].color ? { ...p, sourceColor: groupSegments[0].color } : p);
185
+ const layer = groupSegments[0];
186
+ for (const p of this.buildColorGroupPolygons(groupSegments, multiMaterial ? layer.color : undefined))
187
+ out.push({ ...p, ...layerStamp(layer) });
163
188
  }
164
189
  return out;
165
190
  }
@@ -178,7 +203,20 @@ export class PolygonBuilder {
178
203
  }));
179
204
  // Build closed loops. Multi-material (per-layer) groups additionally STITCH
180
205
  // disconnected open band segments at the interface chords (see `buildLoops`).
181
- const loops = this.buildLoops(segments2D, color !== undefined);
206
+ // Tessellation splits (a triangle edge crossing the cut plane) leave
207
+ // collinear vertices on straight faces; drop them so ring vertices are real
208
+ // corners. The tolerance is far below the weld tolerance so finely
209
+ // tessellated arcs keep their vertices, but never below the float32
210
+ // rounding noise of the source coordinates: an origin-less element ~100 m
211
+ // out rounds each coordinate by a few µm, which pushes a split point on a
212
+ // sloped face off its chord by more than 1% of the weld tolerance. The
213
+ // floor uses the same LOCAL magnitude as the weld floor, so an element
214
+ // placed far away through its RTC origin is not given a looser one.
215
+ const collinearTolerance = Math.max(this.tolerance * 0.01, this.float32NoiseFloor);
216
+ const loops = this.buildLoops(segments2D, color !== undefined).map((loop) => ({
217
+ ...loop,
218
+ points: removeCollinearRingVertices(loop.points, collinearTolerance),
219
+ }));
182
220
  if (loops.length === 0)
183
221
  return [];
184
222
  // Classify loops as outer boundaries or holes
@@ -620,50 +658,4 @@ export class PolygonBuilder {
620
658
  return inside;
621
659
  }
622
660
  }
623
- // ═══════════════════════════════════════════════════════════════════════════
624
- // HELPER FUNCTIONS
625
- // ═══════════════════════════════════════════════════════════════════════════
626
- /**
627
- * Simplify polygon by removing collinear points
628
- */
629
- export function simplifyPolygon(points, tolerance = 0.001) {
630
- if (points.length < 3)
631
- return points;
632
- const result = [];
633
- for (let i = 0; i < points.length; i++) {
634
- const prev = points[(i - 1 + points.length) % points.length];
635
- const curr = points[i];
636
- const next = points[(i + 1) % points.length];
637
- // Check if current point is on the line between prev and next
638
- if (!isCollinear(prev, curr, next, tolerance)) {
639
- result.push(curr);
640
- }
641
- }
642
- return result.length >= 3 ? result : points;
643
- }
644
- /**
645
- * Check if three points are collinear
646
- */
647
- function isCollinear(a, b, c, tolerance) {
648
- // Area of triangle formed by the three points
649
- const area = Math.abs((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y));
650
- return area < tolerance;
651
- }
652
- /**
653
- * Compute polygon bounds
654
- */
655
- export function polygonBounds(points) {
656
- let minX = Infinity, minY = Infinity;
657
- let maxX = -Infinity, maxY = -Infinity;
658
- for (const p of points) {
659
- minX = Math.min(minX, p.x);
660
- minY = Math.min(minY, p.y);
661
- maxX = Math.max(maxX, p.x);
662
- maxY = Math.max(maxY, p.y);
663
- }
664
- return {
665
- min: { x: minX, y: minY },
666
- max: { x: maxX, y: maxY },
667
- };
668
- }
669
661
  //# sourceMappingURL=polygon-builder.js.map