@jscad/modeling 2.12.3 → 2.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.12.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/modeling@2.12.3...@jscad/modeling@2.12.4) (2024-11-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/modeling
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [2.12.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/modeling@2.12.2...@jscad/modeling@2.12.3) (2024-10-06)
|
|
7
15
|
|
|
8
16
|
|
|
@@ -275,7 +275,7 @@ const signedDistanceToPoint=require("../../maths/plane/signedDistanceToPoint"),{
|
|
|
275
275
|
module.exports={colors:require("./colors"),curves:require("./curves"),geometries:require("./geometries"),maths:require("./maths"),measurements:require("./measurements"),primitives:require("./primitives"),text:require("./text"),utils:require("./utils"),booleans:require("./operations/booleans"),expansions:require("./operations/expansions"),extrusions:require("./operations/extrusions"),hulls:require("./operations/hulls"),modifiers:require("./operations/modifiers"),transforms:require("./operations/transforms")};
|
|
276
276
|
|
|
277
277
|
},{"./colors":8,"./curves":19,"./geometries":50,"./maths":95,"./measurements":252,"./operations/booleans":266,"./operations/expansions":295,"./operations/extrusions":318,"./operations/hulls":341,"./operations/modifiers":352,"./operations/transforms":362,"./primitives":378,"./text":392,"./utils":400}],93:[function(require,module,exports){
|
|
278
|
-
const mat4=require("./mat4"),vec2=require("./vec2"),vec3=require("./vec3"),OrthoNormalBasis=function(e,t){arguments.length<2&&(t=vec3.orthogonal(vec3.create(),e)),this.v=vec3.normalize(vec3.create(),vec3.cross(vec3.create(),e,t)),this.u=vec3.cross(vec3.create(),this.v,e),this.plane=e,this.planeorigin=vec3.scale(vec3.create(),e,e[3])};OrthoNormalBasis.
|
|
278
|
+
const mat4=require("./mat4"),vec2=require("./vec2"),vec3=require("./vec3"),OrthoNormalBasis=function(e,t){arguments.length<2&&(t=vec3.orthogonal(vec3.create(),e)),this.v=vec3.normalize(vec3.create(),vec3.cross(vec3.create(),e,t)),this.u=vec3.cross(vec3.create(),this.v,e),this.plane=e,this.planeorigin=vec3.scale(vec3.create(),e,e[3])};OrthoNormalBasis.prototype={getProjectionMatrix:function(){return mat4.fromValues(this.u[0],this.v[0],this.plane[0],0,this.u[1],this.v[1],this.plane[1],0,this.u[2],this.v[2],this.plane[2],0,0,0,-this.plane[3],1)},getInverseProjectionMatrix:function(){const e=vec3.scale(vec3.create(),this.plane,this.plane[3]);return mat4.fromValues(this.u[0],this.u[1],this.u[2],0,this.v[0],this.v[1],this.v[2],0,this.plane[0],this.plane[1],this.plane[2],0,e[0],e[1],e[2],1)},to2D:function(e){return vec2.fromValues(vec3.dot(e,this.u),vec3.dot(e,this.v))},to3D:function(e){const t=vec3.scale(vec3.create(),this.u,e[0]),s=vec3.scale(vec3.create(),this.v,e[1]),i=vec3.add(t,t,this.planeorigin);return vec3.add(s,s,i)}},module.exports=OrthoNormalBasis;
|
|
279
279
|
|
|
280
280
|
},{"./mat4":143,"./vec2":191,"./vec3":222}],94:[function(require,module,exports){
|
|
281
281
|
const spatialResolution=1e5,EPS=1e-5,NEPS=1e-13,TAU=2*Math.PI;module.exports={EPS:EPS,NEPS:NEPS,TAU:TAU,spatialResolution:1e5};
|
|
@@ -1136,7 +1136,7 @@ module.exports={arc:require("./arc"),circle:require("./circle"),cube:require("./
|
|
|
1136
1136
|
const path2=require("../geometries/path2"),line=r=>{if(!Array.isArray(r))throw new Error("points must be an array");return path2.fromPoints({},r)};module.exports=line;
|
|
1137
1137
|
|
|
1138
1138
|
},{"../geometries/path2":62}],380:[function(require,module,exports){
|
|
1139
|
-
const geom2=require("../geometries/geom2"),polygon=r=>{const{points:o,paths:t,orientation:e}=Object.assign({},{points:[],paths:[],orientation:"counterclockwise"},r);if(!Array.isArray(o)||!Array.isArray(t))throw new Error("points and paths must be arrays");let s=o;Array.isArray(o[0])&&(Array.isArray(o[0][0])||(s=[o])),s.forEach((r,o)=>{if(!Array.isArray(r))throw new Error("list of points "+o+" must be an array");if(r.length<3)throw new Error("list of points "+o+" must contain three or more points");r.forEach((r,t)=>{if(!Array.isArray(r))throw new Error("list of points "+o+", point "+t+" must be an array");if(r.length<2)throw new Error("list of points "+o+", point "+t+" must contain by X and Y values")})});let a=t;if(0===t.length){let r=0;a=s.map(o=>o.map(o=>r++))}const n=[];s.forEach(r=>r.forEach(r=>n.push(r)));let i=[];a.forEach(r=>{const o=r.map(r=>n[r]),t=geom2.fromPoints(o);i=i.concat(geom2.toSides(t))});let c=geom2.create(i);return"clockwise"
|
|
1139
|
+
const geom2=require("../geometries/geom2"),polygon=r=>{const{points:o,paths:t,orientation:e}=Object.assign({},{points:[],paths:[],orientation:"counterclockwise"},r);if(!Array.isArray(o)||!Array.isArray(t))throw new Error("points and paths must be arrays");let s=o;Array.isArray(o[0])&&(Array.isArray(o[0][0])||(s=[o])),s.forEach((r,o)=>{if(!Array.isArray(r))throw new Error("list of points "+o+" must be an array");if(r.length<3)throw new Error("list of points "+o+" must contain three or more points");r.forEach((r,t)=>{if(!Array.isArray(r))throw new Error("list of points "+o+", point "+t+" must be an array");if(r.length<2)throw new Error("list of points "+o+", point "+t+" must contain by X and Y values")})});let a=t;if(0===t.length){let r=0;a=s.map(o=>o.map(o=>r++))}const n=[];s.forEach(r=>r.forEach(r=>n.push(r)));let i=[];a.forEach(r=>{const o=r.map(r=>n[r]),t=geom2.fromPoints(o);i=i.concat(geom2.toSides(t))});let c=geom2.create(i);return"clockwise"===e&&(c=geom2.reverse(c)),c};module.exports=polygon;
|
|
1140
1140
|
|
|
1141
1141
|
},{"../geometries/geom2":25}],381:[function(require,module,exports){
|
|
1142
1142
|
const geom3=require("../geometries/geom3"),poly3=require("../geometries/poly3"),{isNumberArray:isNumberArray}=require("./commonChecks"),polyhedron=r=>{const e={points:[],faces:[],colors:void 0,orientation:"outward"},{points:o,faces:a,colors:t,orientation:n}=Object.assign({},e,r);if(!Array.isArray(o)||!Array.isArray(a))throw new Error("points and faces must be arrays");if(o.length<3)throw new Error("three or more points are required");if(a.length<1)throw new Error("one or more faces are required");if(t){if(!Array.isArray(t))throw new Error("colors must be an array");if(t.length!==a.length)throw new Error("faces and colors must have the same length")}o.forEach((r,e)=>{if(!isNumberArray(r,3))throw new Error(`point ${e} must be an array of X, Y, Z values`)}),a.forEach((r,e)=>{if(r.length<3)throw new Error(`face ${e} must contain 3 or more indexes`);if(!isNumberArray(r,r.length))throw new Error(`face ${e} must be an array of numbers`)}),"outward"!==n&&a.forEach(r=>r.reverse());const s=a.map((r,e)=>{const a=poly3.create(r.map(r=>o[r]));return t&&t[e]&&(a.color=t[e]),a});return geom3.create(s)};module.exports=polyhedron;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/modeling",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.4",
|
|
4
4
|
"description": "Constructive Solid Geometry (CSG) Library for JSCAD",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"nyc": "15.1.0",
|
|
62
62
|
"uglifyify": "5.0.2"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "ce4978ee40c30803cba05d1c96ba8b6aaf3abc61"
|
|
65
65
|
}
|
|
@@ -3,24 +3,29 @@ const test = require('ava')
|
|
|
3
3
|
const { fromPointsConvex, validate } = require('./index')
|
|
4
4
|
|
|
5
5
|
test('fromPointsConvex (uniquePoints)', (t) => {
|
|
6
|
-
|
|
7
|
-
for(x
|
|
8
|
-
for(y
|
|
9
|
-
|
|
10
|
-
if (x*x+y*y+z*z <= 96)
|
|
11
|
-
|
|
6
|
+
const out = []
|
|
7
|
+
for (let x = -9; x <= 9; ++x) {
|
|
8
|
+
for (let y = -9; y <= 9; ++y) {
|
|
9
|
+
for (let z = -9; z <= 9; ++z) {
|
|
10
|
+
if (x * x + y * y + z * z <= 96) out.push([x, y, z])
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
const obs = fromPointsConvex(out)
|
|
14
16
|
validate(obs)
|
|
17
|
+
|
|
15
18
|
t.is(obs.polygons.length, 170)
|
|
16
|
-
t.true(obs.polygons.every((f) => ([3,4,8,9].indexOf(f.vertices.length) !== -1)))
|
|
17
|
-
|
|
19
|
+
t.true(obs.polygons.every((f) => ([3, 4, 8, 9].indexOf(f.vertices.length) !== -1)))
|
|
20
|
+
|
|
21
|
+
const c = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
18
22
|
obs.polygons.forEach((f) => c[f.vertices.length]++)
|
|
19
|
-
t.is(c[3], 120)
|
|
20
|
-
t.is(c[4], 24)
|
|
21
|
-
t.is(c[8], 18)
|
|
22
|
-
t.is(c[9], 8)
|
|
23
|
-
|
|
23
|
+
t.is(c[3], 120)
|
|
24
|
+
t.is(c[4], 24)
|
|
25
|
+
t.is(c[8], 18)
|
|
26
|
+
t.is(c[9], 8)
|
|
27
|
+
|
|
28
|
+
let edges2 = 336 * 2
|
|
24
29
|
obs.polygons.forEach((f) => edges2 -= f.vertices.length)
|
|
25
|
-
t.is(edges2, 0)
|
|
30
|
+
t.is(edges2, 0)
|
|
26
31
|
})
|
|
@@ -21,128 +21,6 @@ const OrthoNormalBasis = function (plane, rightvector) {
|
|
|
21
21
|
this.planeorigin = vec3.scale(vec3.create(), plane, plane[3])
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
// Get an orthonormal basis for the standard XYZ planes.
|
|
25
|
-
// Parameters: the names of two 3D axes. The 2d x axis will map to the first given 3D axis, the 2d y
|
|
26
|
-
// axis will map to the second.
|
|
27
|
-
// Prepend the axis with a "-" to invert the direction of this axis.
|
|
28
|
-
// For example: OrthoNormalBasis.GetCartesian("-Y","Z")
|
|
29
|
-
// will return an orthonormal basis where the 2d X axis maps to the 3D inverted Y axis, and
|
|
30
|
-
// the 2d Y axis maps to the 3D Z axis.
|
|
31
|
-
OrthoNormalBasis.GetCartesian = function (xaxisid, yaxisid) {
|
|
32
|
-
const axisid = xaxisid + '/' + yaxisid
|
|
33
|
-
let planenormal, rightvector
|
|
34
|
-
if (axisid === 'X/Y') {
|
|
35
|
-
planenormal = [0, 0, 1]
|
|
36
|
-
rightvector = [1, 0, 0]
|
|
37
|
-
} else if (axisid === 'Y/-X') {
|
|
38
|
-
planenormal = [0, 0, 1]
|
|
39
|
-
rightvector = [0, 1, 0]
|
|
40
|
-
} else if (axisid === '-X/-Y') {
|
|
41
|
-
planenormal = [0, 0, 1]
|
|
42
|
-
rightvector = [-1, 0, 0]
|
|
43
|
-
} else if (axisid === '-Y/X') {
|
|
44
|
-
planenormal = [0, 0, 1]
|
|
45
|
-
rightvector = [0, -1, 0]
|
|
46
|
-
} else if (axisid === '-X/Y') {
|
|
47
|
-
planenormal = [0, 0, -1]
|
|
48
|
-
rightvector = [-1, 0, 0]
|
|
49
|
-
} else if (axisid === '-Y/-X') {
|
|
50
|
-
planenormal = [0, 0, -1]
|
|
51
|
-
rightvector = [0, -1, 0]
|
|
52
|
-
} else if (axisid === 'X/-Y') {
|
|
53
|
-
planenormal = [0, 0, -1]
|
|
54
|
-
rightvector = [1, 0, 0]
|
|
55
|
-
} else if (axisid === 'Y/X') {
|
|
56
|
-
planenormal = [0, 0, -1]
|
|
57
|
-
rightvector = [0, 1, 0]
|
|
58
|
-
} else if (axisid === 'X/Z') {
|
|
59
|
-
planenormal = [0, -1, 0]
|
|
60
|
-
rightvector = [1, 0, 0]
|
|
61
|
-
} else if (axisid === 'Z/-X') {
|
|
62
|
-
planenormal = [0, -1, 0]
|
|
63
|
-
rightvector = [0, 0, 1]
|
|
64
|
-
} else if (axisid === '-X/-Z') {
|
|
65
|
-
planenormal = [0, -1, 0]
|
|
66
|
-
rightvector = [-1, 0, 0]
|
|
67
|
-
} else if (axisid === '-Z/X') {
|
|
68
|
-
planenormal = [0, -1, 0]
|
|
69
|
-
rightvector = [0, 0, -1]
|
|
70
|
-
} else if (axisid === '-X/Z') {
|
|
71
|
-
planenormal = [0, 1, 0]
|
|
72
|
-
rightvector = [-1, 0, 0]
|
|
73
|
-
} else if (axisid === '-Z/-X') {
|
|
74
|
-
planenormal = [0, 1, 0]
|
|
75
|
-
rightvector = [0, 0, -1]
|
|
76
|
-
} else if (axisid === 'X/-Z') {
|
|
77
|
-
planenormal = [0, 1, 0]
|
|
78
|
-
rightvector = [1, 0, 0]
|
|
79
|
-
} else if (axisid === 'Z/X') {
|
|
80
|
-
planenormal = [0, 1, 0]
|
|
81
|
-
rightvector = [0, 0, 1]
|
|
82
|
-
} else if (axisid === 'Y/Z') {
|
|
83
|
-
planenormal = [1, 0, 0]
|
|
84
|
-
rightvector = [0, 1, 0]
|
|
85
|
-
} else if (axisid === 'Z/-Y') {
|
|
86
|
-
planenormal = [1, 0, 0]
|
|
87
|
-
rightvector = [0, 0, 1]
|
|
88
|
-
} else if (axisid === '-Y/-Z') {
|
|
89
|
-
planenormal = [1, 0, 0]
|
|
90
|
-
rightvector = [0, -1, 0]
|
|
91
|
-
} else if (axisid === '-Z/Y') {
|
|
92
|
-
planenormal = [1, 0, 0]
|
|
93
|
-
rightvector = [0, 0, -1]
|
|
94
|
-
} else if (axisid === '-Y/Z') {
|
|
95
|
-
planenormal = [-1, 0, 0]
|
|
96
|
-
rightvector = [0, -1, 0]
|
|
97
|
-
} else if (axisid === '-Z/-Y') {
|
|
98
|
-
planenormal = [-1, 0, 0]
|
|
99
|
-
rightvector = [0, 0, -1]
|
|
100
|
-
} else if (axisid === 'Y/-Z') {
|
|
101
|
-
planenormal = [-1, 0, 0]
|
|
102
|
-
rightvector = [0, 1, 0]
|
|
103
|
-
} else if (axisid === 'Z/Y') {
|
|
104
|
-
planenormal = [-1, 0, 0]
|
|
105
|
-
rightvector = [0, 0, 1]
|
|
106
|
-
} else {
|
|
107
|
-
throw new Error('OrthoNormalBasis.GetCartesian: invalid combination of axis identifiers. Should pass two string arguments from [X,Y,Z,-X,-Y,-Z], being two different axes.')
|
|
108
|
-
}
|
|
109
|
-
return new OrthoNormalBasis(new Plane(new Vector3D(planenormal), 0), new Vector3D(rightvector))
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/*
|
|
113
|
-
// test code for OrthoNormalBasis.GetCartesian()
|
|
114
|
-
OrthoNormalBasis.GetCartesian_Test=function() {
|
|
115
|
-
let axisnames=["X","Y","Z","-X","-Y","-Z"];
|
|
116
|
-
let axisvectors=[[1,0,0], [0,1,0], [0,0,1], [-1,0,0], [0,-1,0], [0,0,-1]];
|
|
117
|
-
for(let axis1=0; axis1 < 3; axis1++) {
|
|
118
|
-
for(let axis1inverted=0; axis1inverted < 2; axis1inverted++) {
|
|
119
|
-
let axis1name=axisnames[axis1+3*axis1inverted];
|
|
120
|
-
let axis1vector=axisvectors[axis1+3*axis1inverted];
|
|
121
|
-
for(let axis2=0; axis2 < 3; axis2++) {
|
|
122
|
-
if(axis2 != axis1) {
|
|
123
|
-
for(let axis2inverted=0; axis2inverted < 2; axis2inverted++) {
|
|
124
|
-
let axis2name=axisnames[axis2+3*axis2inverted];
|
|
125
|
-
let axis2vector=axisvectors[axis2+3*axis2inverted];
|
|
126
|
-
let orthobasis=OrthoNormalBasis.GetCartesian(axis1name, axis2name);
|
|
127
|
-
let test1=orthobasis.to3D(new Vector2D([1,0]));
|
|
128
|
-
let test2=orthobasis.to3D(new Vector2D([0,1]));
|
|
129
|
-
let expected1=new Vector3D(axis1vector);
|
|
130
|
-
let expected2=new Vector3D(axis2vector);
|
|
131
|
-
let d1=test1.distanceTo(expected1);
|
|
132
|
-
let d2=test2.distanceTo(expected2);
|
|
133
|
-
if( (d1 > 0.01) || (d2 > 0.01) ) {
|
|
134
|
-
throw new Error("Wrong!");
|
|
135
|
-
}}}}}}
|
|
136
|
-
throw new Error("OK");
|
|
137
|
-
};
|
|
138
|
-
*/
|
|
139
|
-
|
|
140
|
-
// The z=0 plane, with the 3D x and y vectors mapped to the 2D x and y vector
|
|
141
|
-
OrthoNormalBasis.Z0Plane = function () {
|
|
142
|
-
const plane = new Plane(new Vector3D([0, 0, 1]), 0)
|
|
143
|
-
return new OrthoNormalBasis(plane, new Vector3D([1, 0, 0]))
|
|
144
|
-
}
|
|
145
|
-
|
|
146
24
|
OrthoNormalBasis.prototype = {
|
|
147
25
|
|
|
148
26
|
getProjectionMatrix: function () {
|
|
@@ -175,32 +53,6 @@ OrthoNormalBasis.prototype = {
|
|
|
175
53
|
const v3 = vec3.add(v1, v1, this.planeorigin)
|
|
176
54
|
const v4 = vec3.add(v2, v2, v3)
|
|
177
55
|
return v4
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
line3Dto2D: function (line3d) {
|
|
181
|
-
const a = line3d.point
|
|
182
|
-
const b = line3d.direction.plus(a)
|
|
183
|
-
const a2d = this.to2D(a)
|
|
184
|
-
const b2d = this.to2D(b)
|
|
185
|
-
return Line2D.fromPoints(a2d, b2d)
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
line2Dto3D: function (line2d) {
|
|
189
|
-
const a = line2d.origin()
|
|
190
|
-
const b = line2d.direction().plus(a)
|
|
191
|
-
const a3d = this.to3D(a)
|
|
192
|
-
const b3d = this.to3D(b)
|
|
193
|
-
return Line3D.fromPoints(a3d, b3d)
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
transform: function (matrix4x4) {
|
|
197
|
-
// todo: this may not work properly in case of mirroring
|
|
198
|
-
const newplane = this.plane.transform(matrix4x4)
|
|
199
|
-
const rightpointTransformed = this.u.transform(matrix4x4)
|
|
200
|
-
const originTransformed = new Vector3D(0, 0, 0).transform(matrix4x4)
|
|
201
|
-
const newrighthandvector = rightpointTransformed.minus(originTransformed)
|
|
202
|
-
const newbasis = new OrthoNormalBasis(newplane, newrighthandvector)
|
|
203
|
-
return newbasis
|
|
204
56
|
}
|
|
205
57
|
}
|
|
206
58
|
|
|
@@ -71,8 +71,8 @@ const polygon = (options) => {
|
|
|
71
71
|
})
|
|
72
72
|
|
|
73
73
|
// convert the list of sides into a geometry
|
|
74
|
-
let geometry =
|
|
75
|
-
if (orientation
|
|
74
|
+
let geometry = geom2.create(sides)
|
|
75
|
+
if (orientation === 'clockwise') {
|
|
76
76
|
geometry = geom2.reverse(geometry)
|
|
77
77
|
}
|
|
78
78
|
return geometry
|
|
@@ -56,7 +56,7 @@ test('polygon: providing object.points (array) and object.path (array) creates e
|
|
|
56
56
|
test('polygon: clockwise points', (t) => {
|
|
57
57
|
const poly = polygon({
|
|
58
58
|
points: [[-10, -0], [-10, -10], [-15, -5]],
|
|
59
|
-
orientation:
|
|
59
|
+
orientation: 'clockwise'
|
|
60
60
|
})
|
|
61
61
|
t.is(poly.sides.length, 3)
|
|
62
62
|
t.is(measureArea(poly), 25)
|