@buerli.io/core 0.10.0 → 0.11.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 (81) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/README.md +12 -12
  3. package/build/cjs/geometry/ThreeGeometryCreator.js +320 -320
  4. package/build/cjs/geometry/index.js +17 -17
  5. package/build/cjs/graphic/filters.js +25 -25
  6. package/build/cjs/index.js +25 -25
  7. package/build/cjs/store/index.js +37 -37
  8. package/build/cjs/store/states/buerli.js +98 -98
  9. package/build/cjs/store/states/cad.js +47 -35
  10. package/build/cjs/store/states/drawing.js +49 -49
  11. package/build/cjs/store/states/geometry.js +137 -137
  12. package/build/cjs/store/states/graphic.js +112 -112
  13. package/build/cjs/store/states/interaction.js +55 -55
  14. package/build/cjs/store/states/message.js +25 -25
  15. package/build/cjs/store/states/plugin.js +115 -115
  16. package/build/cjs/store/states/selection.js +267 -267
  17. package/build/cjs/store/states/structure.js +250 -250
  18. package/build/cjs/store/store.js +9 -9
  19. package/build/cjs/store/subscribtion/selection.js +49 -49
  20. package/build/cjs/store/subscribtion/subscribeToDrawing.js +13 -13
  21. package/build/cjs/types/IGraphicPackage.js +46 -46
  22. package/build/cjs/types/IStructurePatch.js +2 -2
  23. package/build/cjs/types/IStructureTree.js +28 -28
  24. package/build/cjs/types/InteractionInfo.js +11 -11
  25. package/build/cjs/types/index.js +20 -20
  26. package/build/cjs/utils/Math.js +91 -91
  27. package/build/cjs/utils/Measure.js +576 -576
  28. package/build/cjs/utils/Timing.js +34 -34
  29. package/build/esm/geometry/ThreeGeometryCreator.js +291 -291
  30. package/build/esm/geometry/index.js +1 -1
  31. package/build/esm/graphic/filters.js +12 -12
  32. package/build/esm/index.js +9 -9
  33. package/build/esm/store/index.js +26 -26
  34. package/build/esm/store/states/buerli.js +92 -92
  35. package/build/esm/store/states/cad.js +42 -30
  36. package/build/esm/store/states/drawing.js +45 -45
  37. package/build/esm/store/states/geometry.js +109 -109
  38. package/build/esm/store/states/graphic.js +107 -107
  39. package/build/esm/store/states/interaction.js +50 -50
  40. package/build/esm/store/states/message.js +21 -21
  41. package/build/esm/store/states/plugin.js +109 -109
  42. package/build/esm/store/states/selection.js +261 -261
  43. package/build/esm/store/states/structure.js +219 -219
  44. package/build/esm/store/store.js +3 -3
  45. package/build/esm/store/subscribtion/selection.js +44 -44
  46. package/build/esm/store/subscribtion/subscribeToDrawing.js +9 -9
  47. package/build/esm/types/IGraphicPackage.js +43 -43
  48. package/build/esm/types/IStructurePatch.js +1 -1
  49. package/build/esm/types/IStructureTree.js +24 -24
  50. package/build/esm/types/InteractionInfo.js +6 -6
  51. package/build/esm/types/index.js +4 -4
  52. package/build/esm/utils/Math.js +65 -65
  53. package/build/esm/utils/Measure.js +550 -550
  54. package/build/esm/utils/Timing.js +31 -31
  55. package/build/types/geometry/ThreeGeometryCreator.d.ts +256 -256
  56. package/build/types/geometry/index.d.ts +1 -1
  57. package/build/types/graphic/filters.d.ts +11 -11
  58. package/build/types/index.d.ts +37 -37
  59. package/build/types/store/index.d.ts +16 -16
  60. package/build/types/store/states/buerli.d.ts +41 -41
  61. package/build/types/store/states/cad.d.ts +53 -42
  62. package/build/types/store/states/drawing.d.ts +45 -45
  63. package/build/types/store/states/geometry.d.ts +63 -63
  64. package/build/types/store/states/graphic.d.ts +22 -22
  65. package/build/types/store/states/interaction.d.ts +34 -34
  66. package/build/types/store/states/message.d.ts +30 -30
  67. package/build/types/store/states/plugin.d.ts +53 -53
  68. package/build/types/store/states/selection.d.ts +62 -62
  69. package/build/types/store/states/structure.d.ts +47 -47
  70. package/build/types/store/store.d.ts +2 -2
  71. package/build/types/store/subscribtion/selection.d.ts +7 -7
  72. package/build/types/store/subscribtion/subscribeToDrawing.d.ts +4 -4
  73. package/build/types/types/IGraphicPackage.d.ts +157 -155
  74. package/build/types/types/IStructurePatch.d.ts +6 -6
  75. package/build/types/types/IStructureTree.d.ts +80 -80
  76. package/build/types/types/InteractionInfo.d.ts +43 -43
  77. package/build/types/types/index.d.ts +4 -4
  78. package/build/types/utils/Math.d.ts +21 -21
  79. package/build/types/utils/Measure.d.ts +64 -64
  80. package/build/types/utils/Timing.d.ts +8 -8
  81. package/package.json +44 -44
@@ -1,576 +1,576 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Measure = exports.MeasureResultType = void 0;
27
- /* eslint-disable max-lines */
28
- const THREE = __importStar(require("three"));
29
- const store_1 = require("./../store");
30
- const types_1 = require("./../types");
31
- var MeasureResultType;
32
- (function (MeasureResultType) {
33
- MeasureResultType["NONE"] = "none";
34
- MeasureResultType["VALUE"] = "value";
35
- MeasureResultType["DISTANCE"] = "linear";
36
- MeasureResultType["ANGLE"] = "angular";
37
- MeasureResultType["VECTOR"] = "vector";
38
- MeasureResultType["POSITION"] = "position";
39
- })(MeasureResultType = exports.MeasureResultType || (exports.MeasureResultType = {}));
40
- const tolerance = 1e-3;
41
- exports.Measure = {
42
- transform(items, drawingId) {
43
- const drawing = (0, store_1.getDrawing)(drawingId);
44
- const transformed = [];
45
- for (const item of items) {
46
- const matrix = drawing.api.structure.calculateGlobalTransformation(item.productId);
47
- const matrix3 = new THREE.Matrix3().setFromMatrix4(matrix);
48
- const newItem = Object.assign({}, item);
49
- switch (newItem.type) {
50
- case types_1.GraphicType.POINT:
51
- case types_1.GraphicType.CURVEPOINT:
52
- const point = newItem;
53
- point.position = point.position.clone().applyMatrix4(matrix);
54
- break;
55
- case types_1.GraphicType.LINE:
56
- case types_1.GraphicType.CURVELINE:
57
- const line = newItem;
58
- line.start = line.start.clone().applyMatrix4(matrix);
59
- line.end = line.end.clone().applyMatrix4(matrix);
60
- break;
61
- case types_1.GraphicType.PLANE:
62
- const plane = newItem;
63
- plane.normal = plane.normal.clone().applyMatrix3(matrix3);
64
- plane.normal.normalize();
65
- plane.pointOnPlane = plane.pointOnPlane.clone().applyMatrix4(matrix);
66
- break;
67
- case types_1.GraphicType.CYLINDER:
68
- const cylinder = newItem;
69
- cylinder.axis = cylinder.axis.clone().applyMatrix3(matrix3);
70
- cylinder.axis.normalize();
71
- cylinder.origin = cylinder.origin.clone().applyMatrix4(matrix);
72
- break;
73
- case types_1.GraphicType.CONE:
74
- const cone = newItem;
75
- cone.axis = cone.axis.clone().applyMatrix3(matrix3);
76
- cone.axis.normalize();
77
- cone.origin = cone.origin.clone().applyMatrix4(matrix);
78
- break;
79
- case types_1.GraphicType.ARC:
80
- case types_1.GraphicType.CURVEARC:
81
- const arc = newItem;
82
- arc.normal = arc.normal.clone().applyMatrix3(matrix3);
83
- arc.normal.normalize();
84
- arc.center = arc.center.clone().applyMatrix4(matrix);
85
- arc.start = arc.start.clone().applyMatrix4(matrix);
86
- arc.end = arc.end.clone().applyMatrix4(matrix);
87
- break;
88
- case types_1.GraphicType.CIRCLE:
89
- case types_1.GraphicType.CURVECIRCLE:
90
- const circle = newItem;
91
- circle.normal = circle.normal.clone().applyMatrix3(matrix3);
92
- circle.normal.normalize();
93
- circle.center = circle.center.clone().applyMatrix4(matrix);
94
- circle.start = circle.start.clone().applyMatrix4(matrix);
95
- circle.end = circle.end.clone().applyMatrix4(matrix);
96
- break;
97
- default:
98
- break;
99
- }
100
- transformed.push(newItem);
101
- }
102
- return transformed;
103
- },
104
- getInfo(objects, drawingId) {
105
- const transformed = exports.Measure.transform(objects, drawingId);
106
- const results = [];
107
- const dir = (start, end) => end.clone().sub(start).normalize();
108
- const getPointOnCircumference = (center, axis, radius) => {
109
- const axisNormalized = axis.clone().normalize();
110
- const helperVec = axisNormalized.x !== 1 ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 1, 0);
111
- const tangent = axisNormalized.clone().cross(helperVec).normalize();
112
- return center.clone().addScaledVector(tangent, radius);
113
- };
114
- for (const element of transformed) {
115
- switch (element.type) {
116
- case types_1.GraphicType.POINT:
117
- case types_1.GraphicType.CURVEPOINT:
118
- const point = element;
119
- results.push({
120
- description: 'Position',
121
- type: MeasureResultType.POSITION,
122
- measureData: { value: point.position.clone() },
123
- });
124
- break;
125
- case types_1.GraphicType.LINE:
126
- case types_1.GraphicType.CURVELINE:
127
- const line = element;
128
- const absoluteDistance = line.start.distanceTo(line.end);
129
- results.push({
130
- description: 'Line length',
131
- type: MeasureResultType.DISTANCE,
132
- measureData: { value: absoluteDistance, start: line.start.clone(), end: line.end.clone() },
133
- });
134
- break;
135
- case types_1.GraphicType.NURBSCURVE:
136
- case types_1.GraphicType.CURVESPLINE:
137
- const edge = element;
138
- results.push({
139
- description: 'Edge start',
140
- type: MeasureResultType.POSITION,
141
- measureData: { value: edge.start.clone() },
142
- });
143
- results.push({
144
- description: 'Edge end',
145
- type: MeasureResultType.POSITION,
146
- measureData: { value: edge.end.clone() },
147
- });
148
- break;
149
- case types_1.GraphicType.ARC:
150
- case types_1.GraphicType.CURVEARC:
151
- const arc = element;
152
- const arcNEnd = arc.center.clone().addScaledVector(arc.normal.clone().normalize(), 40);
153
- const pointOnArc = getPointOnCircumference(arc.center, arc.normal, arc.radius);
154
- results.push({
155
- description: 'Arc start',
156
- type: MeasureResultType.POSITION,
157
- measureData: { value: arc.start.clone() },
158
- });
159
- results.push({
160
- description: 'Arc end',
161
- type: MeasureResultType.POSITION,
162
- measureData: { value: arc.end.clone() },
163
- });
164
- results.push({
165
- description: 'Arc center',
166
- type: MeasureResultType.POSITION,
167
- measureData: { value: arc.center.clone() },
168
- });
169
- results.push({
170
- description: 'Arc normal',
171
- type: MeasureResultType.VECTOR,
172
- measureData: { value: arc.normal.clone(), start: arc.center.clone(), end: arcNEnd },
173
- });
174
- results.push({
175
- description: 'Arc radius',
176
- type: MeasureResultType.DISTANCE,
177
- measureData: { value: arc.radius, start: arc.center.clone(), end: pointOnArc },
178
- });
179
- break;
180
- case types_1.GraphicType.CIRCLE:
181
- case types_1.GraphicType.CURVECIRCLE:
182
- const circle = element;
183
- const circleNEnd = circle.center.clone().addScaledVector(circle.normal.clone().normalize(), 40);
184
- const pointOnCircle = getPointOnCircumference(circle.center, circle.normal, circle.radius);
185
- results.push({
186
- description: 'Circle center',
187
- type: MeasureResultType.POSITION,
188
- measureData: { value: circle.center.clone() },
189
- });
190
- results.push({
191
- description: 'Circle normal',
192
- type: MeasureResultType.VECTOR,
193
- measureData: { value: circle.normal.clone(), start: circle.center.clone(), end: circleNEnd },
194
- });
195
- results.push({
196
- description: 'Circle radius',
197
- type: MeasureResultType.DISTANCE,
198
- measureData: { value: circle.radius, start: circle.center.clone(), end: pointOnCircle },
199
- });
200
- results.push({
201
- description: 'Circle start/end',
202
- type: MeasureResultType.POSITION,
203
- measureData: { value: circle.start.clone() },
204
- });
205
- break;
206
- case types_1.GraphicType.PLANE:
207
- const plane = element;
208
- const planeNEnd = plane.pointOnPlane.clone().addScaledVector(plane.normal.clone().normalize(), 40);
209
- results.push({
210
- description: 'Plane normal',
211
- type: MeasureResultType.VECTOR,
212
- measureData: { value: plane.normal, start: plane.pointOnPlane.clone(), end: planeNEnd },
213
- });
214
- break;
215
- case types_1.GraphicType.CYLINDER:
216
- const cylinder = element;
217
- const cylAxisNormalized = cylinder.axis.clone().normalize();
218
- const cylNEnd = cylinder.origin.clone().addScaledVector(cylAxisNormalized, cylinder.height + 40);
219
- const pointOnCyl = getPointOnCircumference(cylinder.origin, cylinder.axis, cylinder.radius);
220
- const cylHStart = cylinder.origin
221
- .clone()
222
- .addScaledVector(dir(cylinder.origin, pointOnCyl), cylinder.radius + 3);
223
- const cylHEnd = cylHStart.clone().addScaledVector(cylAxisNormalized, cylinder.height);
224
- results.push({
225
- description: 'Cylinder origin',
226
- type: MeasureResultType.POSITION,
227
- measureData: { value: cylinder.origin.clone() },
228
- });
229
- results.push({
230
- description: 'Cylinder axis',
231
- type: MeasureResultType.VECTOR,
232
- measureData: { value: cylinder.axis, start: cylinder.origin.clone(), end: cylNEnd },
233
- });
234
- results.push({
235
- description: 'Cylinder radius',
236
- type: MeasureResultType.DISTANCE,
237
- measureData: { value: cylinder.radius, start: cylinder.origin.clone(), end: pointOnCyl },
238
- });
239
- results.push({
240
- description: 'Cylinder height',
241
- type: MeasureResultType.DISTANCE,
242
- measureData: { value: cylinder.height, start: cylHStart, end: cylHEnd },
243
- });
244
- break;
245
- case types_1.GraphicType.CONE:
246
- const cone = element;
247
- const isExpanding = cone.radiusBottom < cone.radiusTop;
248
- const R = Math.max(cone.radiusBottom, cone.radiusTop);
249
- const r = Math.min(cone.radiusBottom, cone.radiusTop);
250
- const coneAxisNormalized = cone.axis.clone().normalize();
251
- const coneCenterTop = cone.origin.clone().addScaledVector(coneAxisNormalized, cone.height);
252
- const coneEnd = coneCenterTop.clone().addScaledVector(coneAxisNormalized, 40);
253
- const coneCenterMinR = isExpanding ? cone.origin.clone() : coneCenterTop.clone();
254
- const coneCenterMaxR = isExpanding ? coneCenterTop.clone() : cone.origin.clone();
255
- const pointOnConeBottom = getPointOnCircumference(cone.origin, cone.axis, cone.radiusBottom);
256
- const pointOnConeTop = getPointOnCircumference(coneCenterTop, cone.axis, cone.radiusTop);
257
- const pointOnConeMinR = isExpanding ? pointOnConeBottom : pointOnConeTop;
258
- const pointOnConeMaxR = isExpanding ? pointOnConeTop : pointOnConeBottom;
259
- const coneHStart = coneCenterMaxR.clone().addScaledVector(dir(coneCenterMaxR, pointOnConeMaxR), R + 3);
260
- const coneHEnd = coneHStart
261
- .clone()
262
- .addScaledVector(coneAxisNormalized, isExpanding ? -cone.height : cone.height);
263
- results.push({
264
- description: 'Cone origin',
265
- type: MeasureResultType.POSITION,
266
- measureData: { value: cone.origin.clone() },
267
- });
268
- results.push({
269
- description: 'Cone axis',
270
- type: MeasureResultType.VECTOR,
271
- measureData: { value: cone.axis, start: cone.origin.clone(), end: coneEnd },
272
- });
273
- results.push({
274
- description: 'Cone radius (min)',
275
- type: MeasureResultType.DISTANCE,
276
- measureData: { value: r, start: coneCenterMinR, end: pointOnConeMinR },
277
- });
278
- results.push({
279
- description: 'Cone radius (max)',
280
- type: MeasureResultType.DISTANCE,
281
- measureData: { value: R, start: coneCenterMaxR, end: pointOnConeMaxR },
282
- });
283
- results.push({
284
- description: 'Cone height',
285
- type: MeasureResultType.DISTANCE,
286
- measureData: { value: cone.height, start: coneHStart, end: coneHEnd },
287
- });
288
- break;
289
- case types_1.GraphicType.SPHERE:
290
- const sphere = element;
291
- results.push({
292
- description: 'Sphere radius',
293
- type: MeasureResultType.VALUE,
294
- measureData: { value: sphere.radius },
295
- });
296
- break;
297
- case types_1.GraphicType.NURBSSURFACE:
298
- results.push({ description: 'NURBS Surface', type: MeasureResultType.NONE });
299
- break;
300
- default:
301
- results.push({ description: 'Undefined', type: MeasureResultType.NONE });
302
- break;
303
- }
304
- }
305
- return results;
306
- },
307
- calculateMeasures(objects, drawingId) {
308
- const transformed = exports.Measure.transform(objects, drawingId);
309
- const first = transformed[0];
310
- const second = transformed[1];
311
- let results = [];
312
- switch (first.type) {
313
- case types_1.GraphicType.POINT:
314
- case types_1.GraphicType.CURVEPOINT:
315
- switch (second.type) {
316
- case types_1.GraphicType.POINT:
317
- case types_1.GraphicType.CURVEPOINT:
318
- results = exports.Measure.calculatePointPoint(first.position, second.position);
319
- break;
320
- case types_1.GraphicType.LINE:
321
- case types_1.GraphicType.CURVELINE:
322
- results = exports.Measure.calculatePointLine(first, second);
323
- break;
324
- case types_1.GraphicType.PLANE:
325
- results = exports.Measure.calculatePointPlane(first, second);
326
- break;
327
- case types_1.GraphicType.ARC:
328
- case types_1.GraphicType.CIRCLE:
329
- results = exports.Measure.calculatePointPoint(first.position.clone(), second.center.clone());
330
- break;
331
- default:
332
- results = exports.Measure.getInfo(objects, drawingId);
333
- break;
334
- }
335
- break;
336
- case types_1.GraphicType.LINE:
337
- case types_1.GraphicType.CURVELINE:
338
- switch (second.type) {
339
- case types_1.GraphicType.POINT:
340
- case types_1.GraphicType.CURVEPOINT:
341
- results = exports.Measure.calculatePointLine(second, first);
342
- break;
343
- case types_1.GraphicType.LINE:
344
- case types_1.GraphicType.CURVELINE:
345
- results = exports.Measure.calculateLineLine(first, second);
346
- break;
347
- case types_1.GraphicType.PLANE:
348
- results = exports.Measure.calculateLinePlane(first, second);
349
- break;
350
- default:
351
- results = exports.Measure.getInfo(objects, drawingId);
352
- break;
353
- }
354
- break;
355
- case types_1.GraphicType.CIRCLE:
356
- case types_1.GraphicType.ARC:
357
- switch (second.type) {
358
- case types_1.GraphicType.ARC:
359
- case types_1.GraphicType.CIRCLE:
360
- results = exports.Measure.calculatePointPoint(first.center, second.center);
361
- break;
362
- case types_1.GraphicType.POINT:
363
- results = exports.Measure.calculatePointPoint(first.center, second.position);
364
- break;
365
- default:
366
- results = exports.Measure.getInfo(objects, drawingId);
367
- break;
368
- }
369
- break;
370
- case types_1.GraphicType.PLANE:
371
- switch (second.type) {
372
- case types_1.GraphicType.POINT:
373
- case types_1.GraphicType.CURVEPOINT:
374
- results = exports.Measure.calculatePointPlane(second, first);
375
- break;
376
- case types_1.GraphicType.LINE:
377
- case types_1.GraphicType.CURVELINE:
378
- results = exports.Measure.calculateLinePlane(second, first);
379
- break;
380
- case types_1.GraphicType.ARC:
381
- case types_1.GraphicType.CURVEARC:
382
- results = exports.Measure.calculateArcPlane(second, first);
383
- break;
384
- case types_1.GraphicType.PLANE:
385
- results = exports.Measure.calculatePlanePlane(first, second);
386
- break;
387
- default:
388
- results = exports.Measure.getInfo(objects, drawingId);
389
- break;
390
- }
391
- break;
392
- default:
393
- results = exports.Measure.getInfo(objects, drawingId);
394
- break;
395
- }
396
- return results;
397
- },
398
- calculatePointPoint(point1, point2) {
399
- const p1 = point1.clone();
400
- const p2 = point2.clone();
401
- const distance = p1.distanceTo(p2);
402
- const dx = Math.abs(p1.x - p2.x);
403
- const dy = Math.abs(p1.y - p2.y);
404
- const dz = Math.abs(p1.z - p2.z);
405
- const px = p1.clone().setX(p2.x);
406
- const pxy = px.clone().setY(p2.y);
407
- return [
408
- {
409
- description: 'Distance',
410
- type: MeasureResultType.DISTANCE,
411
- measureData: { value: distance, start: p1, end: p2 },
412
- },
413
- { description: 'dx', type: MeasureResultType.DISTANCE, measureData: { value: dx, start: p1, end: px } },
414
- { description: 'dy', type: MeasureResultType.DISTANCE, measureData: { value: dy, start: px, end: pxy } },
415
- { description: 'dz', type: MeasureResultType.DISTANCE, measureData: { value: dz, start: pxy, end: p2 } },
416
- ];
417
- },
418
- calculatePointLine(point, line) {
419
- const [start, end] = exports.Measure.getPointLineMPoints(point.position, line.start, line.end);
420
- const distance = start.distanceTo(end);
421
- return [
422
- {
423
- description: 'Distance',
424
- type: MeasureResultType.DISTANCE,
425
- measureData: { value: distance, start, end },
426
- },
427
- ];
428
- },
429
- calculatePointPlane(point, plane) {
430
- const [start, end] = exports.Measure.getPointPlaneMPoints(point.position, plane.pointOnPlane, plane.normal);
431
- const distance = start.distanceTo(end);
432
- return [
433
- {
434
- description: 'Distance',
435
- type: MeasureResultType.DISTANCE,
436
- measureData: { value: distance, start, end },
437
- },
438
- ];
439
- },
440
- calculateLineLine(first, second) {
441
- const [start, end] = exports.Measure.getLineLineMPoints(first.start, first.end, second.start, second.end);
442
- const distance = start && end ? start.distanceTo(end) : NaN;
443
- const [dir1, dir2] = exports.Measure.getLineLineMDirs(first.start, first.end, second.start, second.end);
444
- const angle = exports.Measure.degrees(dir1.angleTo(dir2));
445
- const angleS = 180 - angle;
446
- return [
447
- {
448
- description: 'Distance',
449
- type: MeasureResultType.DISTANCE,
450
- measureData: start && end ? { value: distance, start, end } : undefined,
451
- },
452
- {
453
- description: 'Angle1',
454
- type: MeasureResultType.ANGLE,
455
- measureData: { value: angle, center: first.start, dir1, dir2 },
456
- },
457
- {
458
- description: 'Angle2',
459
- type: MeasureResultType.ANGLE,
460
- measureData: { value: angleS, center: first.start, dir1, dir2: dir2.clone().negate() },
461
- },
462
- ];
463
- },
464
- calculateLinePlane(line, plane) {
465
- const [start, end] = exports.Measure.getLinePlaneMPoints(line.start, line.end, plane.pointOnPlane, plane.normal);
466
- const distance = start && end ? start.distanceTo(end) : NaN;
467
- return [
468
- {
469
- description: 'Distance',
470
- type: MeasureResultType.DISTANCE,
471
- measureData: start && end ? { value: distance, start, end } : undefined,
472
- },
473
- ];
474
- },
475
- calculateArcPlane(arc, plane) {
476
- const [start, end] = exports.Measure.getArcPlaneMPoints(arc.center, arc.normal, plane.pointOnPlane, plane.normal);
477
- const distance = start && end ? start.distanceTo(end) : NaN;
478
- return [
479
- {
480
- description: 'Distance',
481
- type: MeasureResultType.DISTANCE,
482
- measureData: start && end ? { value: distance, start, end } : undefined,
483
- },
484
- ];
485
- },
486
- calculatePlanePlane(plane1, plane2) {
487
- const [start, end] = exports.Measure.getPlanePlaneMPoints(plane1.pointOnPlane, plane1.normal, plane2.pointOnPlane, plane2.normal);
488
- const distance = start && end ? start.distanceTo(end) : NaN;
489
- const [dir1, dir2] = exports.Measure.getPlanePlaneMDirs(plane1.normal, plane2.normal);
490
- const angle = dir1 && dir2 ? exports.Measure.degrees(dir1.angleTo(dir2)) : exports.Measure.degrees(plane1.normal.angleTo(plane2.normal));
491
- return [
492
- {
493
- description: 'Distance',
494
- type: MeasureResultType.DISTANCE,
495
- measureData: start && end ? { value: distance, start, end } : undefined,
496
- },
497
- {
498
- description: 'Angle',
499
- type: MeasureResultType.ANGLE,
500
- measureData: dir1 && dir2 ? { value: angle, center: plane1.pointOnPlane.clone(), dir1, dir2 } : undefined,
501
- },
502
- ];
503
- },
504
- degrees(radians) {
505
- return (radians / Math.PI) * 180;
506
- },
507
- areParallel(vec1, vec2) {
508
- const val = Math.abs(vec1.clone().cross(vec2).length());
509
- return val < tolerance;
510
- },
511
- arePerpendicular(vec1, vec2) {
512
- const val = Math.abs(vec1.clone().normalize().dot(vec2.clone().normalize()));
513
- return val < tolerance;
514
- },
515
- getPointLineMPoints(pointsPos, startPos, endPos) {
516
- const p1 = pointsPos.clone();
517
- const lineDir = endPos.clone().sub(startPos);
518
- const p2 = pointsPos.clone().sub(startPos).projectOnVector(lineDir).add(startPos);
519
- return [p1, p2];
520
- },
521
- getPointPlaneMPoints(pointPos, pointOnPlane, normal) {
522
- const p1 = pointPos.clone();
523
- const offsetV = pointPos.clone().sub(pointOnPlane).projectOnVector(normal);
524
- const p2 = pointPos.clone().sub(offsetV);
525
- return [p1, p2];
526
- },
527
- getLineLineMPoints(start1Pos, end1Pos, start2Pos, end2Pos) {
528
- const vec1 = start1Pos.clone().sub(end1Pos);
529
- const vec2 = start2Pos.clone().sub(end2Pos);
530
- if (exports.Measure.areParallel(vec1, vec2)) {
531
- // lines are parallel
532
- const vecAB = start1Pos.clone().sub(start2Pos);
533
- if (!exports.Measure.areParallel(vecAB, vec1)) {
534
- // lines are not conincident
535
- return exports.Measure.getPointLineMPoints(start1Pos, start2Pos, end2Pos);
536
- }
537
- }
538
- return [undefined, undefined];
539
- },
540
- getLinePlaneMPoints(startPos, endPos, pointOnPlane, normal) {
541
- const vec = startPos.clone().sub(endPos);
542
- if (exports.Measure.arePerpendicular(vec, normal)) {
543
- // line is perpendicular to plane normal
544
- return exports.Measure.getPointPlaneMPoints(startPos, pointOnPlane, normal);
545
- }
546
- return [undefined, undefined];
547
- },
548
- getArcPlaneMPoints(arcCenter, arcNormal, pointOnPlane, planeNormal) {
549
- if (exports.Measure.areParallel(arcNormal, planeNormal)) {
550
- // parallel
551
- return exports.Measure.getPointPlaneMPoints(arcCenter, pointOnPlane, planeNormal);
552
- }
553
- return [undefined, undefined];
554
- },
555
- getPlanePlaneMPoints(pointOnPlane1, normal1, pointOnPlane2, normal2) {
556
- if (exports.Measure.areParallel(normal1, normal2)) {
557
- // parallel
558
- return exports.Measure.getPointPlaneMPoints(pointOnPlane1, pointOnPlane2, normal2);
559
- }
560
- return [undefined, undefined];
561
- },
562
- getLineLineMDirs(start1Pos, end1Pos, start2Pos, end2Pos) {
563
- const vec1 = end1Pos.clone().sub(start1Pos);
564
- const vec2 = end2Pos.clone().sub(start2Pos);
565
- return [vec1, vec2];
566
- },
567
- getPlanePlaneMDirs(normal1, normal2) {
568
- if (!exports.Measure.areParallel(normal1, normal2)) {
569
- const tangent1 = normal1.clone().projectOnPlane(normal2).normalize();
570
- const tangent2 = normal2.clone().projectOnPlane(normal1).normalize();
571
- const angle = tangent1.angleTo(tangent2);
572
- return angle <= Math.PI / 2 ? [tangent1, tangent2] : [tangent1, tangent2.negate()];
573
- }
574
- return [undefined, undefined];
575
- },
576
- };
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Measure = exports.MeasureResultType = void 0;
27
+ /* eslint-disable max-lines */
28
+ const THREE = __importStar(require("three"));
29
+ const store_1 = require("./../store");
30
+ const types_1 = require("./../types");
31
+ var MeasureResultType;
32
+ (function (MeasureResultType) {
33
+ MeasureResultType["NONE"] = "none";
34
+ MeasureResultType["VALUE"] = "value";
35
+ MeasureResultType["DISTANCE"] = "linear";
36
+ MeasureResultType["ANGLE"] = "angular";
37
+ MeasureResultType["VECTOR"] = "vector";
38
+ MeasureResultType["POSITION"] = "position";
39
+ })(MeasureResultType = exports.MeasureResultType || (exports.MeasureResultType = {}));
40
+ const tolerance = 1e-3;
41
+ exports.Measure = {
42
+ transform(items, drawingId) {
43
+ const drawing = (0, store_1.getDrawing)(drawingId);
44
+ const transformed = [];
45
+ for (const item of items) {
46
+ const matrix = drawing.api.structure.calculateGlobalTransformation(item.productId);
47
+ const matrix3 = new THREE.Matrix3().setFromMatrix4(matrix);
48
+ const newItem = Object.assign({}, item);
49
+ switch (newItem.type) {
50
+ case types_1.GraphicType.POINT:
51
+ case types_1.GraphicType.CURVEPOINT:
52
+ const point = newItem;
53
+ point.position = point.position.clone().applyMatrix4(matrix);
54
+ break;
55
+ case types_1.GraphicType.LINE:
56
+ case types_1.GraphicType.CURVELINE:
57
+ const line = newItem;
58
+ line.start = line.start.clone().applyMatrix4(matrix);
59
+ line.end = line.end.clone().applyMatrix4(matrix);
60
+ break;
61
+ case types_1.GraphicType.PLANE:
62
+ const plane = newItem;
63
+ plane.normal = plane.normal.clone().applyMatrix3(matrix3);
64
+ plane.normal.normalize();
65
+ plane.pointOnPlane = plane.pointOnPlane.clone().applyMatrix4(matrix);
66
+ break;
67
+ case types_1.GraphicType.CYLINDER:
68
+ const cylinder = newItem;
69
+ cylinder.axis = cylinder.axis.clone().applyMatrix3(matrix3);
70
+ cylinder.axis.normalize();
71
+ cylinder.origin = cylinder.origin.clone().applyMatrix4(matrix);
72
+ break;
73
+ case types_1.GraphicType.CONE:
74
+ const cone = newItem;
75
+ cone.axis = cone.axis.clone().applyMatrix3(matrix3);
76
+ cone.axis.normalize();
77
+ cone.origin = cone.origin.clone().applyMatrix4(matrix);
78
+ break;
79
+ case types_1.GraphicType.ARC:
80
+ case types_1.GraphicType.CURVEARC:
81
+ const arc = newItem;
82
+ arc.normal = arc.normal.clone().applyMatrix3(matrix3);
83
+ arc.normal.normalize();
84
+ arc.center = arc.center.clone().applyMatrix4(matrix);
85
+ arc.start = arc.start.clone().applyMatrix4(matrix);
86
+ arc.end = arc.end.clone().applyMatrix4(matrix);
87
+ break;
88
+ case types_1.GraphicType.CIRCLE:
89
+ case types_1.GraphicType.CURVECIRCLE:
90
+ const circle = newItem;
91
+ circle.normal = circle.normal.clone().applyMatrix3(matrix3);
92
+ circle.normal.normalize();
93
+ circle.center = circle.center.clone().applyMatrix4(matrix);
94
+ circle.start = circle.start.clone().applyMatrix4(matrix);
95
+ circle.end = circle.end.clone().applyMatrix4(matrix);
96
+ break;
97
+ default:
98
+ break;
99
+ }
100
+ transformed.push(newItem);
101
+ }
102
+ return transformed;
103
+ },
104
+ getInfo(objects, drawingId) {
105
+ const transformed = exports.Measure.transform(objects, drawingId);
106
+ const results = [];
107
+ const dir = (start, end) => end.clone().sub(start).normalize();
108
+ const getPointOnCircumference = (center, axis, radius) => {
109
+ const axisNormalized = axis.clone().normalize();
110
+ const helperVec = axisNormalized.x !== 1 ? new THREE.Vector3(1, 0, 0) : new THREE.Vector3(0, 1, 0);
111
+ const tangent = axisNormalized.clone().cross(helperVec).normalize();
112
+ return center.clone().addScaledVector(tangent, radius);
113
+ };
114
+ for (const element of transformed) {
115
+ switch (element.type) {
116
+ case types_1.GraphicType.POINT:
117
+ case types_1.GraphicType.CURVEPOINT:
118
+ const point = element;
119
+ results.push({
120
+ description: 'Position',
121
+ type: MeasureResultType.POSITION,
122
+ measureData: { value: point.position.clone() },
123
+ });
124
+ break;
125
+ case types_1.GraphicType.LINE:
126
+ case types_1.GraphicType.CURVELINE:
127
+ const line = element;
128
+ const absoluteDistance = line.start.distanceTo(line.end);
129
+ results.push({
130
+ description: 'Line length',
131
+ type: MeasureResultType.DISTANCE,
132
+ measureData: { value: absoluteDistance, start: line.start.clone(), end: line.end.clone() },
133
+ });
134
+ break;
135
+ case types_1.GraphicType.NURBSCURVE:
136
+ case types_1.GraphicType.CURVESPLINE:
137
+ const edge = element;
138
+ results.push({
139
+ description: 'Edge start',
140
+ type: MeasureResultType.POSITION,
141
+ measureData: { value: edge.start.clone() },
142
+ });
143
+ results.push({
144
+ description: 'Edge end',
145
+ type: MeasureResultType.POSITION,
146
+ measureData: { value: edge.end.clone() },
147
+ });
148
+ break;
149
+ case types_1.GraphicType.ARC:
150
+ case types_1.GraphicType.CURVEARC:
151
+ const arc = element;
152
+ const arcNEnd = arc.center.clone().addScaledVector(arc.normal.clone().normalize(), 40);
153
+ const pointOnArc = getPointOnCircumference(arc.center, arc.normal, arc.radius);
154
+ results.push({
155
+ description: 'Arc start',
156
+ type: MeasureResultType.POSITION,
157
+ measureData: { value: arc.start.clone() },
158
+ });
159
+ results.push({
160
+ description: 'Arc end',
161
+ type: MeasureResultType.POSITION,
162
+ measureData: { value: arc.end.clone() },
163
+ });
164
+ results.push({
165
+ description: 'Arc center',
166
+ type: MeasureResultType.POSITION,
167
+ measureData: { value: arc.center.clone() },
168
+ });
169
+ results.push({
170
+ description: 'Arc normal',
171
+ type: MeasureResultType.VECTOR,
172
+ measureData: { value: arc.normal.clone(), start: arc.center.clone(), end: arcNEnd },
173
+ });
174
+ results.push({
175
+ description: 'Arc radius',
176
+ type: MeasureResultType.DISTANCE,
177
+ measureData: { value: arc.radius, start: arc.center.clone(), end: pointOnArc },
178
+ });
179
+ break;
180
+ case types_1.GraphicType.CIRCLE:
181
+ case types_1.GraphicType.CURVECIRCLE:
182
+ const circle = element;
183
+ const circleNEnd = circle.center.clone().addScaledVector(circle.normal.clone().normalize(), 40);
184
+ const pointOnCircle = getPointOnCircumference(circle.center, circle.normal, circle.radius);
185
+ results.push({
186
+ description: 'Circle center',
187
+ type: MeasureResultType.POSITION,
188
+ measureData: { value: circle.center.clone() },
189
+ });
190
+ results.push({
191
+ description: 'Circle normal',
192
+ type: MeasureResultType.VECTOR,
193
+ measureData: { value: circle.normal.clone(), start: circle.center.clone(), end: circleNEnd },
194
+ });
195
+ results.push({
196
+ description: 'Circle radius',
197
+ type: MeasureResultType.DISTANCE,
198
+ measureData: { value: circle.radius, start: circle.center.clone(), end: pointOnCircle },
199
+ });
200
+ results.push({
201
+ description: 'Circle start/end',
202
+ type: MeasureResultType.POSITION,
203
+ measureData: { value: circle.start.clone() },
204
+ });
205
+ break;
206
+ case types_1.GraphicType.PLANE:
207
+ const plane = element;
208
+ const planeNEnd = plane.pointOnPlane.clone().addScaledVector(plane.normal.clone().normalize(), 40);
209
+ results.push({
210
+ description: 'Plane normal',
211
+ type: MeasureResultType.VECTOR,
212
+ measureData: { value: plane.normal, start: plane.pointOnPlane.clone(), end: planeNEnd },
213
+ });
214
+ break;
215
+ case types_1.GraphicType.CYLINDER:
216
+ const cylinder = element;
217
+ const cylAxisNormalized = cylinder.axis.clone().normalize();
218
+ const cylNEnd = cylinder.origin.clone().addScaledVector(cylAxisNormalized, cylinder.height + 40);
219
+ const pointOnCyl = getPointOnCircumference(cylinder.origin, cylinder.axis, cylinder.radius);
220
+ const cylHStart = cylinder.origin
221
+ .clone()
222
+ .addScaledVector(dir(cylinder.origin, pointOnCyl), cylinder.radius + 3);
223
+ const cylHEnd = cylHStart.clone().addScaledVector(cylAxisNormalized, cylinder.height);
224
+ results.push({
225
+ description: 'Cylinder origin',
226
+ type: MeasureResultType.POSITION,
227
+ measureData: { value: cylinder.origin.clone() },
228
+ });
229
+ results.push({
230
+ description: 'Cylinder axis',
231
+ type: MeasureResultType.VECTOR,
232
+ measureData: { value: cylinder.axis, start: cylinder.origin.clone(), end: cylNEnd },
233
+ });
234
+ results.push({
235
+ description: 'Cylinder radius',
236
+ type: MeasureResultType.DISTANCE,
237
+ measureData: { value: cylinder.radius, start: cylinder.origin.clone(), end: pointOnCyl },
238
+ });
239
+ results.push({
240
+ description: 'Cylinder height',
241
+ type: MeasureResultType.DISTANCE,
242
+ measureData: { value: cylinder.height, start: cylHStart, end: cylHEnd },
243
+ });
244
+ break;
245
+ case types_1.GraphicType.CONE:
246
+ const cone = element;
247
+ const isExpanding = cone.radiusBottom < cone.radiusTop;
248
+ const R = Math.max(cone.radiusBottom, cone.radiusTop);
249
+ const r = Math.min(cone.radiusBottom, cone.radiusTop);
250
+ const coneAxisNormalized = cone.axis.clone().normalize();
251
+ const coneCenterTop = cone.origin.clone().addScaledVector(coneAxisNormalized, cone.height);
252
+ const coneEnd = coneCenterTop.clone().addScaledVector(coneAxisNormalized, 40);
253
+ const coneCenterMinR = isExpanding ? cone.origin.clone() : coneCenterTop.clone();
254
+ const coneCenterMaxR = isExpanding ? coneCenterTop.clone() : cone.origin.clone();
255
+ const pointOnConeBottom = getPointOnCircumference(cone.origin, cone.axis, cone.radiusBottom);
256
+ const pointOnConeTop = getPointOnCircumference(coneCenterTop, cone.axis, cone.radiusTop);
257
+ const pointOnConeMinR = isExpanding ? pointOnConeBottom : pointOnConeTop;
258
+ const pointOnConeMaxR = isExpanding ? pointOnConeTop : pointOnConeBottom;
259
+ const coneHStart = coneCenterMaxR.clone().addScaledVector(dir(coneCenterMaxR, pointOnConeMaxR), R + 3);
260
+ const coneHEnd = coneHStart
261
+ .clone()
262
+ .addScaledVector(coneAxisNormalized, isExpanding ? -cone.height : cone.height);
263
+ results.push({
264
+ description: 'Cone origin',
265
+ type: MeasureResultType.POSITION,
266
+ measureData: { value: cone.origin.clone() },
267
+ });
268
+ results.push({
269
+ description: 'Cone axis',
270
+ type: MeasureResultType.VECTOR,
271
+ measureData: { value: cone.axis, start: cone.origin.clone(), end: coneEnd },
272
+ });
273
+ results.push({
274
+ description: 'Cone radius (min)',
275
+ type: MeasureResultType.DISTANCE,
276
+ measureData: { value: r, start: coneCenterMinR, end: pointOnConeMinR },
277
+ });
278
+ results.push({
279
+ description: 'Cone radius (max)',
280
+ type: MeasureResultType.DISTANCE,
281
+ measureData: { value: R, start: coneCenterMaxR, end: pointOnConeMaxR },
282
+ });
283
+ results.push({
284
+ description: 'Cone height',
285
+ type: MeasureResultType.DISTANCE,
286
+ measureData: { value: cone.height, start: coneHStart, end: coneHEnd },
287
+ });
288
+ break;
289
+ case types_1.GraphicType.SPHERE:
290
+ const sphere = element;
291
+ results.push({
292
+ description: 'Sphere radius',
293
+ type: MeasureResultType.VALUE,
294
+ measureData: { value: sphere.radius },
295
+ });
296
+ break;
297
+ case types_1.GraphicType.NURBSSURFACE:
298
+ results.push({ description: 'NURBS Surface', type: MeasureResultType.NONE });
299
+ break;
300
+ default:
301
+ results.push({ description: 'Undefined', type: MeasureResultType.NONE });
302
+ break;
303
+ }
304
+ }
305
+ return results;
306
+ },
307
+ calculateMeasures(objects, drawingId) {
308
+ const transformed = exports.Measure.transform(objects, drawingId);
309
+ const first = transformed[0];
310
+ const second = transformed[1];
311
+ let results = [];
312
+ switch (first.type) {
313
+ case types_1.GraphicType.POINT:
314
+ case types_1.GraphicType.CURVEPOINT:
315
+ switch (second.type) {
316
+ case types_1.GraphicType.POINT:
317
+ case types_1.GraphicType.CURVEPOINT:
318
+ results = exports.Measure.calculatePointPoint(first.position, second.position);
319
+ break;
320
+ case types_1.GraphicType.LINE:
321
+ case types_1.GraphicType.CURVELINE:
322
+ results = exports.Measure.calculatePointLine(first, second);
323
+ break;
324
+ case types_1.GraphicType.PLANE:
325
+ results = exports.Measure.calculatePointPlane(first, second);
326
+ break;
327
+ case types_1.GraphicType.ARC:
328
+ case types_1.GraphicType.CIRCLE:
329
+ results = exports.Measure.calculatePointPoint(first.position.clone(), second.center.clone());
330
+ break;
331
+ default:
332
+ results = exports.Measure.getInfo(objects, drawingId);
333
+ break;
334
+ }
335
+ break;
336
+ case types_1.GraphicType.LINE:
337
+ case types_1.GraphicType.CURVELINE:
338
+ switch (second.type) {
339
+ case types_1.GraphicType.POINT:
340
+ case types_1.GraphicType.CURVEPOINT:
341
+ results = exports.Measure.calculatePointLine(second, first);
342
+ break;
343
+ case types_1.GraphicType.LINE:
344
+ case types_1.GraphicType.CURVELINE:
345
+ results = exports.Measure.calculateLineLine(first, second);
346
+ break;
347
+ case types_1.GraphicType.PLANE:
348
+ results = exports.Measure.calculateLinePlane(first, second);
349
+ break;
350
+ default:
351
+ results = exports.Measure.getInfo(objects, drawingId);
352
+ break;
353
+ }
354
+ break;
355
+ case types_1.GraphicType.CIRCLE:
356
+ case types_1.GraphicType.ARC:
357
+ switch (second.type) {
358
+ case types_1.GraphicType.ARC:
359
+ case types_1.GraphicType.CIRCLE:
360
+ results = exports.Measure.calculatePointPoint(first.center, second.center);
361
+ break;
362
+ case types_1.GraphicType.POINT:
363
+ results = exports.Measure.calculatePointPoint(first.center, second.position);
364
+ break;
365
+ default:
366
+ results = exports.Measure.getInfo(objects, drawingId);
367
+ break;
368
+ }
369
+ break;
370
+ case types_1.GraphicType.PLANE:
371
+ switch (second.type) {
372
+ case types_1.GraphicType.POINT:
373
+ case types_1.GraphicType.CURVEPOINT:
374
+ results = exports.Measure.calculatePointPlane(second, first);
375
+ break;
376
+ case types_1.GraphicType.LINE:
377
+ case types_1.GraphicType.CURVELINE:
378
+ results = exports.Measure.calculateLinePlane(second, first);
379
+ break;
380
+ case types_1.GraphicType.ARC:
381
+ case types_1.GraphicType.CURVEARC:
382
+ results = exports.Measure.calculateArcPlane(second, first);
383
+ break;
384
+ case types_1.GraphicType.PLANE:
385
+ results = exports.Measure.calculatePlanePlane(first, second);
386
+ break;
387
+ default:
388
+ results = exports.Measure.getInfo(objects, drawingId);
389
+ break;
390
+ }
391
+ break;
392
+ default:
393
+ results = exports.Measure.getInfo(objects, drawingId);
394
+ break;
395
+ }
396
+ return results;
397
+ },
398
+ calculatePointPoint(point1, point2) {
399
+ const p1 = point1.clone();
400
+ const p2 = point2.clone();
401
+ const distance = p1.distanceTo(p2);
402
+ const dx = Math.abs(p1.x - p2.x);
403
+ const dy = Math.abs(p1.y - p2.y);
404
+ const dz = Math.abs(p1.z - p2.z);
405
+ const px = p1.clone().setX(p2.x);
406
+ const pxy = px.clone().setY(p2.y);
407
+ return [
408
+ {
409
+ description: 'Distance',
410
+ type: MeasureResultType.DISTANCE,
411
+ measureData: { value: distance, start: p1, end: p2 },
412
+ },
413
+ { description: 'dx', type: MeasureResultType.DISTANCE, measureData: { value: dx, start: p1, end: px } },
414
+ { description: 'dy', type: MeasureResultType.DISTANCE, measureData: { value: dy, start: px, end: pxy } },
415
+ { description: 'dz', type: MeasureResultType.DISTANCE, measureData: { value: dz, start: pxy, end: p2 } },
416
+ ];
417
+ },
418
+ calculatePointLine(point, line) {
419
+ const [start, end] = exports.Measure.getPointLineMPoints(point.position, line.start, line.end);
420
+ const distance = start.distanceTo(end);
421
+ return [
422
+ {
423
+ description: 'Distance',
424
+ type: MeasureResultType.DISTANCE,
425
+ measureData: { value: distance, start, end },
426
+ },
427
+ ];
428
+ },
429
+ calculatePointPlane(point, plane) {
430
+ const [start, end] = exports.Measure.getPointPlaneMPoints(point.position, plane.pointOnPlane, plane.normal);
431
+ const distance = start.distanceTo(end);
432
+ return [
433
+ {
434
+ description: 'Distance',
435
+ type: MeasureResultType.DISTANCE,
436
+ measureData: { value: distance, start, end },
437
+ },
438
+ ];
439
+ },
440
+ calculateLineLine(first, second) {
441
+ const [start, end] = exports.Measure.getLineLineMPoints(first.start, first.end, second.start, second.end);
442
+ const distance = start && end ? start.distanceTo(end) : NaN;
443
+ const [dir1, dir2] = exports.Measure.getLineLineMDirs(first.start, first.end, second.start, second.end);
444
+ const angle = exports.Measure.degrees(dir1.angleTo(dir2));
445
+ const angleS = 180 - angle;
446
+ return [
447
+ {
448
+ description: 'Distance',
449
+ type: MeasureResultType.DISTANCE,
450
+ measureData: start && end ? { value: distance, start, end } : undefined,
451
+ },
452
+ {
453
+ description: 'Angle1',
454
+ type: MeasureResultType.ANGLE,
455
+ measureData: { value: angle, center: first.start, dir1, dir2 },
456
+ },
457
+ {
458
+ description: 'Angle2',
459
+ type: MeasureResultType.ANGLE,
460
+ measureData: { value: angleS, center: first.start, dir1, dir2: dir2.clone().negate() },
461
+ },
462
+ ];
463
+ },
464
+ calculateLinePlane(line, plane) {
465
+ const [start, end] = exports.Measure.getLinePlaneMPoints(line.start, line.end, plane.pointOnPlane, plane.normal);
466
+ const distance = start && end ? start.distanceTo(end) : NaN;
467
+ return [
468
+ {
469
+ description: 'Distance',
470
+ type: MeasureResultType.DISTANCE,
471
+ measureData: start && end ? { value: distance, start, end } : undefined,
472
+ },
473
+ ];
474
+ },
475
+ calculateArcPlane(arc, plane) {
476
+ const [start, end] = exports.Measure.getArcPlaneMPoints(arc.center, arc.normal, plane.pointOnPlane, plane.normal);
477
+ const distance = start && end ? start.distanceTo(end) : NaN;
478
+ return [
479
+ {
480
+ description: 'Distance',
481
+ type: MeasureResultType.DISTANCE,
482
+ measureData: start && end ? { value: distance, start, end } : undefined,
483
+ },
484
+ ];
485
+ },
486
+ calculatePlanePlane(plane1, plane2) {
487
+ const [start, end] = exports.Measure.getPlanePlaneMPoints(plane1.pointOnPlane, plane1.normal, plane2.pointOnPlane, plane2.normal);
488
+ const distance = start && end ? start.distanceTo(end) : NaN;
489
+ const [dir1, dir2] = exports.Measure.getPlanePlaneMDirs(plane1.normal, plane2.normal);
490
+ const angle = dir1 && dir2 ? exports.Measure.degrees(dir1.angleTo(dir2)) : exports.Measure.degrees(plane1.normal.angleTo(plane2.normal));
491
+ return [
492
+ {
493
+ description: 'Distance',
494
+ type: MeasureResultType.DISTANCE,
495
+ measureData: start && end ? { value: distance, start, end } : undefined,
496
+ },
497
+ {
498
+ description: 'Angle',
499
+ type: MeasureResultType.ANGLE,
500
+ measureData: dir1 && dir2 ? { value: angle, center: plane1.pointOnPlane.clone(), dir1, dir2 } : undefined,
501
+ },
502
+ ];
503
+ },
504
+ degrees(radians) {
505
+ return (radians / Math.PI) * 180;
506
+ },
507
+ areParallel(vec1, vec2) {
508
+ const val = Math.abs(vec1.clone().cross(vec2).length());
509
+ return val < tolerance;
510
+ },
511
+ arePerpendicular(vec1, vec2) {
512
+ const val = Math.abs(vec1.clone().normalize().dot(vec2.clone().normalize()));
513
+ return val < tolerance;
514
+ },
515
+ getPointLineMPoints(pointsPos, startPos, endPos) {
516
+ const p1 = pointsPos.clone();
517
+ const lineDir = endPos.clone().sub(startPos);
518
+ const p2 = pointsPos.clone().sub(startPos).projectOnVector(lineDir).add(startPos);
519
+ return [p1, p2];
520
+ },
521
+ getPointPlaneMPoints(pointPos, pointOnPlane, normal) {
522
+ const p1 = pointPos.clone();
523
+ const offsetV = pointPos.clone().sub(pointOnPlane).projectOnVector(normal);
524
+ const p2 = pointPos.clone().sub(offsetV);
525
+ return [p1, p2];
526
+ },
527
+ getLineLineMPoints(start1Pos, end1Pos, start2Pos, end2Pos) {
528
+ const vec1 = start1Pos.clone().sub(end1Pos);
529
+ const vec2 = start2Pos.clone().sub(end2Pos);
530
+ if (exports.Measure.areParallel(vec1, vec2)) {
531
+ // lines are parallel
532
+ const vecAB = start1Pos.clone().sub(start2Pos);
533
+ if (!exports.Measure.areParallel(vecAB, vec1)) {
534
+ // lines are not conincident
535
+ return exports.Measure.getPointLineMPoints(start1Pos, start2Pos, end2Pos);
536
+ }
537
+ }
538
+ return [undefined, undefined];
539
+ },
540
+ getLinePlaneMPoints(startPos, endPos, pointOnPlane, normal) {
541
+ const vec = startPos.clone().sub(endPos);
542
+ if (exports.Measure.arePerpendicular(vec, normal)) {
543
+ // line is perpendicular to plane normal
544
+ return exports.Measure.getPointPlaneMPoints(startPos, pointOnPlane, normal);
545
+ }
546
+ return [undefined, undefined];
547
+ },
548
+ getArcPlaneMPoints(arcCenter, arcNormal, pointOnPlane, planeNormal) {
549
+ if (exports.Measure.areParallel(arcNormal, planeNormal)) {
550
+ // parallel
551
+ return exports.Measure.getPointPlaneMPoints(arcCenter, pointOnPlane, planeNormal);
552
+ }
553
+ return [undefined, undefined];
554
+ },
555
+ getPlanePlaneMPoints(pointOnPlane1, normal1, pointOnPlane2, normal2) {
556
+ if (exports.Measure.areParallel(normal1, normal2)) {
557
+ // parallel
558
+ return exports.Measure.getPointPlaneMPoints(pointOnPlane1, pointOnPlane2, normal2);
559
+ }
560
+ return [undefined, undefined];
561
+ },
562
+ getLineLineMDirs(start1Pos, end1Pos, start2Pos, end2Pos) {
563
+ const vec1 = end1Pos.clone().sub(start1Pos);
564
+ const vec2 = end2Pos.clone().sub(start2Pos);
565
+ return [vec1, vec2];
566
+ },
567
+ getPlanePlaneMDirs(normal1, normal2) {
568
+ if (!exports.Measure.areParallel(normal1, normal2)) {
569
+ const tangent1 = normal1.clone().projectOnPlane(normal2).normalize();
570
+ const tangent2 = normal2.clone().projectOnPlane(normal1).normalize();
571
+ const angle = tangent1.angleTo(tangent2);
572
+ return angle <= Math.PI / 2 ? [tangent1, tangent2] : [tangent1, tangent2.negate()];
573
+ }
574
+ return [undefined, undefined];
575
+ },
576
+ };