fluidcad 0.0.2 → 0.0.4

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 (123) hide show
  1. package/README.md +7 -7
  2. package/lib/dist/common/shape-factory.d.ts +1 -1
  3. package/lib/dist/oc/boolean-ops.d.ts +2 -2
  4. package/lib/dist/tsconfig.tsbuildinfo +1 -1
  5. package/package.json +3 -2
  6. package/lib/dist/constraints/constraint.d.ts +0 -11
  7. package/lib/dist/constraints/constraint.js +0 -51
  8. package/lib/dist/constraints/outside.d.ts +0 -3
  9. package/lib/dist/constraints/outside.js +0 -4
  10. package/lib/dist/core/2d/aslot.d.ts +0 -12
  11. package/lib/dist/core/2d/aslot.js +0 -40
  12. package/lib/dist/core/2d/crect.d.ts +0 -12
  13. package/lib/dist/core/2d/crect.js +0 -74
  14. package/lib/dist/core/2d/face-maker.d.ts +0 -13
  15. package/lib/dist/core/2d/face-maker.js +0 -119
  16. package/lib/dist/core/2d/face-maker2.d.ts +0 -6
  17. package/lib/dist/core/2d/face-maker2.js +0 -54
  18. package/lib/dist/core/region.d.ts +0 -13
  19. package/lib/dist/core/region.js +0 -18
  20. package/lib/dist/features/2d/amove.d.ts +0 -14
  21. package/lib/dist/features/2d/amove.js +0 -33
  22. package/lib/dist/features/2d/constraints/constraint.d.ts +0 -11
  23. package/lib/dist/features/2d/constraints/constraint.js +0 -49
  24. package/lib/dist/features/2d/constraints/outside.d.ts +0 -3
  25. package/lib/dist/features/2d/constraints/outside.js +0 -4
  26. package/lib/dist/features/2d/tarc-two-circles.d.ts +0 -18
  27. package/lib/dist/features/2d/tarc-two-circles.js +0 -61
  28. package/lib/dist/features/2d/tcircle-three-tan.d.ts +0 -13
  29. package/lib/dist/features/2d/tcircle-three-tan.js +0 -33
  30. package/lib/dist/features/2d/tcircle-two-tan.d.ts +0 -13
  31. package/lib/dist/features/2d/tcircle-two-tan.js +0 -33
  32. package/lib/dist/features/Extrude.d.ts +0 -1
  33. package/lib/dist/features/Extrude.js +0 -1
  34. package/lib/dist/features/cut-base.d.ts +0 -49
  35. package/lib/dist/features/cut-base.js +0 -312
  36. package/lib/dist/features/cut-symmetric.d.ts +0 -23
  37. package/lib/dist/features/cut-symmetric.js +0 -119
  38. package/lib/dist/features/cut-two-distances.d.ts +0 -24
  39. package/lib/dist/features/cut-two-distances.js +0 -110
  40. package/lib/dist/features/cut.d.ts +0 -27
  41. package/lib/dist/features/cut.js +0 -101
  42. package/lib/dist/features/extrude-symmetric.d.ts +0 -28
  43. package/lib/dist/features/extrude-symmetric.js +0 -177
  44. package/lib/dist/features/region2d.d.ts +0 -25
  45. package/lib/dist/features/region2d.js +0 -185
  46. package/lib/dist/features/repeat-circular2d.d.ts +0 -17
  47. package/lib/dist/features/repeat-circular2d.js +0 -90
  48. package/lib/dist/features/repeat-linear2d.d.ts +0 -17
  49. package/lib/dist/features/repeat-linear2d.js +0 -114
  50. package/lib/dist/features/revolve-options.d.ts +0 -6
  51. package/lib/dist/features/revolve-options.js +0 -1
  52. package/lib/dist/features/split.d.ts +0 -14
  53. package/lib/dist/features/split.js +0 -74
  54. package/lib/dist/features/state-scene-object.d.ts +0 -15
  55. package/lib/dist/features/state-scene-object.js +0 -44
  56. package/lib/dist/features/state-select.d.ts +0 -21
  57. package/lib/dist/features/state-select.js +0 -73
  58. package/lib/dist/features/translate2d.d.ts +0 -16
  59. package/lib/dist/features/translate2d.js +0 -61
  60. package/lib/dist/filters/all-filter.d.ts +0 -8
  61. package/lib/dist/filters/all-filter.js +0 -12
  62. package/lib/dist/filters/near-point-filter.d.ts +0 -11
  63. package/lib/dist/filters/near-point-filter.js +0 -33
  64. package/lib/dist/helpers/resolve-filters.d.ts +0 -6
  65. package/lib/dist/helpers/resolve-filters.js +0 -25
  66. package/lib/dist/math/axis.test.d.ts +0 -1
  67. package/lib/dist/math/axis.test.js +0 -287
  68. package/lib/dist/math/coordinate-system.test.d.ts +0 -1
  69. package/lib/dist/math/coordinate-system.test.js +0 -308
  70. package/lib/dist/math/matrix4.test.d.ts +0 -1
  71. package/lib/dist/math/matrix4.test.js +0 -357
  72. package/lib/dist/math/plane.test.d.ts +0 -1
  73. package/lib/dist/math/plane.test.js +0 -398
  74. package/lib/dist/math/point.test.d.ts +0 -1
  75. package/lib/dist/math/point.test.js +0 -385
  76. package/lib/dist/math/quaternion.test.d.ts +0 -1
  77. package/lib/dist/math/quaternion.test.js +0 -278
  78. package/lib/dist/math/vector3d.test.d.ts +0 -1
  79. package/lib/dist/math/vector3d.test.js +0 -276
  80. package/lib/dist/oc/constraint-resolver.d.ts +0 -7
  81. package/lib/dist/oc/constraint-resolver.js +0 -31
  82. package/lib/dist/oc/constraints/curve-constraint-solver.d.ts +0 -1
  83. package/lib/dist/oc/constraints/curve-constraint-solver.js +0 -2
  84. package/lib/dist/oc/constraints/geometric-constraint-solver.d.ts +0 -1
  85. package/lib/dist/oc/constraints/geometric-constraint-solver.js +0 -5
  86. package/lib/dist/oc/face-maker.d.ts +0 -14
  87. package/lib/dist/oc/face-maker.js +0 -191
  88. package/lib/dist/oc/measure.d.ts +0 -21
  89. package/lib/dist/oc/measure.js +0 -256
  90. package/lib/dist/oc/tangent-circle-solver.d.ts +0 -17
  91. package/lib/dist/oc/tangent-circle-solver.js +0 -72
  92. package/lib/dist/oc/tangent-line-solver.d.ts +0 -17
  93. package/lib/dist/oc/tangent-line-solver.js +0 -83
  94. package/lib/dist/oc/tangent-solver.d.ts +0 -14
  95. package/lib/dist/oc/tangent-solver.js +0 -199
  96. package/lib/dist/rendering/builder-context.d.ts +0 -16
  97. package/lib/dist/rendering/builder-context.js +0 -63
  98. package/lib/dist/tests/extrude.test.d.ts +0 -1
  99. package/lib/dist/tests/extrude.test.js +0 -48
  100. package/lib/dist/tests/features/copy.test.d.ts +0 -1
  101. package/lib/dist/tests/features/copy.test.js +0 -158
  102. package/lib/dist/tests/features/dispose.test.d.ts +0 -1
  103. package/lib/dist/tests/features/dispose.test.js +0 -189
  104. package/lib/dist/tests/features/part-pick.test.d.ts +0 -1
  105. package/lib/dist/tests/features/part-pick.test.js +0 -73
  106. package/lib/dist/tests/features/part-repeat.test.d.ts +0 -1
  107. package/lib/dist/tests/features/part-repeat.test.js +0 -109
  108. package/server/dist/fluidcad-server.d.ts +0 -32
  109. package/server/dist/fluidcad-server.js +0 -150
  110. package/server/dist/index.d.ts +0 -1
  111. package/server/dist/index.js +0 -290
  112. package/server/dist/routes/actions.d.ts +0 -3
  113. package/server/dist/routes/actions.js +0 -100
  114. package/server/dist/routes/export.d.ts +0 -3
  115. package/server/dist/routes/export.js +0 -55
  116. package/server/dist/routes/properties.d.ts +0 -3
  117. package/server/dist/routes/properties.js +0 -46
  118. package/server/dist/routes/screenshot.d.ts +0 -2
  119. package/server/dist/routes/screenshot.js +0 -76
  120. package/server/dist/vite-manager.d.ts +0 -10
  121. package/server/dist/vite-manager.js +0 -64
  122. package/server/dist/ws-protocol.d.ts +0 -138
  123. package/server/dist/ws-protocol.js +0 -4
@@ -1,276 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { Vector3d, normalizeVector } from "./vector3d.js";
3
- describe("Vector3d", () => {
4
- describe("constructor", () => {
5
- it("creates a vector with x, y, z components", () => {
6
- const v = new Vector3d(1, 2, 3);
7
- expect(v.x).toBe(1);
8
- expect(v.y).toBe(2);
9
- expect(v.z).toBe(3);
10
- });
11
- });
12
- describe("equals", () => {
13
- it("returns true for identical vectors", () => {
14
- const v1 = new Vector3d(1, 2, 3);
15
- const v2 = new Vector3d(1, 2, 3);
16
- expect(v1.equals(v2)).toBe(true);
17
- });
18
- it("returns false for different vectors", () => {
19
- const v1 = new Vector3d(1, 2, 3);
20
- const v2 = new Vector3d(1, 2, 4);
21
- expect(v1.equals(v2)).toBe(false);
22
- });
23
- it("supports tolerance", () => {
24
- const v1 = new Vector3d(1, 2, 3);
25
- const v2 = new Vector3d(1.001, 2.001, 3.001);
26
- expect(v1.equals(v2, 0.01)).toBe(true);
27
- expect(v1.equals(v2, 0.0001)).toBe(false);
28
- });
29
- });
30
- describe("dot", () => {
31
- it("computes dot product correctly", () => {
32
- const v1 = new Vector3d(1, 2, 3);
33
- const v2 = new Vector3d(4, 5, 6);
34
- expect(v1.dot(v2)).toBe(32); // 1*4 + 2*5 + 3*6
35
- });
36
- it("returns 0 for perpendicular vectors", () => {
37
- const v1 = new Vector3d(1, 0, 0);
38
- const v2 = new Vector3d(0, 1, 0);
39
- expect(v1.dot(v2)).toBe(0);
40
- });
41
- });
42
- describe("cross", () => {
43
- it("computes cross product correctly", () => {
44
- const v1 = new Vector3d(1, 0, 0);
45
- const v2 = new Vector3d(0, 1, 0);
46
- const result = v1.cross(v2);
47
- expect(result.x).toBe(0);
48
- expect(result.y).toBe(0);
49
- expect(result.z).toBe(1);
50
- });
51
- it("returns zero vector for parallel vectors", () => {
52
- const v1 = new Vector3d(1, 0, 0);
53
- const v2 = new Vector3d(2, 0, 0);
54
- const result = v1.cross(v2);
55
- expect(result.isZero()).toBe(true);
56
- });
57
- });
58
- describe("length", () => {
59
- it("computes length correctly", () => {
60
- const v = new Vector3d(3, 4, 0);
61
- expect(v.length()).toBe(5);
62
- });
63
- it("returns 0 for zero vector", () => {
64
- const v = new Vector3d(0, 0, 0);
65
- expect(v.length()).toBe(0);
66
- });
67
- });
68
- describe("normalize", () => {
69
- it("returns unit vector", () => {
70
- const v = new Vector3d(3, 4, 0);
71
- const normalized = v.normalize();
72
- expect(normalized.length()).toBeCloseTo(1);
73
- expect(normalized.x).toBeCloseTo(0.6);
74
- expect(normalized.y).toBeCloseTo(0.8);
75
- expect(normalized.z).toBe(0);
76
- });
77
- it("throws for zero vector", () => {
78
- const v = new Vector3d(0, 0, 0);
79
- expect(() => v.normalize()).toThrow();
80
- });
81
- });
82
- describe("add", () => {
83
- it("adds vectors correctly", () => {
84
- const v1 = new Vector3d(1, 2, 3);
85
- const v2 = new Vector3d(4, 5, 6);
86
- const result = v1.add(v2);
87
- expect(result.x).toBe(5);
88
- expect(result.y).toBe(7);
89
- expect(result.z).toBe(9);
90
- });
91
- it("is immutable", () => {
92
- const v1 = new Vector3d(1, 2, 3);
93
- const v2 = new Vector3d(4, 5, 6);
94
- v1.add(v2);
95
- expect(v1.x).toBe(1);
96
- });
97
- });
98
- describe("subtract", () => {
99
- it("subtracts vectors correctly", () => {
100
- const v1 = new Vector3d(4, 5, 6);
101
- const v2 = new Vector3d(1, 2, 3);
102
- const result = v1.subtract(v2);
103
- expect(result.x).toBe(3);
104
- expect(result.y).toBe(3);
105
- expect(result.z).toBe(3);
106
- });
107
- });
108
- describe("multiply", () => {
109
- it("multiplies by scalar correctly", () => {
110
- const v = new Vector3d(1, 2, 3);
111
- const result = v.multiply(2);
112
- expect(result.x).toBe(2);
113
- expect(result.y).toBe(4);
114
- expect(result.z).toBe(6);
115
- });
116
- });
117
- describe("negate", () => {
118
- it("negates vector correctly", () => {
119
- const v = new Vector3d(1, -2, 3);
120
- const result = v.negate();
121
- expect(result.x).toBe(-1);
122
- expect(result.y).toBe(2);
123
- expect(result.z).toBe(-3);
124
- });
125
- });
126
- describe("isZero", () => {
127
- it("returns true for zero vector", () => {
128
- const v = new Vector3d(0, 0, 0);
129
- expect(v.isZero()).toBe(true);
130
- });
131
- it("returns false for non-zero vector", () => {
132
- const v = new Vector3d(0.001, 0, 0);
133
- expect(v.isZero()).toBe(false);
134
- });
135
- it("supports tolerance", () => {
136
- const v = new Vector3d(0.001, 0.001, 0.001);
137
- expect(v.isZero(0.01)).toBe(true);
138
- });
139
- });
140
- describe("angleTo", () => {
141
- it("returns 0 for same direction", () => {
142
- const v1 = new Vector3d(1, 0, 0);
143
- const v2 = new Vector3d(2, 0, 0);
144
- expect(v1.angleTo(v2)).toBeCloseTo(0);
145
- });
146
- it("returns PI/2 for perpendicular vectors", () => {
147
- const v1 = new Vector3d(1, 0, 0);
148
- const v2 = new Vector3d(0, 1, 0);
149
- expect(v1.angleTo(v2)).toBeCloseTo(Math.PI / 2);
150
- });
151
- it("returns PI for opposite directions", () => {
152
- const v1 = new Vector3d(1, 0, 0);
153
- const v2 = new Vector3d(-1, 0, 0);
154
- expect(v1.angleTo(v2)).toBeCloseTo(Math.PI);
155
- });
156
- });
157
- describe("projectOnto", () => {
158
- it("projects vector correctly", () => {
159
- const v = new Vector3d(3, 4, 0);
160
- const onto = new Vector3d(1, 0, 0);
161
- const result = v.projectOnto(onto);
162
- expect(result.x).toBeCloseTo(3);
163
- expect(result.y).toBeCloseTo(0);
164
- expect(result.z).toBeCloseTo(0);
165
- });
166
- });
167
- describe("reflect", () => {
168
- it("reflects vector correctly", () => {
169
- const v = new Vector3d(1, -1, 0);
170
- const normal = new Vector3d(0, 1, 0);
171
- const result = v.reflect(normal);
172
- expect(result.x).toBeCloseTo(1);
173
- expect(result.y).toBeCloseTo(1);
174
- expect(result.z).toBeCloseTo(0);
175
- });
176
- });
177
- describe("lerp", () => {
178
- it("interpolates at t=0", () => {
179
- const v1 = new Vector3d(0, 0, 0);
180
- const v2 = new Vector3d(10, 10, 10);
181
- const result = v1.lerp(v2, 0);
182
- expect(result.equals(v1)).toBe(true);
183
- });
184
- it("interpolates at t=1", () => {
185
- const v1 = new Vector3d(0, 0, 0);
186
- const v2 = new Vector3d(10, 10, 10);
187
- const result = v1.lerp(v2, 1);
188
- expect(result.equals(v2)).toBe(true);
189
- });
190
- it("interpolates at t=0.5", () => {
191
- const v1 = new Vector3d(0, 0, 0);
192
- const v2 = new Vector3d(10, 10, 10);
193
- const result = v1.lerp(v2, 0.5);
194
- expect(result.x).toBe(5);
195
- expect(result.y).toBe(5);
196
- expect(result.z).toBe(5);
197
- });
198
- });
199
- describe("isParallelTo", () => {
200
- it("returns true for parallel vectors", () => {
201
- const v1 = new Vector3d(1, 0, 0);
202
- const v2 = new Vector3d(5, 0, 0);
203
- expect(v1.isParallelTo(v2)).toBe(true);
204
- });
205
- it("returns true for anti-parallel vectors", () => {
206
- const v1 = new Vector3d(1, 0, 0);
207
- const v2 = new Vector3d(-5, 0, 0);
208
- expect(v1.isParallelTo(v2)).toBe(true);
209
- });
210
- it("returns false for non-parallel vectors", () => {
211
- const v1 = new Vector3d(1, 0, 0);
212
- const v2 = new Vector3d(1, 1, 0);
213
- expect(v1.isParallelTo(v2)).toBe(false);
214
- });
215
- });
216
- describe("isPerpendicularTo", () => {
217
- it("returns true for perpendicular vectors", () => {
218
- const v1 = new Vector3d(1, 0, 0);
219
- const v2 = new Vector3d(0, 1, 0);
220
- expect(v1.isPerpendicularTo(v2)).toBe(true);
221
- });
222
- it("returns false for non-perpendicular vectors", () => {
223
- const v1 = new Vector3d(1, 0, 0);
224
- const v2 = new Vector3d(1, 1, 0);
225
- expect(v1.isPerpendicularTo(v2)).toBe(false);
226
- });
227
- });
228
- describe("static methods", () => {
229
- it("unitX returns (1,0,0)", () => {
230
- const v = Vector3d.unitX();
231
- expect(v.x).toBe(1);
232
- expect(v.y).toBe(0);
233
- expect(v.z).toBe(0);
234
- });
235
- it("unitY returns (0,1,0)", () => {
236
- const v = Vector3d.unitY();
237
- expect(v.x).toBe(0);
238
- expect(v.y).toBe(1);
239
- expect(v.z).toBe(0);
240
- });
241
- it("unitZ returns (0,0,1)", () => {
242
- const v = Vector3d.unitZ();
243
- expect(v.x).toBe(0);
244
- expect(v.y).toBe(0);
245
- expect(v.z).toBe(1);
246
- });
247
- it("zero returns (0,0,0)", () => {
248
- const v = Vector3d.zero();
249
- expect(v.isZero()).toBe(true);
250
- });
251
- it("fromArray creates vector from array", () => {
252
- const v = Vector3d.fromArray([1, 2, 3]);
253
- expect(v.x).toBe(1);
254
- expect(v.y).toBe(2);
255
- expect(v.z).toBe(3);
256
- });
257
- });
258
- describe("toVector3d helper", () => {
259
- it("returns same instance for Vector3d", () => {
260
- const v = new Vector3d(1, 2, 3);
261
- expect(normalizeVector(v)).toBe(v);
262
- });
263
- it("converts array to Vector3d", () => {
264
- const v = normalizeVector([1, 2, 3]);
265
- expect(v.x).toBe(1);
266
- expect(v.y).toBe(2);
267
- expect(v.z).toBe(3);
268
- });
269
- it("converts object to Vector3d", () => {
270
- const v = normalizeVector({ x: 1, y: 2, z: 3 });
271
- expect(v.x).toBe(1);
272
- expect(v.y).toBe(2);
273
- expect(v.z).toBe(3);
274
- });
275
- });
276
- });
@@ -1,7 +0,0 @@
1
- import type { GccEnt_Position, GccEnt_QualifiedCirc, GccEnt_QualifiedLin, gp_Circ, gp_Circ2d, gp_Lin, gp_Lin2d, gp_Pln, gp_Pnt, gp_Pnt2d } from "occjs-wrapper";
2
- import { ConstraintQualifier } from "../features/2d/constraints/qualified-geometry.js";
3
- export declare class ConstraintResolver {
4
- static get2dGeometry<T extends gp_Circ | gp_Lin | gp_Pnt>(plane: gp_Pln, geometry: T): gp_Lin2d | gp_Circ2d | gp_Pnt2d;
5
- static getQualifier(qualifier: ConstraintQualifier): GccEnt_Position;
6
- static getQualified(plane: gp_Pln, geometry: gp_Circ | gp_Lin, qualifier: ConstraintQualifier): GccEnt_QualifiedCirc | GccEnt_QualifiedLin;
7
- }
@@ -1,31 +0,0 @@
1
- import { getOC } from "./init.js";
2
- export class ConstraintResolver {
3
- static get2dGeometry(plane, geometry) {
4
- const oc = getOC();
5
- return oc.ProjLib.Project(plane, geometry);
6
- }
7
- static getQualifier(qualifier) {
8
- const oc = getOC();
9
- switch (qualifier) {
10
- case 'unqualified':
11
- return oc.GccEnt_Position.GccEnt_unqualified;
12
- case 'enclosed':
13
- return oc.GccEnt_Position.GccEnt_enclosed;
14
- case 'enclosing':
15
- return oc.GccEnt_Position.GccEnt_enclosing;
16
- case 'outside':
17
- return oc.GccEnt_Position.GccEnt_outside;
18
- }
19
- }
20
- static getQualified(plane, geometry, qualifier) {
21
- const oc = getOC();
22
- const geom = this.get2dGeometry(plane, geometry);
23
- if (geom instanceof oc.gp_Circ2d) {
24
- return new oc.GccEnt_QualifiedCirc(geom, this.getQualifier(qualifier));
25
- }
26
- else if (geom instanceof oc.gp_Lin2d) {
27
- return new oc.GccEnt_QualifiedLin(geom, this.getQualifier(qualifier));
28
- }
29
- throw new Error('Unsupported geometry type');
30
- }
31
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- getQualifiedGeometry;
2
- export {};
@@ -1,5 +0,0 @@
1
- getQualifiedGeometry;
2
- getQualifiedGeometry;
3
- getQualifiedGeometry;
4
- getQualifiedGeometry;
5
- export {};
@@ -1,14 +0,0 @@
1
- import type { TopoDS_Compound, gp_Pln, TopoDS_Face, TopoDS_Wire } from "occjs-wrapper";
2
- import type { BoundingBox, FaceInfo } from "../helpers/types.js";
3
- export declare class OcFaceMaker {
4
- static createFacesFromWires(wires: TopoDS_Wire[], gpPln: gp_Pln): TopoDS_Face[];
5
- static fuseIntersectingFaces(faces: TopoDS_Face[]): TopoDS_Face[];
6
- static unifyFaces(facesCompound: TopoDS_Compound): TopoDS_Face;
7
- static boundingBoxesIntersect(bbox1: BoundingBox, bbox2: BoundingBox): boolean;
8
- static getWiresFromFaces(faces: TopoDS_Face[]): TopoDS_Wire[];
9
- static drillHoles(faceInfos: FaceInfo[]): FaceInfo[];
10
- private static getFaceHoles;
11
- private static wireIsInsideFace;
12
- private static getFirstPointOfWire;
13
- private static hitTest;
14
- }
@@ -1,191 +0,0 @@
1
- import { getOC } from "./init.js";
2
- import { Explorer } from "./explorer.js";
3
- import { ShapeOps } from "./shape-ops.js";
4
- import { FaceOps } from "./face-ops.js";
5
- import { Face } from "../common/face.js";
6
- export class OcFaceMaker {
7
- static createFacesFromWires(wires, gpPln) {
8
- const oc = getOC();
9
- if (wires.length === 0)
10
- return [];
11
- console.log("Creating faces from wires:", wires.length);
12
- const faces = [];
13
- for (let wire of wires) {
14
- const face = FaceOps.makeFaceOnPlane(oc.TopoDS.Wire(wire), gpPln);
15
- const fixer = new oc.ShapeFix_Face(face);
16
- fixer.FixOrientation();
17
- fixer.Perform();
18
- const fixedFace = fixer.Face();
19
- faces.push(fixedFace);
20
- fixer.delete();
21
- face.delete();
22
- }
23
- return faces;
24
- }
25
- static fuseIntersectingFaces(faces) {
26
- const oc = getOC();
27
- if (faces.length === 0)
28
- return [];
29
- if (faces.length === 1)
30
- return faces;
31
- const faceBoxes = faces.map((face, index) => ({
32
- face,
33
- index,
34
- bbox: ShapeOps.getBoundingBox(face)
35
- }));
36
- const result = [];
37
- const processedFaces = new Set();
38
- for (let i = 0; i < faces.length; i++) {
39
- const face1 = faces[i];
40
- if (processedFaces.has(face1)) {
41
- continue;
42
- }
43
- let fusedFace = face1;
44
- const facesToFuse = [face1];
45
- let bbox1 = faceBoxes[i].bbox;
46
- for (let j = i + 1; j < faces.length; j++) {
47
- const face2 = faces[j];
48
- if (processedFaces.has(face2)) {
49
- continue;
50
- }
51
- const bbox2 = faceBoxes[j].bbox;
52
- if (!OcFaceMaker.boundingBoxesIntersect(bbox1, bbox2)) {
53
- continue;
54
- }
55
- const progress = new oc.Message_ProgressRange();
56
- const fuseMaker = new oc.BRepAlgoAPI_Fuse(fusedFace, face2, progress);
57
- if (fuseMaker.IsDone()) {
58
- const newShape = fuseMaker.Shape();
59
- if (!newShape.IsNull()) {
60
- if (newShape.ShapeType() === oc.TopAbs_ShapeEnum.TopAbs_COMPOUND) {
61
- const facesInCompound = Explorer.findShapes(newShape, oc.TopAbs_ShapeEnum.TopAbs_FACE);
62
- console.log("Fused faces into a compound, found faces:", facesInCompound.length);
63
- if (facesInCompound.length > 2) {
64
- fusedFace = OcFaceMaker.unifyFaces(newShape);
65
- bbox1 = ShapeOps.getBoundingBox(fusedFace);
66
- facesToFuse.push(face2);
67
- }
68
- }
69
- }
70
- }
71
- progress.delete();
72
- fuseMaker.delete();
73
- }
74
- result.push(fusedFace);
75
- facesToFuse.forEach(face => processedFaces.add(face));
76
- }
77
- console.log("Fused faces count:", result.length);
78
- return result;
79
- }
80
- static unifyFaces(facesCompound) {
81
- console.log("Unifying faces compound:", facesCompound);
82
- const oc = getOC();
83
- const freeBounds = new oc.ShapeAnalysis_FreeBounds(facesCompound, oc.Precision.Confusion(), true, false);
84
- const closedWiresCompound = freeBounds.GetClosedWires();
85
- const firstWire = Explorer.findFirstShapeOfType(closedWiresCompound, oc.TopAbs_ShapeEnum.TopAbs_WIRE);
86
- freeBounds.delete();
87
- return FaceOps.makeFace(oc.TopoDS.Wire(firstWire));
88
- }
89
- static boundingBoxesIntersect(bbox1, bbox2) {
90
- return !(bbox1.maxX < bbox2.minX || bbox2.maxX < bbox1.minX ||
91
- bbox1.maxY < bbox2.minY || bbox2.maxY < bbox1.minY);
92
- }
93
- static getWiresFromFaces(faces) {
94
- const oc = getOC();
95
- const wires = [];
96
- for (let face of faces) {
97
- const faceWires = Explorer.findShapes(face, oc.TopAbs_ShapeEnum.TopAbs_WIRE);
98
- console.log("Found wires in face:", faceWires.length);
99
- for (const wire of faceWires) {
100
- wires.push(oc.TopoDS.Wire(wire));
101
- }
102
- }
103
- return wires;
104
- }
105
- static drillHoles(faceInfos) {
106
- const oc = getOC();
107
- const foundHoles = [];
108
- let drilledFaces = [];
109
- for (const faceInfo of faceInfos) {
110
- if (foundHoles.includes(faceInfo)) {
111
- continue;
112
- }
113
- const faceHoles = OcFaceMaker.getFaceHoles(faceInfo, faceInfos, foundHoles);
114
- console.log("Found holes for face:", faceHoles.length);
115
- if (faceHoles.length === 0) {
116
- drilledFaces.push(faceInfo);
117
- continue;
118
- }
119
- faceInfo.holes = faceHoles;
120
- drilledFaces.push(faceInfo);
121
- for (const hole of faceHoles) {
122
- foundHoles.push(hole);
123
- }
124
- }
125
- console.log("Found holes:", foundHoles.length);
126
- console.log("Drilled faces before removing holes:", drilledFaces.length);
127
- drilledFaces = drilledFaces.filter(info => !foundHoles.includes(info));
128
- console.log("Drilled faces:", drilledFaces.length);
129
- for (const info of drilledFaces) {
130
- const holes = info.holes;
131
- if (!holes?.length) {
132
- continue;
133
- }
134
- const rawWire = info.wire.getShape();
135
- const faceMaker = new oc.BRepLib_MakeFace(rawWire, false);
136
- for (const hole of holes) {
137
- const holeWire = hole.wire.getShape();
138
- holeWire.Reverse();
139
- faceMaker.Add(holeWire);
140
- }
141
- const newFace = faceMaker.Face();
142
- info.face = Face.fromTopoDSFace(newFace);
143
- for (const hole of holes) {
144
- hole.wire.getShape().delete();
145
- hole.face.getShape().delete();
146
- }
147
- info.holes = [];
148
- }
149
- return drilledFaces;
150
- }
151
- static getFaceHoles(faceInfo, allFaceInfos, exclude) {
152
- const holes = [];
153
- for (let fInfo of allFaceInfos) {
154
- if (fInfo === faceInfo || exclude.includes(faceInfo)) {
155
- continue;
156
- }
157
- if (OcFaceMaker.wireIsInsideFace(fInfo, faceInfo)) {
158
- holes.push(fInfo);
159
- }
160
- }
161
- return holes;
162
- }
163
- static wireIsInsideFace(inner, outer) {
164
- const firstPoint = OcFaceMaker.getFirstPointOfWire(inner.wire.getShape());
165
- return OcFaceMaker.hitTest(firstPoint, outer.face.getShape());
166
- }
167
- static getFirstPointOfWire(wire) {
168
- const oc = getOC();
169
- try {
170
- const edges = Explorer.findShapes(wire, oc.TopAbs_ShapeEnum.TopAbs_EDGE);
171
- const firstEdge = oc.TopoDS.Edge(edges[0]);
172
- const vertex = oc.TopExp.FirstVertex(firstEdge, true);
173
- const point = oc.BRep_Tool.Pnt(vertex);
174
- return point;
175
- }
176
- catch (error) {
177
- console.error("Error getting first point of wire:", error);
178
- return null;
179
- }
180
- }
181
- static hitTest(point, face) {
182
- const oc = getOC();
183
- const classifier = new oc.BRepClass_FaceClassifier();
184
- classifier.Perform(face, point, oc.Precision.Confusion(), true, oc.Precision.Confusion());
185
- const state = classifier.State();
186
- const isInside = state === oc.TopAbs_State.TopAbs_IN ||
187
- state === oc.TopAbs_State.TopAbs_ON;
188
- classifier.delete();
189
- return isInside;
190
- }
191
- }
@@ -1,21 +0,0 @@
1
- import type { TopoDS_Shape } from "occjs-wrapper";
2
- export interface MeasurementEntry {
3
- label: string;
4
- value: number;
5
- unit: 'mm' | 'deg';
6
- icon: 'distance' | 'angle' | 'radius';
7
- axisBreakdown?: {
8
- dx: number;
9
- dy: number;
10
- dz: number;
11
- };
12
- }
13
- export interface MeasurementResult {
14
- headline: MeasurementEntry;
15
- others: MeasurementEntry[];
16
- refPointA: [number, number, number];
17
- refPointB: [number, number, number];
18
- }
19
- export declare class OccMeasure {
20
- static compute(shapeA: TopoDS_Shape, typeA: 'face' | 'edge', indexA: number, shapeB: TopoDS_Shape, typeB: 'face' | 'edge', indexB: number): MeasurementResult | null;
21
- }