@jscad/modeling 2.7.2 → 2.8.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 +23 -0
- package/dist/jscad-modeling.min.js +136 -133
- package/package.json +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/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/isA.js +2 -2
- package/src/geometries/geom3/toCompactBinary.js +4 -4
- 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/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/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/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/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/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/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/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 +2 -2
- 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/extrudeLinear.js +6 -2
- package/src/operations/extrusions/extrudeLinear.test.js +25 -1
- package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
- package/src/operations/extrusions/extrudeRectangular.js +1 -1
- package/src/operations/extrusions/extrudeRectangular.test.js +2 -2
- package/src/operations/extrusions/project.js +1 -1
- package/src/operations/extrusions/slice/isA.js +2 -2
- package/src/operations/extrusions/slice/toPolygons.js +1 -1
- 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/modifiers/edges.js +1 -1
- package/src/operations/modifiers/generalize.js +1 -1
- 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 +12 -12
- 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/polyhedron.js +1 -1
- package/src/primitives/torus.d.ts +0 -1
- package/src/primitives/triangle.js +1 -1
- package/src/text/vectorText.js +2 -2
- package/src/utils/padArrayToLength.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/modeling",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Constructive Solid Geometry (CSG) Library for JSCAD",
|
|
5
5
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"nyc": "15.1.0",
|
|
61
61
|
"uglifyify": "5.0.2"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "92fb9c75eb070fca5f5ee8c2bab6614b1f54514e"
|
|
64
64
|
}
|
|
@@ -20,7 +20,7 @@ test('quadratic bezier (3 control points)', (t) => {
|
|
|
20
20
|
t.is(bezier.tangentAt(1, OneDCurve), 20)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
test('quadratic bezier (3 control points, non
|
|
23
|
+
test('quadratic bezier (3 control points, non symmetric)', (t) => {
|
|
24
24
|
const OneDCurve = bezier.create([0, 0, 20])
|
|
25
25
|
t.is(bezier.tangentAt(0, OneDCurve), 0)
|
|
26
26
|
t.is(bezier.tangentAt(0.5, OneDCurve), 20)
|
|
@@ -20,7 +20,7 @@ test('quadratic bezier (3 control points)', (t) => {
|
|
|
20
20
|
t.is(bezier.valueAt(1, OneDCurve), 20)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
test('quadratic bezier (3 control points, non
|
|
23
|
+
test('quadratic bezier (3 control points, non symmetric)', (t) => {
|
|
24
24
|
const OneDCurve = bezier.create([0, 0, 20])
|
|
25
25
|
t.is(bezier.valueAt(0, OneDCurve), 0)
|
|
26
26
|
t.is(bezier.valueAt(0.5, OneDCurve), 5)
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
* Represents a 2D geometry consisting of a list of sides.
|
|
3
3
|
* @see {@link geom2} for data structure information.
|
|
4
4
|
* @module modeling/geometries/geom2
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* colorize([0.5,0,1,1], square()) // purple square
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* {
|
|
11
|
+
* "sides": [[[-1,1],[-1,-1]],[[-1,-1],[1,-1]],[[1,-1],[1,1]],[[1,1],[-1,1]]],
|
|
12
|
+
* "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
|
|
13
|
+
* "color": [0.5,0,1,1]
|
|
14
|
+
* }
|
|
5
15
|
*/
|
|
6
16
|
module.exports = {
|
|
7
17
|
clone: require('./clone'),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {Object} object - the object to
|
|
2
|
+
* Determine if the given object is a 2D geometry.
|
|
3
|
+
* @param {Object} object - the object to interrogate
|
|
4
4
|
* @returns {Boolean} true, if the object matches a geom2 based object
|
|
5
5
|
* @alias module:modeling/geometries/geom2.isA
|
|
6
6
|
*/
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @returns {TypedArray} compact binary representation
|
|
5
5
|
* @alias module:modeling/geometries/geom2.toCompactBinary
|
|
6
6
|
*/
|
|
7
|
-
const toCompactBinary = (
|
|
8
|
-
const sides =
|
|
9
|
-
const transforms =
|
|
7
|
+
const toCompactBinary = (geometry) => {
|
|
8
|
+
const sides = geometry.sides
|
|
9
|
+
const transforms = geometry.transforms
|
|
10
10
|
let color = [-1, -1, -1, -1]
|
|
11
|
-
if (
|
|
11
|
+
if (geometry.color) color = geometry.color
|
|
12
12
|
|
|
13
13
|
// FIXME why Float32Array?
|
|
14
14
|
const compacted = new Float32Array(1 + 16 + 4 + (sides.length * 4)) // type + transforms + color + sides data
|
|
@@ -5,7 +5,7 @@ const toSides = require('./toSides')
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a string representing the contents of the given geometry.
|
|
7
7
|
* @param {geom2} geometry - the geometry
|
|
8
|
-
* @returns {String} a
|
|
8
|
+
* @returns {String} a representative string
|
|
9
9
|
* @alias module:modeling/geometries/geom2.toString
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
@@ -11,7 +11,7 @@ test('transform: adjusts the transforms of geom2', (t) => {
|
|
|
11
11
|
const rotation = 90 * 0.017453292519943295
|
|
12
12
|
const rotate90 = mat4.fromZRotation(mat4.create(), rotation)
|
|
13
13
|
|
|
14
|
-
// continue with typical user scenario, several
|
|
14
|
+
// continue with typical user scenario, several iterations of transforms and access
|
|
15
15
|
|
|
16
16
|
// expect lazy transform, i.e. only the transforms change
|
|
17
17
|
const expected = {
|
|
@@ -33,7 +33,7 @@ const fromCompactBinary = (data) => {
|
|
|
33
33
|
created.polygons.push(poly3.create(vertices))
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// transfer known
|
|
36
|
+
// transfer known properties, i.e. color
|
|
37
37
|
if (data[17] >= 0) {
|
|
38
38
|
created.color = [data[17], data[18], data[19], data[20]]
|
|
39
39
|
}
|
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
* Represents a 3D geometry consisting of a list of polygons.
|
|
3
3
|
* @see {@link geom3} for data structure information.
|
|
4
4
|
* @module modeling/geometries/geom3
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* colorize([0,0.5,1,0.6], cube()) // transparent ice cube
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* {
|
|
11
|
+
* "polygons": [
|
|
12
|
+
* {"vertices": [[-1,-1,-1], [-1,-1,1], [-1,1,1], [-1,1,-1]]},
|
|
13
|
+
* {"vertices": [[1,-1,-1], [1,1,-1], [1,1,1], [1,-1,1]]},
|
|
14
|
+
* {"vertices": [[-1,-1,-1], [1,-1,-1], [1,-1,1], [-1,-1,1]]},
|
|
15
|
+
* {"vertices": [[-1,1,-1], [-1,1,1], [1,1,1], [1,1,-1]]},
|
|
16
|
+
* {"vertices": [[-1,-1,-1], [-1,1,-1], [1,1,-1], [1,-1,-1]]},
|
|
17
|
+
* {"vertices": [[-1,-1,1], [1,-1,1], [1,1,1], [-1,1,1]]}
|
|
18
|
+
* ],
|
|
19
|
+
* "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
|
|
20
|
+
* "color": [0,0.5,1,0.6]
|
|
21
|
+
* }
|
|
5
22
|
*/
|
|
6
23
|
module.exports = {
|
|
7
24
|
clone: require('./clone'),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {object} object - the object to
|
|
2
|
+
* Determine if the given object is a 3D geometry.
|
|
3
|
+
* @param {object} object - the object to interrogate
|
|
4
4
|
* @returns {Boolean} true if the object matches a geom3
|
|
5
5
|
* @alias module:modeling/geometries/geom3.isA
|
|
6
6
|
*/
|
|
@@ -6,14 +6,14 @@ const poly3 = require('../poly3')
|
|
|
6
6
|
* @return {TypedArray} compact binary representation
|
|
7
7
|
* @alias module:modeling/geometries/geom3.toCompactBinary
|
|
8
8
|
*/
|
|
9
|
-
const toCompactBinary = (
|
|
10
|
-
const polygons =
|
|
11
|
-
const transforms =
|
|
9
|
+
const toCompactBinary = (geometry) => {
|
|
10
|
+
const polygons = geometry.polygons
|
|
11
|
+
const transforms = geometry.transforms
|
|
12
12
|
|
|
13
13
|
const numberOfPolygons = polygons.length
|
|
14
14
|
const numberOfVertices = polygons.reduce((count, polygon) => count + polygon.vertices.length, 0)
|
|
15
15
|
let color = [-1, -1, -1, -1]
|
|
16
|
-
if (
|
|
16
|
+
if (geometry.color) color = geometry.color
|
|
17
17
|
|
|
18
18
|
// FIXME why Float32Array?
|
|
19
19
|
const compacted = new Float32Array(1 + 16 + 4 + 1 + numberOfPolygons + (numberOfVertices * 3))
|
|
@@ -5,7 +5,7 @@ const toPolygons = require('./toPolygons')
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a string representing the contents of the given geometry.
|
|
7
7
|
* @param {geom3} geometry - the geometry
|
|
8
|
-
* @returns {String} a
|
|
8
|
+
* @returns {String} a representative string
|
|
9
9
|
* @alias module:modeling/geometries/geom3.toString
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
@@ -11,7 +11,7 @@ test('transform: Adjusts the transforms of a populated geom3', (t) => {
|
|
|
11
11
|
const rotation = 90 * 0.017453292519943295
|
|
12
12
|
const rotate90 = mat4.fromZRotation(mat4.create(), rotation)
|
|
13
13
|
|
|
14
|
-
// continue with typical user scenario, several
|
|
14
|
+
// continue with typical user scenario, several iterations of transforms and access
|
|
15
15
|
|
|
16
16
|
// expect lazy transform, i.e. only the transforms change
|
|
17
17
|
const expected = {
|
package/src/geometries/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Geometries are objects that represent the contents of primitives or the results of operations.
|
|
3
|
-
* Note: Geometries are
|
|
3
|
+
* Note: Geometries are considered immutable, so never change the contents directly.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link geom2} - 2D geometry consisting of sides
|
|
6
|
+
* @see {@link geom3} - 3D geometry consisting of polygons
|
|
7
|
+
* @see {@link path2} - 2D geometry consisting of ordered points
|
|
8
|
+
* @see {@link poly2} - 2D polygon consisting of ordered vertices
|
|
9
|
+
* @see {@link poly3} - 3D polygon consisting of ordered vertices
|
|
10
|
+
*
|
|
4
11
|
* @module modeling/geometries
|
|
5
12
|
* @example
|
|
6
13
|
* const { geom2, geom3, path2, poly2, poly3 } = require('@jscad/modeling').geometries
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const toPoints = require('./toPoints')
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Calls a function for each point in the
|
|
4
|
+
* Calls a function for each point in the path.
|
|
5
5
|
* @param {Object} options - options
|
|
6
6
|
* @param {Function} thunk - the function to call
|
|
7
|
-
* @param {path2}
|
|
7
|
+
* @param {path2} path - the path to traverse
|
|
8
8
|
* @alias module:modeling/geometries/path2.eachPoint
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
|
-
* eachPoint({}, accumulate,
|
|
11
|
+
* eachPoint({}, accumulate, path)
|
|
12
12
|
*/
|
|
13
13
|
const eachPoint = (options, thunk, path) => {
|
|
14
14
|
toPoints(path).forEach(thunk)
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
* Represents a 2D geometry consisting of a list of ordered points.
|
|
3
3
|
* @see {@link path2} for data structure information.
|
|
4
4
|
* @module modeling/geometries/path2
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* colorize([0,0,0,1], path2.fromPoints({ closed: true }, [[0,0], [4,0], [4,3]]))
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* {
|
|
11
|
+
* "points": [[0,0], [4,0], [4,3]],
|
|
12
|
+
* "isClosed": true,
|
|
13
|
+
* "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
|
|
14
|
+
* "color": [0,0,0,1]
|
|
15
|
+
* }
|
|
5
16
|
*/
|
|
6
17
|
module.exports = {
|
|
7
18
|
appendArc: require('./appendArc'),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {Object} object - the object to
|
|
2
|
+
* Determine if the given object is a path2 geometry.
|
|
3
|
+
* @param {Object} object - the object to interrogate
|
|
4
4
|
* @returns {Boolean} true if the object matches a path2
|
|
5
5
|
* @alias module:modeling/geometries/path2.isA
|
|
6
6
|
*/
|
|
@@ -3,17 +3,17 @@ const clone = require('./clone')
|
|
|
3
3
|
/**
|
|
4
4
|
* Reverses the path so that the points are in the opposite order.
|
|
5
5
|
* This swaps the left (interior) and right (exterior) edges.
|
|
6
|
-
* @param {path2} geometry - the
|
|
6
|
+
* @param {path2} geometry - the path to reverse
|
|
7
7
|
* @returns {path2} a new path
|
|
8
8
|
* @alias module:modeling/geometries/path2.reverse
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* let newpath = reverse(mypath)
|
|
12
12
|
*/
|
|
13
|
-
const reverse = (
|
|
13
|
+
const reverse = (geometry) => {
|
|
14
14
|
// NOTE: this only updates the order of the points
|
|
15
|
-
const cloned = clone(
|
|
16
|
-
cloned.points =
|
|
15
|
+
const cloned = clone(geometry)
|
|
16
|
+
cloned.points = geometry.points.slice().reverse()
|
|
17
17
|
return cloned
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Produce a compact binary representation from the given path.
|
|
3
|
-
* @param {path2} geometry - the path
|
|
3
|
+
* @param {path2} geometry - the path geometry
|
|
4
4
|
* @returns {TypedArray} compact binary representation
|
|
5
5
|
* @alias module:modeling/geometries/path2.toCompactBinary
|
|
6
6
|
*/
|
|
7
|
-
const toCompactBinary = (
|
|
8
|
-
const points =
|
|
9
|
-
const transforms =
|
|
7
|
+
const toCompactBinary = (geometry) => {
|
|
8
|
+
const points = geometry.points
|
|
9
|
+
const transforms = geometry.transforms
|
|
10
10
|
let color = [-1, -1, -1, -1]
|
|
11
|
-
if (
|
|
11
|
+
if (geometry.color) color = geometry.color
|
|
12
12
|
|
|
13
13
|
// FIXME why Float32Array?
|
|
14
14
|
const compacted = new Float32Array(1 + 16 + 1 + 4 + (points.length * 2)) // type + transforms + isClosed + color + points data
|
|
@@ -32,7 +32,7 @@ const toCompactBinary = (geom) => {
|
|
|
32
32
|
compacted[15] = transforms[14]
|
|
33
33
|
compacted[16] = transforms[15]
|
|
34
34
|
|
|
35
|
-
compacted[17] =
|
|
35
|
+
compacted[17] = geometry.isClosed ? 1 : 0
|
|
36
36
|
|
|
37
37
|
compacted[18] = color[0]
|
|
38
38
|
compacted[19] = color[1]
|
|
@@ -5,7 +5,7 @@ const toPoints = require('./toPoints')
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a string representing the contents of the given path.
|
|
7
7
|
* @param {path2} geometry - the path
|
|
8
|
-
* @returns {String} a
|
|
8
|
+
* @returns {String} a representative string
|
|
9
9
|
* @alias module:modeling/geometries/path2.toString
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
@@ -11,7 +11,7 @@ test('transform: adjusts the transforms of path', (t) => {
|
|
|
11
11
|
const rotation = 90 * 0.017453292519943295
|
|
12
12
|
const rotate90 = mat4.fromZRotation(mat4.create(), rotation)
|
|
13
13
|
|
|
14
|
-
// continue with typical user scenario, several
|
|
14
|
+
// continue with typical user scenario, several iterations of transforms and access
|
|
15
15
|
|
|
16
16
|
// expect lazy transform, i.e. only the transforms change
|
|
17
17
|
const expected = {
|
|
@@ -12,7 +12,7 @@ test('poly2: arePointsInside() should return proper values', (t) => {
|
|
|
12
12
|
t.is(obs, 0)
|
|
13
13
|
|
|
14
14
|
polygon = create([[0, 0], [5, 0], [5, 5], [0, 5]])
|
|
15
|
-
// points
|
|
15
|
+
// points overlapping points
|
|
16
16
|
obs = arePointsInside([[0, 0]], polygon)
|
|
17
17
|
t.is(obs, 0)
|
|
18
18
|
obs = arePointsInside([[5, 0]], polygon)
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
* Represents a 2D polygon consisting of a list of ordered vertices.
|
|
3
3
|
* @see {@link poly2} for data structure information.
|
|
4
4
|
* @module modeling/geometries/poly2
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* poly2.create([[0,0], [4,0], [4,3]])
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* {"vertices": [[0,0], [4,0], [4,3]]}
|
|
5
11
|
*/
|
|
6
12
|
module.exports = {
|
|
7
13
|
arePointsInside: require('./arePointsInside'),
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Represents a convex 3D polygon consisting of a list of vertices.
|
|
2
|
+
* Represents a convex 3D polygon consisting of a list of ordered vertices.
|
|
3
3
|
* @see {@link poly3} for data structure information.
|
|
4
4
|
* @module modeling/geometries/poly3
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* poly3.create([[0,0,0], [4,0,0], [4,3,12]])
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* {"vertices": [[0,0,0], [4,0,0], [4,3,12]]}
|
|
5
11
|
*/
|
|
6
12
|
module.exports = {
|
|
7
13
|
clone: require('./clone'),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {Object} object - the object to
|
|
2
|
+
* Determine if the given object is a polygon.
|
|
3
|
+
* @param {Object} object - the object to interrogate
|
|
4
4
|
* @returns {Boolean} true if the object matches a poly3
|
|
5
5
|
* @alias module:modeling/geometries/poly3.isA
|
|
6
6
|
*/
|
|
@@ -3,11 +3,11 @@ const vec3 = require('../../maths/vec3')
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Check whether the given polygon is convex.
|
|
6
|
-
* @param {poly3} polygon - the polygon to
|
|
6
|
+
* @param {poly3} polygon - the polygon to interrogate
|
|
7
7
|
* @returns {Boolean} true if convex
|
|
8
8
|
* @alias module:modeling/geometries/poly3.isConvex
|
|
9
9
|
*/
|
|
10
|
-
const isConvex = (
|
|
10
|
+
const isConvex = (polygon) => areVerticesConvex(polygon.vertices)
|
|
11
11
|
|
|
12
12
|
const areVerticesConvex = (vertices) => {
|
|
13
13
|
const numvertices = vertices.length
|
|
@@ -7,15 +7,15 @@ const plane = require('./plane')
|
|
|
7
7
|
* @return {Number} area of the polygon
|
|
8
8
|
* @alias module:modeling/geometries/poly3.measureArea
|
|
9
9
|
*/
|
|
10
|
-
const measureArea = (
|
|
11
|
-
const n =
|
|
10
|
+
const measureArea = (polygon) => {
|
|
11
|
+
const n = polygon.vertices.length
|
|
12
12
|
if (n < 3) {
|
|
13
13
|
return 0 // degenerate polygon
|
|
14
14
|
}
|
|
15
|
-
const vertices =
|
|
15
|
+
const vertices = polygon.vertices
|
|
16
16
|
|
|
17
17
|
// calculate a normal vector
|
|
18
|
-
const normal = plane(
|
|
18
|
+
const normal = plane(polygon)
|
|
19
19
|
|
|
20
20
|
// determine direction of projection
|
|
21
21
|
const ax = Math.abs(normal[0])
|
|
@@ -5,8 +5,8 @@ const vec3 = require('../../maths/vec3')
|
|
|
5
5
|
* @returns {Array} an array of two vectors (3D); minimum and maximum coordinates
|
|
6
6
|
* @alias module:modeling/geometries/poly3.measureBoundingBox
|
|
7
7
|
*/
|
|
8
|
-
const measureBoundingBox = (
|
|
9
|
-
const vertices =
|
|
8
|
+
const measureBoundingBox = (polygon) => {
|
|
9
|
+
const vertices = polygon.vertices
|
|
10
10
|
const numvertices = vertices.length
|
|
11
11
|
const min = numvertices === 0 ? vec3.create() : vec3.clone(vertices[0])
|
|
12
12
|
const max = vec3.clone(min)
|
|
@@ -7,8 +7,8 @@ const measureBoundingBox = require('./measureBoundingBox')
|
|
|
7
7
|
* @returns {Array} the computed bounding sphere; center point (3D) and radius
|
|
8
8
|
* @alias module:modeling/geometries/poly3.measureBoundingSphere
|
|
9
9
|
*/
|
|
10
|
-
const measureBoundingSphere = (
|
|
11
|
-
const box = measureBoundingBox(
|
|
10
|
+
const measureBoundingSphere = (polygon) => {
|
|
11
|
+
const box = measureBoundingBox(polygon)
|
|
12
12
|
const center = box[0]
|
|
13
13
|
vec3.add(center, box[0], box[1])
|
|
14
14
|
vec3.scale(center, center, 0.5)
|
|
@@ -2,17 +2,17 @@ const vec3 = require('../../maths/vec3')
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Measure the signed volume of the given polygon, which must be convex.
|
|
5
|
-
* The volume is that formed by the
|
|
5
|
+
* The volume is that formed by the tetrahedron connected to the axis [0,0,0],
|
|
6
6
|
* and will be positive or negative based on the rotation of the vertices.
|
|
7
7
|
* @see http://chenlab.ece.cornell.edu/Publication/Cha/icip01_Cha.pdf
|
|
8
8
|
* @param {poly3} polygon - the polygon to measure
|
|
9
9
|
* @return {Number} volume of the polygon
|
|
10
10
|
* @alias module:modeling/geometries/poly3.measureSignedVolume
|
|
11
11
|
*/
|
|
12
|
-
const measureSignedVolume = (
|
|
12
|
+
const measureSignedVolume = (polygon) => {
|
|
13
13
|
let signedVolume = 0
|
|
14
|
-
const vertices =
|
|
15
|
-
// calculate based on
|
|
14
|
+
const vertices = polygon.vertices
|
|
15
|
+
// calculate based on triangular polygons
|
|
16
16
|
const cross = vec3.create()
|
|
17
17
|
for (let i = 0; i < vertices.length - 2; i++) {
|
|
18
18
|
vec3.cross(cross, vertices[i + 1], vertices[i + 2])
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Return the given
|
|
2
|
+
* Return the given polygon as a list of points.
|
|
3
3
|
* NOTE: The returned array should not be modified as the points are shared with the geometry.
|
|
4
4
|
* @param {poly3} polygon - the polygon
|
|
5
5
|
* @return {Array} list of points (3D)
|
|
6
6
|
* @alias module:modeling/geometries/poly3.toPoints
|
|
7
7
|
*/
|
|
8
|
-
const toPoints = (
|
|
8
|
+
const toPoints = (polygon) => polygon.vertices
|
|
9
9
|
|
|
10
10
|
module.exports = toPoints
|
|
@@ -5,9 +5,9 @@ const vec3 = require('../../maths/vec3/')
|
|
|
5
5
|
* @return {String} the string representation
|
|
6
6
|
* @alias module:modeling/geometries/poly3.toString
|
|
7
7
|
*/
|
|
8
|
-
const toString = (
|
|
8
|
+
const toString = (polygon) => {
|
|
9
9
|
let result = 'poly3: vertices: ['
|
|
10
|
-
|
|
10
|
+
polygon.vertices.forEach((vertex) => {
|
|
11
11
|
result += `${vec3.toString(vertex)}, `
|
|
12
12
|
})
|
|
13
13
|
result += ']'
|
|
@@ -10,8 +10,8 @@ const create = require('./create')
|
|
|
10
10
|
* @returns {poly3} a new polygon
|
|
11
11
|
* @alias module:modeling/geometries/poly3.transform
|
|
12
12
|
*/
|
|
13
|
-
const transform = (matrix,
|
|
14
|
-
const vertices =
|
|
13
|
+
const transform = (matrix, polygon) => {
|
|
14
|
+
const vertices = polygon.vertices.map((vertex) => vec3.transform(vec3.create(), vertex, matrix))
|
|
15
15
|
if (mat4.isMirroring(matrix)) {
|
|
16
16
|
// reverse the order to preserve the orientation
|
|
17
17
|
vertices.reverse()
|
package/src/maths/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Maths are computational units for fundamental Euclidean geometry. All maths operate upon array data structures.
|
|
3
|
-
* Note: Maths data
|
|
3
|
+
* Note: Maths data structures are considered immutable, so never change the contents directly.
|
|
4
4
|
* @see Most computations are based upon the glMatrix library (glmatrix.net)
|
|
5
5
|
* @module modeling/maths
|
|
6
6
|
* @example
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compare the given lines for equality.
|
|
3
3
|
*
|
|
4
|
-
* @param {line2}
|
|
5
|
-
* @param {line2}
|
|
4
|
+
* @param {line2} line1 - first line to compare
|
|
5
|
+
* @param {line2} line2 - second line to compare
|
|
6
6
|
* @return {Boolean} true if lines are equal
|
|
7
7
|
* @alias module:modeling/maths/line2.equals
|
|
8
8
|
*/
|
|
@@ -9,11 +9,11 @@ const create = require('./create')
|
|
|
9
9
|
* @returns {line2} a new unbounded line
|
|
10
10
|
* @alias module:modeling/maths/line2.fromValues
|
|
11
11
|
*/
|
|
12
|
-
const fromValues = (x, y,
|
|
12
|
+
const fromValues = (x, y, d) => {
|
|
13
13
|
const out = create()
|
|
14
14
|
out[0] = x
|
|
15
15
|
out[1] = y
|
|
16
|
-
out[2] =
|
|
16
|
+
out[2] = d
|
|
17
17
|
return out
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -5,7 +5,7 @@ const { solve2Linear } = require('../utils')
|
|
|
5
5
|
* Return the point of intersection between the given lines.
|
|
6
6
|
*
|
|
7
7
|
* NOTES:
|
|
8
|
-
* The point will have Infinity values if the lines are
|
|
8
|
+
* The point will have Infinity values if the lines are parallel.
|
|
9
9
|
* The point will have NaN values if the lines are the same.
|
|
10
10
|
*
|
|
11
11
|
* @param {line2} line1 - line of reference
|
|
@@ -15,7 +15,7 @@ test('line2: intersectPointOfLines() should return proper points', (t) => {
|
|
|
15
15
|
const int3 = intersectPointOfLines(line3, line2)
|
|
16
16
|
t.true(compareVectors(int3, [NaN, NaN]))
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// parallel lines
|
|
19
19
|
const line4 = fromPoints(create(), [0, 6], [6, 0])
|
|
20
20
|
const int4 = intersectPointOfLines(line4, line3)
|
|
21
21
|
t.true(compareVectors(int4, [Infinity, -Infinity]))
|
|
@@ -3,7 +3,7 @@ const { reverse, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line2: reverse() called with two
|
|
6
|
+
test('line2: reverse() called with two parameters should update a line2 with proper values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const obs1 = create()
|
|
9
9
|
const ret1 = reverse(obs1, line1)
|
|
@@ -3,7 +3,7 @@ const { transform, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line2: transform() called with three
|
|
6
|
+
test('line2: transform() called with three parameters should update a line2 with correct values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const line2 = fromPoints(create(), [0, 0], [0, 1])
|
|
9
9
|
const line3 = fromPoints(create(), [-3, -3], [3, 3])
|
|
@@ -3,8 +3,8 @@ const vec3 = require('../vec3')
|
|
|
3
3
|
/**
|
|
4
4
|
* Compare the given lines for equality.
|
|
5
5
|
*
|
|
6
|
-
* @param {line3}
|
|
7
|
-
* @param {line3}
|
|
6
|
+
* @param {line3} line1 - first line to compare
|
|
7
|
+
* @param {line3} line2 - second line to compare
|
|
8
8
|
* @return {Boolean} true if lines are equal
|
|
9
9
|
* @alias module:modeling/maths/line3.equals
|
|
10
10
|
*/
|
|
@@ -3,7 +3,7 @@ const { reverse, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line3: reverse() called with two
|
|
6
|
+
test('line3: reverse() called with two parameters should update a line3 with proper values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const out = create()
|
|
9
9
|
let rev = reverse(out, line1)
|
|
@@ -3,7 +3,7 @@ const { transform, create, fromPoints } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('line3: transform() called with three
|
|
6
|
+
test('line3: transform() called with three parameters should update a line3 with correct values', (t) => {
|
|
7
7
|
const line1 = create()
|
|
8
8
|
const line2 = fromPoints(create(), [1, 0, 0], [0, 1, 0])
|
|
9
9
|
const line3 = fromPoints(create(), [-3, -3, -3], [3, 3, 3])
|
|
@@ -5,7 +5,7 @@ const fromRotation = require('./fromRotation')
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a matrix that rotates the given source to the given target vector.
|
|
7
7
|
*
|
|
8
|
-
* Each vector must be a directional vector with a length greater
|
|
8
|
+
* Each vector must be a directional vector with a length greater than zero.
|
|
9
9
|
* @see https://gist.github.com/kevinmoran/b45980723e53edeb8a5a43c49f134724
|
|
10
10
|
* @param {mat4} out - receiving matrix
|
|
11
11
|
* @param {vec3} source - source vector
|
|
@@ -96,7 +96,7 @@ test('mat4: fromVectorRotation() called with out parameter should return a mat4
|
|
|
96
96
|
t.is(ret, out)
|
|
97
97
|
t.true(compareVectors(out, [1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1]))
|
|
98
98
|
|
|
99
|
-
//
|
|
99
|
+
// different units
|
|
100
100
|
ret = fromVectorRotation(out, [11, 0, 0], [0, 33, 0])
|
|
101
101
|
t.is(ret, out)
|
|
102
102
|
t.true(compareVectors(out, [0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))
|
|
@@ -3,7 +3,7 @@ const { identity } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('mat4: identity() called with one
|
|
6
|
+
test('mat4: identity() called with one parameters should update a mat4 with correct values', (t) => {
|
|
7
7
|
const obs1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
8
8
|
const ret1 = identity(obs1)
|
|
9
9
|
t.true(compareVectors(obs1, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))
|