@jscad/modeling 2.7.1 → 2.9.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.
- package/CHANGELOG.md +46 -0
- package/dist/jscad-modeling.min.js +174 -144
- package/package.json +2 -2
- package/src/colors/hslToRgb.js +1 -1
- package/src/colors/hueToColorComponent.js +1 -0
- package/src/curves/bezier/tangentAt.js +2 -2
- package/src/curves/bezier/tangentAt.test.js +1 -1
- package/src/curves/bezier/valueAt.test.js +1 -1
- package/src/geometries/geom2/index.js +10 -0
- package/src/geometries/geom2/isA.js +2 -2
- package/src/geometries/geom2/toCompactBinary.js +4 -4
- package/src/geometries/geom2/toOutlines.js +6 -11
- package/src/geometries/geom2/toString.js +1 -1
- package/src/geometries/geom2/transform.test.js +1 -1
- package/src/geometries/geom3/fromCompactBinary.js +1 -1
- package/src/geometries/geom3/index.js +17 -0
- package/src/geometries/geom3/invert.js +2 -2
- package/src/geometries/geom3/isA.js +2 -2
- package/src/geometries/geom3/toCompactBinary.js +4 -4
- package/src/geometries/geom3/toPoints.js +1 -0
- package/src/geometries/geom3/toString.js +1 -1
- package/src/geometries/geom3/transform.test.js +1 -1
- package/src/geometries/index.js +8 -1
- package/src/geometries/path2/eachPoint.js +3 -3
- package/src/geometries/path2/index.js +11 -0
- package/src/geometries/path2/isA.js +2 -2
- package/src/geometries/path2/reverse.js +4 -4
- package/src/geometries/path2/toCompactBinary.js +6 -6
- package/src/geometries/path2/toString.js +1 -1
- package/src/geometries/path2/transform.test.js +1 -1
- package/src/geometries/poly2/arePointsInside.test.js +1 -1
- package/src/geometries/poly2/index.js +6 -0
- package/src/geometries/poly3/index.js +7 -1
- package/src/geometries/poly3/invert.js +7 -1
- package/src/geometries/poly3/isA.js +2 -2
- package/src/geometries/poly3/isConvex.js +2 -2
- package/src/geometries/poly3/measureArea.js +4 -4
- package/src/geometries/poly3/measureBoundingBox.js +2 -2
- package/src/geometries/poly3/measureBoundingSphere.js +2 -2
- package/src/geometries/poly3/measureSignedVolume.js +4 -4
- package/src/geometries/poly3/toPoints.js +2 -2
- package/src/geometries/poly3/toString.js +2 -2
- package/src/geometries/poly3/transform.js +2 -2
- package/src/maths/index.js +1 -1
- package/src/maths/line2/equals.js +2 -2
- package/src/maths/line2/fromValues.js +2 -2
- package/src/maths/line2/intersectPointOfLines.js +1 -1
- package/src/maths/line2/intersectPointOfLines.test.js +1 -1
- package/src/maths/line2/reverse.test.js +1 -1
- package/src/maths/line2/transform.test.js +1 -1
- package/src/maths/line3/equals.js +2 -2
- package/src/maths/line3/reverse.test.js +1 -1
- package/src/maths/line3/transform.test.js +1 -1
- package/src/maths/mat4/fromRotation.js +1 -1
- package/src/maths/mat4/fromVectorRotation.js +1 -1
- package/src/maths/mat4/fromVectorRotation.test.js +1 -1
- package/src/maths/mat4/identity.test.js +1 -1
- package/src/maths/mat4/invert.js +18 -18
- package/src/maths/mat4/isIdentity.js +1 -1
- package/src/maths/mat4/isIdentity.test.js +0 -2
- package/src/maths/mat4/isMirroring.js +4 -4
- package/src/maths/mat4/isMirroring.test.js +1 -1
- package/src/maths/mat4/leftMultiplyVec3.js +2 -2
- package/src/maths/mat4/rotate.js +1 -1
- package/src/maths/mat4/toString.js +2 -2
- package/src/maths/mat4/translate.test.js +1 -1
- package/src/maths/plane/flip.test.js +1 -1
- package/src/maths/plane/fromPoints.d.ts +1 -1
- package/src/maths/plane/fromPoints.js +1 -3
- package/src/maths/plane/signedDistanceToPoint.js +1 -1
- package/src/maths/plane/transform.test.js +1 -1
- package/src/maths/utils/aboutEqualNormals.js +2 -2
- package/src/maths/vec2/abs.d.ts +1 -1
- package/src/maths/vec2/add.test.js +1 -1
- package/src/maths/vec2/angleDegrees.d.ts +1 -1
- package/src/maths/vec2/angleRadians.d.ts +1 -1
- package/src/maths/vec2/create.js +1 -1
- package/src/maths/vec2/cross.test.js +1 -1
- package/src/maths/vec2/divide.test.js +1 -1
- package/src/maths/vec2/fromAngleDegrees.js +1 -1
- package/src/maths/vec2/fromScalar.js +1 -1
- package/src/maths/vec2/length.d.ts +1 -1
- package/src/maths/vec2/length.js +1 -1
- package/src/maths/vec2/length.test.js +10 -0
- package/src/maths/vec2/lerp.test.js +1 -1
- package/src/maths/vec2/multiply.test.js +1 -1
- package/src/maths/vec2/negate.test.js +1 -1
- package/src/maths/vec2/normal.js +1 -1
- package/src/maths/vec2/normalize.d.ts +1 -1
- package/src/maths/vec2/normalize.test.js +1 -1
- package/src/maths/vec2/rotate.test.js +1 -1
- package/src/maths/vec2/squaredLength.d.ts +1 -1
- package/src/maths/vec2/squaredLength.js +3 -3
- package/src/maths/vec2/subtract.test.js +1 -1
- package/src/maths/vec2/toString.js +1 -1
- package/src/maths/vec2/transform.test.js +1 -1
- package/src/maths/vec3/abs.d.ts +1 -1
- package/src/maths/vec3/add.test.js +1 -1
- package/src/maths/vec3/angle.js +2 -2
- package/src/maths/vec3/angle.test.js +17 -0
- package/src/maths/vec3/cross.test.js +1 -1
- package/src/maths/vec3/divide.test.js +1 -1
- package/src/maths/vec3/fromScalar.js +1 -1
- package/src/maths/vec3/fromVec2.d.ts +1 -1
- package/src/maths/vec3/fromVec2.js +3 -3
- package/src/maths/vec3/length.d.ts +1 -1
- package/src/maths/vec3/length.js +4 -4
- package/src/maths/vec3/length.test.js +10 -0
- package/src/maths/vec3/lerp.test.js +1 -1
- package/src/maths/vec3/multiply.test.js +1 -1
- package/src/maths/vec3/negate.d.ts +1 -1
- package/src/maths/vec3/negate.test.js +1 -1
- package/src/maths/vec3/normalize.d.ts +1 -1
- package/src/maths/vec3/normalize.test.js +1 -1
- package/src/maths/vec3/rotateX.test.js +1 -1
- package/src/maths/vec3/rotateY.test.js +1 -1
- package/src/maths/vec3/rotateZ.test.js +1 -1
- package/src/maths/vec3/scale.test.js +1 -1
- package/src/maths/vec3/squaredLength.d.ts +1 -1
- package/src/maths/vec3/squaredLength.js +4 -4
- package/src/maths/vec3/subtract.test.js +1 -1
- package/src/maths/vec3/toString.js +1 -1
- package/src/maths/vec3/transform.test.js +1 -1
- package/src/maths/vec4/toString.js +1 -1
- package/src/maths/vec4/transform.test.js +1 -1
- package/src/measurements/measureBoundingSphere.js +4 -4
- package/src/measurements/measureCenterOfMass.js +1 -1
- package/src/operations/booleans/mayOverlap.js +3 -3
- package/src/operations/booleans/retessellate.js +3 -5
- package/src/operations/booleans/scission.js +1 -1
- package/src/operations/booleans/subtract.js +1 -1
- package/src/operations/booleans/union.test.js +1 -1
- package/src/operations/booleans/unionGeom3Sub.js +1 -1
- package/src/operations/expansions/expand.js +2 -2
- package/src/operations/expansions/expand.test.js +3 -35
- package/src/operations/expansions/expandShell.js +24 -18
- package/src/operations/expansions/offset.js +1 -1
- package/src/operations/expansions/offset.test.js +25 -89
- package/src/operations/expansions/offsetFromPoints.js +11 -6
- package/src/operations/extrusions/earcut/assignHoles.js +87 -0
- package/src/operations/extrusions/earcut/assignHoles.test.js +28 -0
- package/src/operations/extrusions/earcut/eliminateHoles.js +131 -0
- package/src/operations/extrusions/earcut/index.js +252 -0
- package/src/operations/extrusions/earcut/linkedList.js +58 -0
- package/src/operations/extrusions/earcut/linkedListSort.js +54 -0
- package/src/operations/extrusions/earcut/linkedPolygon.js +197 -0
- package/src/operations/extrusions/earcut/polygonHierarchy.js +64 -0
- package/src/operations/extrusions/earcut/triangle.js +16 -0
- package/src/operations/extrusions/extrudeFromSlices.js +10 -3
- package/src/operations/extrusions/extrudeFromSlices.test.js +33 -23
- package/src/operations/extrusions/extrudeLinear.js +11 -6
- package/src/operations/extrusions/extrudeLinear.test.js +77 -27
- package/src/operations/extrusions/extrudeLinearGeom2.js +5 -2
- package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
- package/src/operations/extrusions/extrudeRectangular.js +1 -1
- package/src/operations/extrusions/extrudeRectangular.test.js +7 -7
- package/src/operations/extrusions/extrudeRotate.test.js +19 -27
- package/src/operations/extrusions/project.js +1 -1
- package/src/operations/extrusions/slice/calculatePlane.js +7 -4
- package/src/operations/extrusions/slice/isA.js +2 -2
- package/src/operations/extrusions/slice/repairSlice.js +47 -0
- package/src/operations/extrusions/slice/toPolygons.js +24 -60
- package/src/operations/hulls/hull.test.js +1 -1
- package/src/operations/hulls/hullChain.js +1 -1
- package/src/operations/hulls/hullGeom2.js +1 -1
- package/src/operations/hulls/hullPath2.js +6 -4
- package/src/operations/hulls/hullPath2.test.js +16 -0
- package/src/operations/hulls/hullPoints2.test.js +1 -1
- package/src/operations/hulls/quickhull/QuickHull.js +2 -2
- package/src/operations/modifiers/edges.js +2 -4
- package/src/operations/modifiers/generalize.js +4 -7
- package/src/operations/modifiers/snap.test.js +3 -3
- package/src/operations/transforms/align.d.ts +1 -1
- package/src/operations/transforms/center.js +17 -17
- package/src/operations/transforms/mirror.js +11 -11
- package/src/operations/transforms/rotate.js +12 -12
- package/src/operations/transforms/scale.js +19 -19
- package/src/operations/transforms/transform.js +3 -3
- package/src/operations/transforms/translate.js +14 -14
- package/src/primitives/arc.js +1 -1
- package/src/primitives/cylinderElliptic.test.js +0 -2
- package/src/primitives/ellipsoid.js +1 -1
- package/src/primitives/ellipsoid.test.js +0 -2
- package/src/primitives/geodesicSphere.d.ts +0 -1
- package/src/primitives/geodesicSphere.js +2 -2
- package/src/primitives/polyhedron.js +1 -1
- package/src/primitives/roundedCylinder.js +1 -1
- package/src/primitives/torus.d.ts +0 -1
- package/src/primitives/torus.test.js +1 -1
- package/src/primitives/triangle.js +1 -1
- package/src/text/vectorText.js +2 -2
- package/src/utils/padArrayToLength.js +1 -1
- package/test/helpers/comparePolygons.js +1 -3
- package/test/helpers/nearlyEqual.js +2 -6
|
@@ -79,7 +79,7 @@ const geodesicSphere = (options) => {
|
|
|
79
79
|
|
|
80
80
|
// -- normalize
|
|
81
81
|
for (let k = 0; k < 3; k++) {
|
|
82
|
-
const r = Math.
|
|
82
|
+
const r = Math.hypot(q[k][0], q[k][1], q[k][2])
|
|
83
83
|
for (let l = 0; l < 3; l++) {
|
|
84
84
|
q[k][l] /= r
|
|
85
85
|
}
|
|
@@ -95,7 +95,7 @@ const geodesicSphere = (options) => {
|
|
|
95
95
|
|
|
96
96
|
// -- normalize
|
|
97
97
|
for (let k = 0; k < 3; k++) {
|
|
98
|
-
const r = Math.
|
|
98
|
+
const r = Math.hypot(q[k][0], q[k][1], q[k][2])
|
|
99
99
|
for (let l = 0; l < 3; l++) {
|
|
100
100
|
q[k][l] /= r
|
|
101
101
|
}
|
|
@@ -11,7 +11,7 @@ const { isNumberArray } = require('./commonChecks')
|
|
|
11
11
|
* @param {Array} options.points - list of points in 3D space
|
|
12
12
|
* @param {Array} options.faces - list of faces, where each face is a set of indexes into the points
|
|
13
13
|
* @param {Array} [options.colors=undefined] - list of RGBA colors to apply to each face
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {String} [options.orientation='outward'] - orientation of faces
|
|
15
15
|
* @returns {geom3} new 3D geometry
|
|
16
16
|
* @alias module:modeling/primitives.polyhedron
|
|
17
17
|
*
|
|
@@ -11,7 +11,7 @@ const { isGT, isGTE, isNumberArray } = require('./commonChecks')
|
|
|
11
11
|
* Construct a Z axis-aligned solid cylinder in three dimensional space with rounded ends.
|
|
12
12
|
* @param {Object} [options] - options for construction
|
|
13
13
|
* @param {Array} [options.center=[0,0,0]] - center of cylinder
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {Number} [options.height=2] - height of cylinder
|
|
15
15
|
* @param {Number} [options.radius=1] - radius of cylinder
|
|
16
16
|
* @param {Number} [options.roundRadius=0.2] - radius of rounded edges
|
|
17
17
|
* @param {Number} [options.segments=32] - number of segments to create per full rotation
|
|
@@ -30,7 +30,7 @@ test('torus (Simple options)', (t) => {
|
|
|
30
30
|
test('torus (complex options)', (t) => {
|
|
31
31
|
const obs = torus({ innerRadius: 1, outerRadius: 5, innerSegments: 32, outerSegments: 72, startAngle: Math.PI / 2, outerRotation: Math.PI / 2 })
|
|
32
32
|
const pts = geom3.toPoints(obs)
|
|
33
|
-
t.is(pts.length,
|
|
33
|
+
t.is(pts.length, 1212)
|
|
34
34
|
|
|
35
35
|
const bounds = measureBoundingBox(obs)
|
|
36
36
|
const expectedBounds = [[-6, 0, -1], [0, 6, 1]]
|
|
@@ -119,7 +119,7 @@ const createTriangle = (A, B, C, a, b, c) => {
|
|
|
119
119
|
* The triangle is always constructed CCW from the origin, [0, 0, 0].
|
|
120
120
|
* @see https://www.mathsisfun.com/algebra/trig-solving-triangles.html
|
|
121
121
|
* @param {Object} [options] - options for construction
|
|
122
|
-
* @param {String} [options.type='SSS' - type of triangle to construct; A ~ angle, S ~ side
|
|
122
|
+
* @param {String} [options.type='SSS'] - type of triangle to construct; A ~ angle, S ~ side
|
|
123
123
|
* @param {Array} [options.values=[1,1,1]] - angle (radians) of corners or length of sides
|
|
124
124
|
* @returns {geom2} new 2D geometry
|
|
125
125
|
* @alias module:modeling/primitives.triangle
|
package/src/text/vectorText.js
CHANGED
|
@@ -26,7 +26,7 @@ const translateLine = (options, line) => {
|
|
|
26
26
|
* @param {Float} [options.height=21] - font size (uppercase height)
|
|
27
27
|
* @param {Float} [options.lineSpacing=1.4] - line spacing expressed as a percentage of font size
|
|
28
28
|
* @param {Float} [options.letterSpacing=1] - extra letter spacing expressed as a percentage of font size
|
|
29
|
-
* @param {String} [options.align='left'] - multi-line text
|
|
29
|
+
* @param {String} [options.align='left'] - multi-line text alignment: left, center, right
|
|
30
30
|
* @param {Float} [options.extrudeOffset=0] - width of the extrusion that will be applied (manually) after the creation of the character
|
|
31
31
|
* @param {String} [options.input='?'] - ascii string (ignored/overwrited if provided as seconds parameter)
|
|
32
32
|
* @param {String} [text='?'] - ascii string
|
|
@@ -47,7 +47,7 @@ const vectorText = (options, text) => {
|
|
|
47
47
|
xOffset, yOffset, input, font, height, align, extrudeOffset, lineSpacing, letterSpacing
|
|
48
48
|
} = vectorParams(options, text)
|
|
49
49
|
let [x, y] = [xOffset, yOffset]
|
|
50
|
-
let
|
|
50
|
+
let i, il, char, vect, width, diff
|
|
51
51
|
let line = { width: 0, segments: [] }
|
|
52
52
|
const lines = []
|
|
53
53
|
let output = []
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param {Array} anArray - the source array to copy into the result.
|
|
4
4
|
* @param {*} padding - the value to add to the new array to reach the desired length.
|
|
5
5
|
* @param {Number} targetLength - The desired length of the return array.
|
|
6
|
-
* @returns {Array} an array of at least 'targetLength
|
|
6
|
+
* @returns {Array} an array of at least 'targetLength' length
|
|
7
7
|
* @alias module:modeling/utils.padArrayToLength
|
|
8
8
|
*/
|
|
9
9
|
const padArrayToLength = (anArray, padding, targetLength) => {
|
|
@@ -8,9 +8,7 @@ const compareVectors = require('./compareVectors')
|
|
|
8
8
|
*/
|
|
9
9
|
const comparePolygons = (poly1, poly2) => {
|
|
10
10
|
if (poly1.vertices.length === poly2.vertices.length) {
|
|
11
|
-
return poly1.vertices.reduce((valid, vertex, index) =>
|
|
12
|
-
return valid && compareVectors(poly1.vertices[index], poly2.vertices[index])
|
|
13
|
-
}, true)
|
|
11
|
+
return poly1.vertices.reduce((valid, vertex, index) => valid && compareVectors(poly1.vertices[index], poly2.vertices[index]), true)
|
|
14
12
|
}
|
|
15
13
|
return false
|
|
16
14
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Compare two numeric values for near equality.
|
|
2
2
|
// the given test is fails if the numeric values are outside the given epsilon
|
|
3
3
|
const nearlyEqual = (t, a, b, epsilon, failMessage) => {
|
|
4
|
-
// console.log('nearEqual(t,'+a+','+b+','+epsilon+')')
|
|
5
4
|
if (a === b) { // shortcut, also handles infinities and NaNs
|
|
6
5
|
return true
|
|
7
6
|
}
|
|
@@ -10,11 +9,9 @@ const nearlyEqual = (t, a, b, epsilon, failMessage) => {
|
|
|
10
9
|
const absB = Math.abs(b)
|
|
11
10
|
const diff = Math.abs(a - b)
|
|
12
11
|
if (Number.isNaN(diff)) {
|
|
13
|
-
|
|
12
|
+
failMessage = failMessage === undefined ? 'difference is not a number' : failMessage
|
|
13
|
+
t.fail(failMessage + '(' + a + ',' + b + ')')
|
|
14
14
|
}
|
|
15
|
-
// console.log(absA)
|
|
16
|
-
// console.log(absB)
|
|
17
|
-
// console.log(diff)
|
|
18
15
|
if (a === 0 || b === 0 || diff < Number.EPSILON) {
|
|
19
16
|
// a or b is zero or both are extremely close to it
|
|
20
17
|
// relative error is less meaningful here
|
|
@@ -25,7 +22,6 @@ const nearlyEqual = (t, a, b, epsilon, failMessage) => {
|
|
|
25
22
|
}
|
|
26
23
|
// use relative error
|
|
27
24
|
const relative = (diff / Math.min((absA + absB), Number.MAX_VALUE))
|
|
28
|
-
// console.log(relative)
|
|
29
25
|
if (relative > epsilon) {
|
|
30
26
|
failMessage = failMessage === undefined ? 'Numbers outside of epsilon' : failMessage
|
|
31
27
|
t.fail(failMessage + '(' + a + ',' + b + ')')
|