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