@buerli.io/core 0.4.0-beta.3 → 0.4.0-beta.5
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/store/states/geometry.d.ts +9 -1
- package/build/store/states/geometry.js +3 -3
- package/build/types/index.d.ts +0 -1
- package/build/types/index.js +0 -1
- package/build/utils/Math.d.ts +15 -0
- package/build/utils/Math.js +40 -0
- package/build/utils/Measure.d.ts +20 -95
- package/build/utils/Measure.js +81 -94
- package/package.json +1 -1
- package/build/types/ErrorTypes.d.ts +0 -5
- package/build/types/ErrorTypes.js +0 -1
|
@@ -26,7 +26,15 @@ export declare type GeometryConfig = {
|
|
|
26
26
|
points?: ElementConfig;
|
|
27
27
|
};
|
|
28
28
|
export declare type GeometryData = {
|
|
29
|
-
cache: Record<GraphicID, ContainerGeometryT
|
|
29
|
+
cache: Record<GraphicID, ContainerGeometryT & {
|
|
30
|
+
/**
|
|
31
|
+
* The dirty stamp will be updated, as soon as a client side modification of the geometry will happen!
|
|
32
|
+
* Examples: 'setColor' or 'setOpacity'
|
|
33
|
+
*
|
|
34
|
+
* Can for example be used to trigger the render process for this container.
|
|
35
|
+
*/
|
|
36
|
+
dirtyStamp?: number;
|
|
37
|
+
}>;
|
|
30
38
|
stamp: number;
|
|
31
39
|
bounds: GeometryBounds;
|
|
32
40
|
config: {
|
|
@@ -37,7 +37,7 @@ export const geometryApi = (set, get, buerliApi) => ({
|
|
|
37
37
|
if (container) {
|
|
38
38
|
geom = new ThreeGeometryCreator().createGeometry(container, color);
|
|
39
39
|
set(state => {
|
|
40
|
-
const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: geom });
|
|
40
|
+
const geometryCache = Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, geom), { dirtyStamp: Date.now() }) });
|
|
41
41
|
return {
|
|
42
42
|
geometry: Object.assign(Object.assign({}, state.geometry), { cache: geometryCache, stamp: Date.now() }),
|
|
43
43
|
};
|
|
@@ -52,14 +52,14 @@ export const geometryApi = (set, get, buerliApi) => ({
|
|
|
52
52
|
cachedGeom.color = thCol;
|
|
53
53
|
cachedGeom.meshes.forEach(mesh => (mesh.color = thCol));
|
|
54
54
|
set(state => ({
|
|
55
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: cachedGeom
|
|
55
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
|
|
56
56
|
}));
|
|
57
57
|
},
|
|
58
58
|
setOpacity: (containerId, opacity) => {
|
|
59
59
|
const cachedGeom = Object.assign(Object.assign({}, get().geometry.cache[containerId]), { opacity });
|
|
60
60
|
cachedGeom.meshes.forEach(mesh => (mesh.opacity = opacity));
|
|
61
61
|
set(state => ({
|
|
62
|
-
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: cachedGeom
|
|
62
|
+
geometry: Object.assign(Object.assign({}, state.geometry), { cache: Object.assign(Object.assign({}, state.geometry.cache), { [containerId]: Object.assign(Object.assign({}, cachedGeom), { dirtyStamp: Date.now() }) }) }),
|
|
63
63
|
}));
|
|
64
64
|
},
|
|
65
65
|
setConfig: (objId, config) => {
|
package/build/types/index.d.ts
CHANGED
package/build/types/index.js
CHANGED
package/build/utils/Math.d.ts
CHANGED
|
@@ -3,4 +3,19 @@ export declare const MathUtils: {
|
|
|
3
3
|
convertToMatrix4: (coordinateSystem: number[][]) => THREE.Matrix4;
|
|
4
4
|
convertToMatrix3: (coordinateSystem: number[][]) => THREE.Matrix3;
|
|
5
5
|
convertToCoordinateSystem: (matrix: THREE.Matrix4) => number[][];
|
|
6
|
+
round(value: number, digits: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Calculates a transformation matrix.
|
|
9
|
+
*
|
|
10
|
+
* xDir and yDir are NOT orthogonal in general case, thus the y-axis is calculated as a series of cross products.
|
|
11
|
+
*
|
|
12
|
+
* @param originPos The origin position.
|
|
13
|
+
* @param xDir The x direction.
|
|
14
|
+
* @param yDir The y direction.
|
|
15
|
+
* @param offset The offset vector.
|
|
16
|
+
* @param rotation The rotation vector.
|
|
17
|
+
* @param inverted The inverted flag --- 0: do not invert; 1: do invert.
|
|
18
|
+
* @returns The calculated THREE.Matrix4
|
|
19
|
+
*/
|
|
20
|
+
calcluateTransform: (originPos: THREE.Vector3, xDir: THREE.Vector3, yDir: THREE.Vector3, offset: THREE.Vector3, rotation: THREE.Vector3, inverted: 0 | 1) => THREE.Matrix4;
|
|
6
21
|
};
|
package/build/utils/Math.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
+
const degToRad = THREE.MathUtils.degToRad;
|
|
3
|
+
const tolerance = 1e-6;
|
|
2
4
|
export const MathUtils = {
|
|
3
5
|
convertToMatrix4: function (coordinateSystem) {
|
|
4
6
|
const [orig, vx, vy, vz] = coordinateSystem.map(row => new THREE.Vector3().fromArray(row));
|
|
@@ -22,4 +24,42 @@ export const MathUtils = {
|
|
|
22
24
|
coordSys[3] = [zAxis.x, zAxis.y, zAxis.z];
|
|
23
25
|
return coordSys;
|
|
24
26
|
},
|
|
27
|
+
round(value, digits) {
|
|
28
|
+
if (isNaN(value))
|
|
29
|
+
return NaN;
|
|
30
|
+
const factor = Math.pow(10, digits);
|
|
31
|
+
return Math.round(value * factor) / factor;
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Calculates a transformation matrix.
|
|
35
|
+
*
|
|
36
|
+
* xDir and yDir are NOT orthogonal in general case, thus the y-axis is calculated as a series of cross products.
|
|
37
|
+
*
|
|
38
|
+
* @param originPos The origin position.
|
|
39
|
+
* @param xDir The x direction.
|
|
40
|
+
* @param yDir The y direction.
|
|
41
|
+
* @param offset The offset vector.
|
|
42
|
+
* @param rotation The rotation vector.
|
|
43
|
+
* @param inverted The inverted flag --- 0: do not invert; 1: do invert.
|
|
44
|
+
* @returns The calculated THREE.Matrix4
|
|
45
|
+
*/
|
|
46
|
+
calcluateTransform: function (originPos, xDir, yDir, offset, rotation, inverted) {
|
|
47
|
+
rotation = new THREE.Vector3(degToRad(rotation.x), degToRad(rotation.y), degToRad(rotation.z));
|
|
48
|
+
const xAxis = xDir.clone().normalize();
|
|
49
|
+
let yDir_ = yDir.clone().normalize();
|
|
50
|
+
if (Math.abs(yDir_.dot(xAxis.clone())) > 1 - tolerance) {
|
|
51
|
+
yDir_ = Math.abs(xAxis.y) !== 1 ? new THREE.Vector3(0.0, 1.0, 0.0) : new THREE.Vector3(1.0, 0.0, 0.0);
|
|
52
|
+
}
|
|
53
|
+
const zAxis = xAxis.clone().cross(yDir_).normalize();
|
|
54
|
+
const yAxis = zAxis.clone().cross(xAxis).normalize();
|
|
55
|
+
if (inverted) {
|
|
56
|
+
xAxis.negate();
|
|
57
|
+
zAxis.negate();
|
|
58
|
+
}
|
|
59
|
+
const mLocal = new THREE.Matrix4()
|
|
60
|
+
.makeRotationFromEuler(new THREE.Euler(rotation.x, rotation.y, rotation.z))
|
|
61
|
+
.setPosition(offset.x, offset.y, offset.z);
|
|
62
|
+
const mGlobal = new THREE.Matrix4().makeBasis(xAxis, yAxis, zAxis).setPosition(originPos);
|
|
63
|
+
return mGlobal.clone().multiply(mLocal);
|
|
64
|
+
},
|
|
25
65
|
};
|
package/build/utils/Measure.d.ts
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { ArcGeometry, LineGeometry, PlaneGeometry, PointGeometry, ProductElement } from './../geometry';
|
|
3
3
|
import { DrawingID } from './../store/states/drawing';
|
|
4
|
+
export declare type ValueMeasureData = {
|
|
5
|
+
value: number;
|
|
6
|
+
};
|
|
4
7
|
export declare type LinearMeasureData = {
|
|
8
|
+
value: number;
|
|
5
9
|
start: THREE.Vector3;
|
|
6
10
|
end: THREE.Vector3;
|
|
7
11
|
};
|
|
8
12
|
export declare type AngularMeasureData = {
|
|
13
|
+
value: number;
|
|
9
14
|
center: THREE.Vector3;
|
|
10
15
|
dir1: THREE.Vector3;
|
|
11
16
|
dir2: THREE.Vector3;
|
|
12
17
|
};
|
|
13
18
|
export declare type PositionMeasureData = {
|
|
14
|
-
|
|
19
|
+
value: THREE.Vector3;
|
|
20
|
+
};
|
|
21
|
+
export declare type VectorMeasureData = {
|
|
22
|
+
value: THREE.Vector3;
|
|
23
|
+
start: THREE.Vector3;
|
|
24
|
+
end: THREE.Vector3;
|
|
15
25
|
};
|
|
16
|
-
declare type MeasureData = LinearMeasureData | AngularMeasureData | PositionMeasureData;
|
|
26
|
+
declare type MeasureData = LinearMeasureData | AngularMeasureData | PositionMeasureData | VectorMeasureData | ValueMeasureData;
|
|
17
27
|
export declare enum MeasureResultType {
|
|
18
28
|
NONE = "none",
|
|
29
|
+
VALUE = "value",
|
|
19
30
|
DISTANCE = "linear",
|
|
20
31
|
ANGLE = "angular",
|
|
21
32
|
VECTOR = "vector",
|
|
@@ -23,7 +34,6 @@ export declare enum MeasureResultType {
|
|
|
23
34
|
}
|
|
24
35
|
export declare type MeasureResult = {
|
|
25
36
|
description: string;
|
|
26
|
-
value: string | number;
|
|
27
37
|
type: MeasureResultType;
|
|
28
38
|
measureData?: MeasureData;
|
|
29
39
|
};
|
|
@@ -32,99 +42,14 @@ export declare const Measure: {
|
|
|
32
42
|
transform(items: Item[], drawingId: DrawingID): Item[];
|
|
33
43
|
getInfo(objects: Item[], drawingId: DrawingID): MeasureResult[];
|
|
34
44
|
calculateMeasures(objects: Item[], drawingId: DrawingID): MeasureResult[];
|
|
35
|
-
calculatePointPoint(point1:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
}[];
|
|
44
|
-
calculatePointLine(point: PointGeometry, line: LineGeometry): {
|
|
45
|
-
value: number;
|
|
46
|
-
description: string;
|
|
47
|
-
type: MeasureResultType;
|
|
48
|
-
measureData: {
|
|
49
|
-
start: THREE.Vector3;
|
|
50
|
-
end: THREE.Vector3;
|
|
51
|
-
};
|
|
52
|
-
}[];
|
|
53
|
-
calculatePointPlane(point: PointGeometry, plane: PlaneGeometry): {
|
|
54
|
-
value: number;
|
|
55
|
-
description: string;
|
|
56
|
-
type: MeasureResultType;
|
|
57
|
-
measureData: {
|
|
58
|
-
start: THREE.Vector3;
|
|
59
|
-
end: THREE.Vector3;
|
|
60
|
-
};
|
|
61
|
-
}[];
|
|
62
|
-
calculateLineLine(first: LineGeometry, second: LineGeometry): ({
|
|
63
|
-
value: number;
|
|
64
|
-
description: string;
|
|
65
|
-
type: MeasureResultType;
|
|
66
|
-
measureData: {
|
|
67
|
-
start: THREE.Vector3;
|
|
68
|
-
end: THREE.Vector3;
|
|
69
|
-
center?: undefined;
|
|
70
|
-
dir1?: undefined;
|
|
71
|
-
dir2?: undefined;
|
|
72
|
-
} | undefined;
|
|
73
|
-
} | {
|
|
74
|
-
value: number;
|
|
75
|
-
description: string;
|
|
76
|
-
type: MeasureResultType;
|
|
77
|
-
measureData: {
|
|
78
|
-
center: THREE.Vector3;
|
|
79
|
-
dir1: THREE.Vector3;
|
|
80
|
-
dir2: THREE.Vector3;
|
|
81
|
-
start?: undefined;
|
|
82
|
-
end?: undefined;
|
|
83
|
-
};
|
|
84
|
-
})[];
|
|
85
|
-
calculateLinePlane(line: LineGeometry, plane: PlaneGeometry): {
|
|
86
|
-
value: number;
|
|
87
|
-
description: string;
|
|
88
|
-
type: MeasureResultType;
|
|
89
|
-
measureData: {
|
|
90
|
-
start: THREE.Vector3;
|
|
91
|
-
end: THREE.Vector3;
|
|
92
|
-
} | undefined;
|
|
93
|
-
}[];
|
|
94
|
-
calculateArcPlane(arc: ArcGeometry, plane: PlaneGeometry): {
|
|
95
|
-
value: number;
|
|
96
|
-
description: string;
|
|
97
|
-
type: MeasureResultType;
|
|
98
|
-
measureData: {
|
|
99
|
-
start: THREE.Vector3;
|
|
100
|
-
end: THREE.Vector3;
|
|
101
|
-
} | undefined;
|
|
102
|
-
}[];
|
|
103
|
-
calculatePlanePlane(plane1: PlaneGeometry, plane2: PlaneGeometry): ({
|
|
104
|
-
value: number;
|
|
105
|
-
description: string;
|
|
106
|
-
type: MeasureResultType;
|
|
107
|
-
measureData: {
|
|
108
|
-
start: THREE.Vector3;
|
|
109
|
-
end: THREE.Vector3;
|
|
110
|
-
center?: undefined;
|
|
111
|
-
dir1?: undefined;
|
|
112
|
-
dir2?: undefined;
|
|
113
|
-
} | undefined;
|
|
114
|
-
} | {
|
|
115
|
-
value: number;
|
|
116
|
-
description: string;
|
|
117
|
-
type: MeasureResultType;
|
|
118
|
-
measureData: {
|
|
119
|
-
center: THREE.Vector3;
|
|
120
|
-
dir1: THREE.Vector3;
|
|
121
|
-
dir2: THREE.Vector3;
|
|
122
|
-
start?: undefined;
|
|
123
|
-
end?: undefined;
|
|
124
|
-
} | undefined;
|
|
125
|
-
})[];
|
|
45
|
+
calculatePointPoint(point1: THREE.Vector3, point2: THREE.Vector3): MeasureResult[];
|
|
46
|
+
calculatePointLine(point: PointGeometry, line: LineGeometry): MeasureResult[];
|
|
47
|
+
calculatePointPlane(point: PointGeometry, plane: PlaneGeometry): MeasureResult[];
|
|
48
|
+
calculateLineLine(first: LineGeometry, second: LineGeometry): MeasureResult[];
|
|
49
|
+
calculateLinePlane(line: LineGeometry, plane: PlaneGeometry): MeasureResult[];
|
|
50
|
+
calculateArcPlane(arc: ArcGeometry, plane: PlaneGeometry): MeasureResult[];
|
|
51
|
+
calculatePlanePlane(plane1: PlaneGeometry, plane2: PlaneGeometry): MeasureResult[];
|
|
126
52
|
degrees(radians: number): number;
|
|
127
|
-
round(value: number, digits: number): number;
|
|
128
53
|
areParallel(vec1: THREE.Vector3, vec2: THREE.Vector3): boolean;
|
|
129
54
|
arePerpendicular(vec1: THREE.Vector3, vec2: THREE.Vector3): boolean;
|
|
130
55
|
getPointLineMPoints(pointsPos: THREE.Vector3, startPos: THREE.Vector3, endPos: THREE.Vector3): [THREE.Vector3, THREE.Vector3];
|
package/build/utils/Measure.js
CHANGED
|
@@ -5,6 +5,7 @@ import { GraphicType } from './../types';
|
|
|
5
5
|
export var MeasureResultType;
|
|
6
6
|
(function (MeasureResultType) {
|
|
7
7
|
MeasureResultType["NONE"] = "none";
|
|
8
|
+
MeasureResultType["VALUE"] = "value";
|
|
8
9
|
MeasureResultType["DISTANCE"] = "linear";
|
|
9
10
|
MeasureResultType["ANGLE"] = "angular";
|
|
10
11
|
MeasureResultType["VECTOR"] = "vector";
|
|
@@ -73,10 +74,6 @@ export const Measure = {
|
|
|
73
74
|
getInfo(objects, drawingId) {
|
|
74
75
|
const transformed = Measure.transform(objects, drawingId);
|
|
75
76
|
const results = [];
|
|
76
|
-
const vecToStr = (point) => `[ ${point
|
|
77
|
-
.toArray()
|
|
78
|
-
.map(n => Math.round(n * 100) / 100)
|
|
79
|
-
.join(', ')} ]`;
|
|
80
77
|
const dir = (start, end) => end.clone().sub(start).normalize();
|
|
81
78
|
const getPointOnCircumference = (center, axis, radius) => {
|
|
82
79
|
const axisNormalized = axis.clone().normalize();
|
|
@@ -90,32 +87,34 @@ export const Measure = {
|
|
|
90
87
|
case GraphicType.CURVEPOINT:
|
|
91
88
|
const point = element;
|
|
92
89
|
results.push({
|
|
93
|
-
value: vecToStr(point.position),
|
|
94
90
|
description: 'Position',
|
|
95
91
|
type: MeasureResultType.POSITION,
|
|
92
|
+
measureData: { value: point.position.clone() },
|
|
96
93
|
});
|
|
97
94
|
break;
|
|
98
95
|
case GraphicType.LINE:
|
|
99
96
|
case GraphicType.CURVELINE:
|
|
100
97
|
const line = element;
|
|
101
|
-
|
|
102
|
-
absoluteDistance = Measure.round(absoluteDistance, 3);
|
|
98
|
+
const absoluteDistance = line.start.distanceTo(line.end);
|
|
103
99
|
results.push({
|
|
104
|
-
value: absoluteDistance,
|
|
105
100
|
description: 'Line length',
|
|
106
101
|
type: MeasureResultType.DISTANCE,
|
|
107
|
-
measureData: { start: line.start.clone(), end: line.end.clone() },
|
|
102
|
+
measureData: { value: absoluteDistance, start: line.start.clone(), end: line.end.clone() },
|
|
108
103
|
});
|
|
109
104
|
break;
|
|
110
105
|
case GraphicType.EDGE:
|
|
111
106
|
case GraphicType.CURVESPLINE:
|
|
112
107
|
const edge = element;
|
|
113
108
|
results.push({
|
|
114
|
-
value: vecToStr(edge.start),
|
|
115
109
|
description: 'Edge start',
|
|
116
110
|
type: MeasureResultType.POSITION,
|
|
111
|
+
measureData: { value: edge.start.clone() },
|
|
112
|
+
});
|
|
113
|
+
results.push({
|
|
114
|
+
description: 'Edge end',
|
|
115
|
+
type: MeasureResultType.POSITION,
|
|
116
|
+
measureData: { value: edge.start.clone() },
|
|
117
117
|
});
|
|
118
|
-
results.push({ value: vecToStr(edge.end), description: 'Edge end', type: MeasureResultType.POSITION });
|
|
119
118
|
break;
|
|
120
119
|
case GraphicType.ARC:
|
|
121
120
|
case GraphicType.CURVEARC:
|
|
@@ -123,22 +122,19 @@ export const Measure = {
|
|
|
123
122
|
const arcNEnd = arc.center.clone().addScaledVector(arc.normal.clone().normalize(), 40);
|
|
124
123
|
const pointOnArc = getPointOnCircumference(arc.center, arc.normal, arc.radius);
|
|
125
124
|
results.push({
|
|
126
|
-
value: vecToStr(arc.center),
|
|
127
125
|
description: 'Arc center',
|
|
128
126
|
type: MeasureResultType.POSITION,
|
|
129
|
-
measureData: {
|
|
127
|
+
measureData: { value: arc.center.clone() },
|
|
130
128
|
});
|
|
131
129
|
results.push({
|
|
132
|
-
value: vecToStr(arc.normal),
|
|
133
130
|
description: 'Arc normal',
|
|
134
131
|
type: MeasureResultType.VECTOR,
|
|
135
|
-
measureData: { start: arc.center.clone(), end: arcNEnd },
|
|
132
|
+
measureData: { value: arc.normal.clone(), start: arc.center.clone(), end: arcNEnd },
|
|
136
133
|
});
|
|
137
134
|
results.push({
|
|
138
|
-
value: arc.radius,
|
|
139
135
|
description: 'Arc radius',
|
|
140
136
|
type: MeasureResultType.DISTANCE,
|
|
141
|
-
measureData: { start: arc.center.clone(), end: pointOnArc },
|
|
137
|
+
measureData: { value: arc.radius, start: arc.center.clone(), end: pointOnArc },
|
|
142
138
|
});
|
|
143
139
|
break;
|
|
144
140
|
case GraphicType.CIRCLE:
|
|
@@ -147,32 +143,28 @@ export const Measure = {
|
|
|
147
143
|
const circleNEnd = circle.center.clone().addScaledVector(circle.normal.clone().normalize(), 40);
|
|
148
144
|
const pointOnCircle = getPointOnCircumference(circle.center, circle.normal, circle.radius);
|
|
149
145
|
results.push({
|
|
150
|
-
value: vecToStr(circle.center),
|
|
151
146
|
description: 'Circle center',
|
|
152
147
|
type: MeasureResultType.POSITION,
|
|
153
|
-
measureData: {
|
|
148
|
+
measureData: { value: circle.center.clone() },
|
|
154
149
|
});
|
|
155
150
|
results.push({
|
|
156
|
-
value: vecToStr(circle.normal),
|
|
157
151
|
description: 'Circle normal',
|
|
158
152
|
type: MeasureResultType.VECTOR,
|
|
159
|
-
measureData: { start: circle.center.clone(), end: circleNEnd },
|
|
153
|
+
measureData: { value: circle.normal.clone(), start: circle.center.clone(), end: circleNEnd },
|
|
160
154
|
});
|
|
161
155
|
results.push({
|
|
162
|
-
value: circle.radius,
|
|
163
156
|
description: 'Circle radius',
|
|
164
157
|
type: MeasureResultType.DISTANCE,
|
|
165
|
-
measureData: { start: circle.center.clone(), end: pointOnCircle },
|
|
158
|
+
measureData: { value: circle.radius, start: circle.center.clone(), end: pointOnCircle },
|
|
166
159
|
});
|
|
167
160
|
break;
|
|
168
161
|
case GraphicType.PLANE:
|
|
169
162
|
const plane = element;
|
|
170
163
|
const planeNEnd = plane.pointOnPlane.clone().addScaledVector(plane.normal.clone().normalize(), 40);
|
|
171
164
|
results.push({
|
|
172
|
-
value: vecToStr(plane.normal),
|
|
173
165
|
description: 'Plane normal',
|
|
174
166
|
type: MeasureResultType.VECTOR,
|
|
175
|
-
measureData: { start: plane.pointOnPlane.clone(), end: planeNEnd },
|
|
167
|
+
measureData: { value: plane.normal, start: plane.pointOnPlane.clone(), end: planeNEnd },
|
|
176
168
|
});
|
|
177
169
|
break;
|
|
178
170
|
case GraphicType.CYLINDER:
|
|
@@ -185,28 +177,24 @@ export const Measure = {
|
|
|
185
177
|
.addScaledVector(dir(cylinder.origin, pointOnCyl), cylinder.radius + 3);
|
|
186
178
|
const cylHEnd = cylHStart.clone().addScaledVector(cylAxisNormalized, cylinder.height);
|
|
187
179
|
results.push({
|
|
188
|
-
value: vecToStr(cylinder.origin),
|
|
189
180
|
description: 'Cylinder origin',
|
|
190
181
|
type: MeasureResultType.POSITION,
|
|
191
|
-
measureData: {
|
|
182
|
+
measureData: { value: cylinder.origin.clone() },
|
|
192
183
|
});
|
|
193
184
|
results.push({
|
|
194
|
-
value: vecToStr(cylinder.axis),
|
|
195
185
|
description: 'Cylinder axis',
|
|
196
186
|
type: MeasureResultType.VECTOR,
|
|
197
|
-
measureData: { start: cylinder.origin.clone(), end: cylNEnd },
|
|
187
|
+
measureData: { value: cylinder.axis, start: cylinder.origin.clone(), end: cylNEnd },
|
|
198
188
|
});
|
|
199
189
|
results.push({
|
|
200
|
-
value: cylinder.radius,
|
|
201
190
|
description: 'Cylinder radius',
|
|
202
191
|
type: MeasureResultType.DISTANCE,
|
|
203
|
-
measureData: { start: cylinder.origin.clone(), end: pointOnCyl },
|
|
192
|
+
measureData: { value: cylinder.radius, start: cylinder.origin.clone(), end: pointOnCyl },
|
|
204
193
|
});
|
|
205
194
|
results.push({
|
|
206
|
-
value: cylinder.height,
|
|
207
195
|
description: 'Cylinder height',
|
|
208
196
|
type: MeasureResultType.DISTANCE,
|
|
209
|
-
measureData: { start: cylHStart, end: cylHEnd },
|
|
197
|
+
measureData: { value: cylinder.height, start: cylHStart, end: cylHEnd },
|
|
210
198
|
});
|
|
211
199
|
break;
|
|
212
200
|
case GraphicType.CONE:
|
|
@@ -228,48 +216,47 @@ export const Measure = {
|
|
|
228
216
|
.clone()
|
|
229
217
|
.addScaledVector(coneAxisNormalized, isExpanding ? -cone.height : cone.height);
|
|
230
218
|
results.push({
|
|
231
|
-
value: vecToStr(cone.origin),
|
|
232
219
|
description: 'Cone origin',
|
|
233
220
|
type: MeasureResultType.POSITION,
|
|
234
|
-
measureData: {
|
|
221
|
+
measureData: { value: cone.origin.clone() },
|
|
235
222
|
});
|
|
236
223
|
results.push({
|
|
237
|
-
value: vecToStr(cone.axis),
|
|
238
224
|
description: 'Cone axis',
|
|
239
225
|
type: MeasureResultType.VECTOR,
|
|
240
|
-
measureData: { start: cone.origin.clone(), end: coneEnd },
|
|
226
|
+
measureData: { value: cone.axis, start: cone.origin.clone(), end: coneEnd },
|
|
241
227
|
});
|
|
242
228
|
results.push({
|
|
243
|
-
value: r,
|
|
244
229
|
description: 'Cone radius (min)',
|
|
245
230
|
type: MeasureResultType.DISTANCE,
|
|
246
|
-
measureData: { start: coneCenterMinR, end: pointOnConeMinR },
|
|
231
|
+
measureData: { value: r, start: coneCenterMinR, end: pointOnConeMinR },
|
|
247
232
|
});
|
|
248
233
|
results.push({
|
|
249
|
-
value: R,
|
|
250
234
|
description: 'Cone radius (max)',
|
|
251
235
|
type: MeasureResultType.DISTANCE,
|
|
252
|
-
measureData: { start: coneCenterMaxR, end: pointOnConeMaxR },
|
|
236
|
+
measureData: { value: R, start: coneCenterMaxR, end: pointOnConeMaxR },
|
|
253
237
|
});
|
|
254
238
|
results.push({
|
|
255
|
-
value: cone.height,
|
|
256
239
|
description: 'Cone height',
|
|
257
240
|
type: MeasureResultType.DISTANCE,
|
|
258
|
-
measureData: { start: coneHStart, end: coneHEnd },
|
|
241
|
+
measureData: { value: cone.height, start: coneHStart, end: coneHEnd },
|
|
259
242
|
});
|
|
260
243
|
break;
|
|
261
244
|
case GraphicType.SPHERE:
|
|
262
245
|
const sphere = element;
|
|
263
|
-
results.push({
|
|
246
|
+
results.push({
|
|
247
|
+
description: 'Sphere radius',
|
|
248
|
+
type: MeasureResultType.VALUE,
|
|
249
|
+
measureData: { value: sphere.radius },
|
|
250
|
+
});
|
|
264
251
|
break;
|
|
265
252
|
case GraphicType.NURBS:
|
|
266
|
-
results.push({
|
|
253
|
+
results.push({ description: 'NURBS', type: MeasureResultType.NONE });
|
|
267
254
|
break;
|
|
268
255
|
case GraphicType.NURBSSURFACE:
|
|
269
|
-
results.push({
|
|
256
|
+
results.push({ description: 'NURBS Surface', type: MeasureResultType.NONE });
|
|
270
257
|
break;
|
|
271
258
|
default:
|
|
272
|
-
results.push({
|
|
259
|
+
results.push({ description: 'Undefined', type: MeasureResultType.NONE });
|
|
273
260
|
break;
|
|
274
261
|
}
|
|
275
262
|
}
|
|
@@ -286,7 +273,7 @@ export const Measure = {
|
|
|
286
273
|
switch (second.type) {
|
|
287
274
|
case GraphicType.POINT:
|
|
288
275
|
case GraphicType.CURVEPOINT:
|
|
289
|
-
results = Measure.calculatePointPoint(first, second);
|
|
276
|
+
results = Measure.calculatePointPoint(first.position, second.position);
|
|
290
277
|
break;
|
|
291
278
|
case GraphicType.LINE:
|
|
292
279
|
case GraphicType.CURVELINE:
|
|
@@ -295,6 +282,10 @@ export const Measure = {
|
|
|
295
282
|
case GraphicType.PLANE:
|
|
296
283
|
results = Measure.calculatePointPlane(first, second);
|
|
297
284
|
break;
|
|
285
|
+
case GraphicType.ARC:
|
|
286
|
+
case GraphicType.CIRCLE:
|
|
287
|
+
results = Measure.calculatePointPoint(first.position.clone(), second.center.clone());
|
|
288
|
+
break;
|
|
298
289
|
default:
|
|
299
290
|
results = Measure.getInfo(objects, drawingId);
|
|
300
291
|
break;
|
|
@@ -319,6 +310,21 @@ export const Measure = {
|
|
|
319
310
|
break;
|
|
320
311
|
}
|
|
321
312
|
break;
|
|
313
|
+
case GraphicType.CIRCLE:
|
|
314
|
+
case GraphicType.ARC:
|
|
315
|
+
switch (second.type) {
|
|
316
|
+
case GraphicType.ARC:
|
|
317
|
+
case GraphicType.CIRCLE:
|
|
318
|
+
results = Measure.calculatePointPoint(first.center, second.center);
|
|
319
|
+
break;
|
|
320
|
+
case GraphicType.POINT:
|
|
321
|
+
results = Measure.calculatePointPoint(first.center, second.position);
|
|
322
|
+
break;
|
|
323
|
+
default:
|
|
324
|
+
results = Measure.getInfo(objects, drawingId);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
322
328
|
case GraphicType.PLANE:
|
|
323
329
|
switch (second.type) {
|
|
324
330
|
case GraphicType.POINT:
|
|
@@ -348,133 +354,114 @@ export const Measure = {
|
|
|
348
354
|
return results;
|
|
349
355
|
},
|
|
350
356
|
calculatePointPoint(point1, point2) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
357
|
-
const p2 = point2.position.clone();
|
|
357
|
+
const p1 = point1.clone();
|
|
358
|
+
const p2 = point2.clone();
|
|
359
|
+
const distance = p1.distanceTo(p2);
|
|
360
|
+
const dx = Math.abs(p1.x - p2.x);
|
|
361
|
+
const dy = Math.abs(p1.y - p2.y);
|
|
362
|
+
const dz = Math.abs(p1.z - p2.z);
|
|
358
363
|
const px = p1.clone().setX(p2.x);
|
|
359
364
|
const pxy = px.clone().setY(p2.y);
|
|
360
365
|
return [
|
|
361
366
|
{
|
|
362
|
-
value: distance,
|
|
363
367
|
description: 'Distance',
|
|
364
368
|
type: MeasureResultType.DISTANCE,
|
|
365
|
-
measureData: { start: p1, end: p2 },
|
|
369
|
+
measureData: { value: distance, start: p1, end: p2 },
|
|
366
370
|
},
|
|
367
|
-
{
|
|
368
|
-
{
|
|
369
|
-
{
|
|
371
|
+
{ description: 'dx', type: MeasureResultType.DISTANCE, measureData: { value: dx, start: p1, end: px } },
|
|
372
|
+
{ description: 'dy', type: MeasureResultType.DISTANCE, measureData: { value: dy, start: px, end: pxy } },
|
|
373
|
+
{ description: 'dz', type: MeasureResultType.DISTANCE, measureData: { value: dz, start: pxy, end: p2 } },
|
|
370
374
|
];
|
|
371
375
|
},
|
|
372
376
|
calculatePointLine(point, line) {
|
|
373
377
|
const [start, end] = Measure.getPointLineMPoints(point.position, line.start, line.end);
|
|
374
|
-
const distance =
|
|
378
|
+
const distance = start.distanceTo(end);
|
|
375
379
|
return [
|
|
376
380
|
{
|
|
377
|
-
value: distance,
|
|
378
381
|
description: 'Distance',
|
|
379
382
|
type: MeasureResultType.DISTANCE,
|
|
380
|
-
measureData: { start, end },
|
|
383
|
+
measureData: { value: distance, start, end },
|
|
381
384
|
},
|
|
382
385
|
];
|
|
383
386
|
},
|
|
384
387
|
calculatePointPlane(point, plane) {
|
|
385
388
|
const [start, end] = Measure.getPointPlaneMPoints(point.position, plane.pointOnPlane, plane.normal);
|
|
386
|
-
const distance =
|
|
389
|
+
const distance = start.distanceTo(end);
|
|
387
390
|
return [
|
|
388
391
|
{
|
|
389
|
-
value: distance,
|
|
390
392
|
description: 'Distance',
|
|
391
393
|
type: MeasureResultType.DISTANCE,
|
|
392
|
-
measureData: { start, end },
|
|
394
|
+
measureData: { value: distance, start, end },
|
|
393
395
|
},
|
|
394
396
|
];
|
|
395
397
|
},
|
|
396
398
|
calculateLineLine(first, second) {
|
|
397
399
|
const [start, end] = Measure.getLineLineMPoints(first.start, first.end, second.start, second.end);
|
|
398
|
-
const distance = start && end ?
|
|
400
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
399
401
|
const [dir1, dir2] = Measure.getLineLineMDirs(first.start, first.end, second.start, second.end);
|
|
400
|
-
const angle = Measure.
|
|
402
|
+
const angle = Measure.degrees(dir1.angleTo(dir2));
|
|
401
403
|
const angleS = 180 - angle;
|
|
402
404
|
return [
|
|
403
405
|
{
|
|
404
|
-
value: distance,
|
|
405
406
|
description: 'Distance',
|
|
406
407
|
type: MeasureResultType.DISTANCE,
|
|
407
|
-
measureData: start && end ? { start, end } : undefined,
|
|
408
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
408
409
|
},
|
|
409
410
|
{
|
|
410
|
-
value: angle,
|
|
411
411
|
description: 'Angle1',
|
|
412
412
|
type: MeasureResultType.ANGLE,
|
|
413
|
-
measureData: { center: first.start, dir1, dir2 },
|
|
413
|
+
measureData: { value: angle, center: first.start, dir1, dir2 },
|
|
414
414
|
},
|
|
415
415
|
{
|
|
416
|
-
value: angleS,
|
|
417
416
|
description: 'Angle2',
|
|
418
417
|
type: MeasureResultType.ANGLE,
|
|
419
|
-
measureData: { center: first.start, dir1, dir2: dir2.clone().negate() },
|
|
418
|
+
measureData: { value: angleS, center: first.start, dir1, dir2: dir2.clone().negate() },
|
|
420
419
|
},
|
|
421
420
|
];
|
|
422
421
|
},
|
|
423
422
|
calculateLinePlane(line, plane) {
|
|
424
423
|
const [start, end] = Measure.getLinePlaneMPoints(line.start, line.end, plane.pointOnPlane, plane.normal);
|
|
425
|
-
const distance = start && end ?
|
|
424
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
426
425
|
return [
|
|
427
426
|
{
|
|
428
|
-
value: distance,
|
|
429
427
|
description: 'Distance',
|
|
430
428
|
type: MeasureResultType.DISTANCE,
|
|
431
|
-
measureData: start && end ? { start, end } : undefined,
|
|
429
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
432
430
|
},
|
|
433
431
|
];
|
|
434
432
|
},
|
|
435
433
|
calculateArcPlane(arc, plane) {
|
|
436
434
|
const [start, end] = Measure.getArcPlaneMPoints(arc.center, arc.normal, plane.pointOnPlane, plane.normal);
|
|
437
|
-
const distance = start && end ?
|
|
435
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
438
436
|
return [
|
|
439
437
|
{
|
|
440
|
-
value: distance,
|
|
441
438
|
description: 'Distance',
|
|
442
439
|
type: MeasureResultType.DISTANCE,
|
|
443
|
-
measureData: start && end ? { start, end } : undefined,
|
|
440
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
444
441
|
},
|
|
445
442
|
];
|
|
446
443
|
},
|
|
447
444
|
calculatePlanePlane(plane1, plane2) {
|
|
448
445
|
const [start, end] = Measure.getPlanePlaneMPoints(plane1.pointOnPlane, plane1.normal, plane2.pointOnPlane, plane2.normal);
|
|
449
|
-
const distance = start && end ?
|
|
446
|
+
const distance = start && end ? start.distanceTo(end) : NaN;
|
|
450
447
|
const [dir1, dir2] = Measure.getPlanePlaneMDirs(plane1.normal, plane2.normal);
|
|
451
|
-
const angle = dir1 && dir2
|
|
452
|
-
? Measure.round(Measure.degrees(dir1.angleTo(dir2)), 3)
|
|
453
|
-
: Measure.round(Measure.degrees(plane1.normal.angleTo(plane2.normal)), 3);
|
|
448
|
+
const angle = dir1 && dir2 ? Measure.degrees(dir1.angleTo(dir2)) : Measure.degrees(plane1.normal.angleTo(plane2.normal));
|
|
454
449
|
return [
|
|
455
450
|
{
|
|
456
|
-
value: distance,
|
|
457
451
|
description: 'Distance',
|
|
458
452
|
type: MeasureResultType.DISTANCE,
|
|
459
|
-
measureData: start && end ? { start, end } : undefined,
|
|
453
|
+
measureData: start && end ? { value: distance, start, end } : undefined,
|
|
460
454
|
},
|
|
461
455
|
{
|
|
462
|
-
value: angle,
|
|
463
456
|
description: 'Angle',
|
|
464
457
|
type: MeasureResultType.ANGLE,
|
|
465
|
-
measureData: dir1 && dir2 ? { center: plane1.pointOnPlane.clone(), dir1, dir2 } : undefined,
|
|
458
|
+
measureData: dir1 && dir2 ? { value: angle, center: plane1.pointOnPlane.clone(), dir1, dir2 } : undefined,
|
|
466
459
|
},
|
|
467
460
|
];
|
|
468
461
|
},
|
|
469
462
|
degrees(radians) {
|
|
470
463
|
return (radians / Math.PI) * 180;
|
|
471
464
|
},
|
|
472
|
-
round(value, digits) {
|
|
473
|
-
if (isNaN(value))
|
|
474
|
-
return NaN;
|
|
475
|
-
const factor = Math.pow(10, digits);
|
|
476
|
-
return Math.round(value * factor) / factor;
|
|
477
|
-
},
|
|
478
465
|
areParallel(vec1, vec2) {
|
|
479
466
|
const val = Math.abs(vec1.clone().cross(vec2).length());
|
|
480
467
|
return val < tolerance;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|