@jscad/modeling 2.7.2 → 2.9.1
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 +48 -0
- package/dist/jscad-modeling.min.js +443 -398
- 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.d.ts +1 -0
- package/src/geometries/geom2/index.js +12 -1
- 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/geom2/validate.d.ts +3 -0
- package/src/geometries/geom2/validate.js +36 -0
- package/src/geometries/geom3/fromCompactBinary.js +1 -1
- package/src/geometries/geom3/index.d.ts +1 -0
- package/src/geometries/geom3/index.js +19 -1
- 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/geom3/validate.d.ts +3 -0
- package/src/geometries/geom3/validate.js +62 -0
- package/src/geometries/index.js +8 -1
- package/src/geometries/path2/eachPoint.js +3 -3
- package/src/geometries/path2/index.d.ts +1 -0
- package/src/geometries/path2/index.js +13 -1
- 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/path2/validate.d.ts +3 -0
- package/src/geometries/path2/validate.js +41 -0
- package/src/geometries/poly2/arePointsInside.js +0 -35
- package/src/geometries/poly2/arePointsInside.test.js +1 -1
- package/src/geometries/poly2/index.js +6 -0
- package/src/geometries/poly3/index.d.ts +1 -0
- package/src/geometries/poly3/index.js +9 -2
- 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/measureArea.test.js +16 -16
- package/src/geometries/poly3/measureBoundingBox.js +2 -2
- package/src/geometries/poly3/measureBoundingSphere.js +2 -2
- package/src/geometries/poly3/measureBoundingSphere.test.js +8 -8
- 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/geometries/poly3/validate.d.ts +4 -0
- package/src/geometries/poly3/validate.js +50 -0
- 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/measurements/measureCenterOfMass.test.js +2 -2
- package/src/operations/booleans/intersect.test.js +8 -0
- 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/scission.test.js +4 -4
- package/src/operations/booleans/subtract.js +1 -1
- package/src/operations/booleans/subtract.test.js +8 -0
- package/src/operations/booleans/trees/Node.js +10 -16
- package/src/operations/booleans/trees/PolygonTreeNode.js +13 -14
- package/src/operations/booleans/trees/Tree.js +1 -2
- package/src/operations/booleans/trees/splitPolygonByPlane.js +2 -3
- package/src/operations/booleans/union.test.js +28 -1
- package/src/operations/booleans/unionGeom3Sub.js +1 -1
- package/src/operations/expansions/expand.js +2 -2
- package/src/operations/expansions/expand.test.js +32 -55
- package/src/operations/expansions/expandShell.js +24 -18
- package/src/operations/expansions/offset.js +1 -1
- package/src/operations/expansions/offset.test.js +50 -89
- package/src/operations/expansions/offsetFromPoints.js +11 -6
- package/src/operations/extrusions/earcut/assignHoles.js +91 -0
- package/src/operations/extrusions/earcut/assignHoles.test.js +74 -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 +47 -31
- package/src/operations/extrusions/extrudeLinear.js +10 -5
- package/src/operations/extrusions/extrudeLinear.test.js +91 -35
- 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 +22 -15
- package/src/operations/extrusions/extrudeRotate.test.js +31 -27
- package/src/operations/extrusions/project.js +1 -1
- package/src/operations/extrusions/project.test.js +5 -5
- 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 +25 -2
- package/src/operations/hulls/hullChain.js +1 -1
- package/src/operations/hulls/hullChain.test.js +6 -4
- 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/generalize.test.js +6 -0
- package/src/operations/modifiers/snap.test.js +3 -3
- package/src/operations/transforms/align.d.ts +1 -1
- package/src/operations/transforms/align.test.js +12 -0
- package/src/operations/transforms/center.js +17 -17
- package/src/operations/transforms/center.test.js +12 -0
- package/src/operations/transforms/mirror.js +12 -12
- package/src/operations/transforms/mirror.test.js +16 -0
- package/src/operations/transforms/rotate.js +12 -12
- package/src/operations/transforms/rotate.test.js +10 -0
- package/src/operations/transforms/scale.js +19 -19
- package/src/operations/transforms/scale.test.js +15 -0
- package/src/operations/transforms/transform.js +3 -3
- package/src/operations/transforms/transform.test.js +5 -0
- package/src/operations/transforms/translate.js +14 -14
- package/src/operations/transforms/translate.test.js +16 -0
- package/src/primitives/arc.js +1 -1
- package/src/primitives/arc.test.js +11 -0
- package/src/primitives/circle.test.js +15 -9
- package/src/primitives/cube.test.js +3 -0
- package/src/primitives/cuboid.test.js +9 -24
- package/src/primitives/cylinder.test.js +7 -4
- package/src/primitives/cylinderElliptic.js +13 -6
- package/src/primitives/cylinderElliptic.test.js +72 -52
- package/src/primitives/ellipse.js +3 -1
- package/src/primitives/ellipse.test.js +14 -8
- package/src/primitives/ellipsoid.js +7 -5
- package/src/primitives/ellipsoid.test.js +84 -82
- package/src/primitives/geodesicSphere.d.ts +0 -1
- package/src/primitives/geodesicSphere.test.js +3 -0
- package/src/primitives/line.test.js +1 -0
- package/src/primitives/polygon.test.js +15 -10
- package/src/primitives/polyhedron.js +1 -1
- package/src/primitives/polyhedron.test.js +14 -42
- package/src/primitives/rectangle.test.js +3 -0
- package/src/primitives/roundedCuboid.test.js +5 -0
- package/src/primitives/roundedCylinder.js +6 -4
- package/src/primitives/roundedCylinder.test.js +40 -36
- package/src/primitives/roundedRectangle.test.js +5 -0
- package/src/primitives/sphere.test.js +52 -73
- package/src/primitives/square.test.js +3 -0
- package/src/primitives/star.test.js +6 -0
- package/src/primitives/torus.d.ts +0 -1
- package/src/primitives/torus.test.js +8 -1
- package/src/primitives/triangle.js +1 -1
- package/src/primitives/triangle.test.js +7 -0
- package/src/text/vectorText.js +2 -2
- package/src/utils/areAllShapesTheSameType.js +2 -2
- package/src/utils/areAllShapesTheSameType.test.js +17 -0
- package/src/utils/index.d.ts +1 -0
- package/src/utils/index.js +3 -1
- package/src/utils/padArrayToLength.js +1 -1
- package/src/utils/trigonometry.d.ts +2 -0
- package/src/utils/trigonometry.js +35 -0
- package/src/utils/trigonometry.test.js +25 -0
- package/test/helpers/nearlyEqual.js +4 -1
|
@@ -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])
|
|
@@ -62,10 +62,10 @@ test('poly3: measureArea() should return correct values', (t) => {
|
|
|
62
62
|
ret2 = measureArea(ply2)
|
|
63
63
|
ret3 = measureArea(ply3)
|
|
64
64
|
ret4 = measureArea(ply4)
|
|
65
|
-
nearlyEqual(ret1, 0.0, Number.EPSILON)
|
|
66
|
-
nearlyEqual(ret2, 50.0, Number.EPSILON)
|
|
67
|
-
nearlyEqual(ret3, 100.0, Number.EPSILON)
|
|
68
|
-
nearlyEqual(ret4, 19.5, Number.EPSILON)
|
|
65
|
+
nearlyEqual(t, ret1, 0.0, Number.EPSILON)
|
|
66
|
+
nearlyEqual(t, ret2, 50.0, Number.EPSILON)
|
|
67
|
+
nearlyEqual(t, ret3, 100.0, Number.EPSILON)
|
|
68
|
+
nearlyEqual(t, ret4, 19.5, Number.EPSILON)
|
|
69
69
|
|
|
70
70
|
rotation = mat4.fromYRotation(mat4.create(), (45 * 0.017453292519943295))
|
|
71
71
|
ply1 = transform(rotation, ply1)
|
|
@@ -76,10 +76,10 @@ test('poly3: measureArea() should return correct values', (t) => {
|
|
|
76
76
|
ret2 = measureArea(ply2)
|
|
77
77
|
ret3 = measureArea(ply3)
|
|
78
78
|
ret4 = measureArea(ply4)
|
|
79
|
-
nearlyEqual(ret1, 0.0, Number.EPSILON)
|
|
80
|
-
nearlyEqual(ret2, 50.0, Number.EPSILON)
|
|
81
|
-
nearlyEqual(ret3, 100.0, Number.EPSILON)
|
|
82
|
-
nearlyEqual(ret4, 19.5, Number.EPSILON)
|
|
79
|
+
nearlyEqual(t, ret1, 0.0, Number.EPSILON)
|
|
80
|
+
nearlyEqual(t, ret2, 50.0, Number.EPSILON)
|
|
81
|
+
nearlyEqual(t, ret3, 100.0, Number.EPSILON)
|
|
82
|
+
nearlyEqual(t, ret4, 19.5, Number.EPSILON)
|
|
83
83
|
|
|
84
84
|
rotation = mat4.fromXRotation(mat4.create(), (45 * 0.017453292519943295))
|
|
85
85
|
ply1 = transform(rotation, ply1)
|
|
@@ -90,10 +90,10 @@ test('poly3: measureArea() should return correct values', (t) => {
|
|
|
90
90
|
ret2 = measureArea(ply2)
|
|
91
91
|
ret3 = measureArea(ply3)
|
|
92
92
|
ret4 = measureArea(ply4)
|
|
93
|
-
nearlyEqual(ret1, 0.0, Number.EPSILON)
|
|
94
|
-
nearlyEqual(ret2, 50.0, Number.EPSILON)
|
|
95
|
-
nearlyEqual(ret3, 100.0, Number.EPSILON)
|
|
96
|
-
nearlyEqual(ret4, 19.5, Number.EPSILON)
|
|
93
|
+
nearlyEqual(t, ret1, 0.0, Number.EPSILON)
|
|
94
|
+
nearlyEqual(t, ret2, 50.0, Number.EPSILON)
|
|
95
|
+
nearlyEqual(t, ret3, 100.0, Number.EPSILON)
|
|
96
|
+
nearlyEqual(t, ret4, 19.5, Number.EPSILON)
|
|
97
97
|
|
|
98
98
|
// inverted
|
|
99
99
|
ply1 = invert(ply1)
|
|
@@ -104,8 +104,8 @@ test('poly3: measureArea() should return correct values', (t) => {
|
|
|
104
104
|
ret2 = measureArea(ply2)
|
|
105
105
|
ret3 = measureArea(ply3)
|
|
106
106
|
ret4 = measureArea(ply4)
|
|
107
|
-
nearlyEqual(ret1, 0.0, Number.EPSILON)
|
|
108
|
-
nearlyEqual(ret2, 50.0, Number.EPSILON)
|
|
109
|
-
nearlyEqual(ret3, 100.0, Number.EPSILON)
|
|
110
|
-
nearlyEqual(ret4, 19.5, Number.EPSILON)
|
|
107
|
+
nearlyEqual(t, ret1, 0.0, Number.EPSILON)
|
|
108
|
+
nearlyEqual(t, ret2, 50.0, Number.EPSILON)
|
|
109
|
+
nearlyEqual(t, ret3, 100.0, Number.EPSILON)
|
|
110
|
+
nearlyEqual(t, ret4, 19.5, Number.EPSILON * 2)
|
|
111
111
|
})
|
|
@@ -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)
|
|
@@ -10,21 +10,21 @@ test('poly3: measureBoundingSphere() should return correct values', (t) => {
|
|
|
10
10
|
let exp1 = [[0, 0, 0], 0]
|
|
11
11
|
let ret1 = measureBoundingSphere(ply1)
|
|
12
12
|
t.true(compareVectors(ret1[0], exp1[0]))
|
|
13
|
-
nearlyEqual(ret1[1], exp1[1], Number.EPSILON)
|
|
13
|
+
nearlyEqual(t, ret1[1], exp1[1], Number.EPSILON)
|
|
14
14
|
|
|
15
15
|
// simple triangle
|
|
16
16
|
let ply2 = fromPoints([[0, 0, 0], [0, 10, 0], [0, 10, 10]])
|
|
17
17
|
let exp2 = [[0, 5, 5], 7.0710678118654755]
|
|
18
18
|
let ret2 = measureBoundingSphere(ply2)
|
|
19
19
|
t.true(compareVectors(ret2[0], exp2[0]))
|
|
20
|
-
nearlyEqual(ret2[1], exp2[1], Number.EPSILON)
|
|
20
|
+
nearlyEqual(t, ret2[1], exp2[1], Number.EPSILON)
|
|
21
21
|
|
|
22
22
|
// simple square
|
|
23
23
|
let ply3 = fromPoints([[0, 0, 0], [0, 10, 0], [0, 10, 10], [0, 0, 10]])
|
|
24
24
|
let exp3 = [[0, 5, 5], 7.0710678118654755]
|
|
25
25
|
let ret3 = measureBoundingSphere(ply3)
|
|
26
26
|
t.true(compareVectors(ret3[0], exp3[0]))
|
|
27
|
-
nearlyEqual(ret3[1], exp3[1], Number.EPSILON)
|
|
27
|
+
nearlyEqual(t, ret3[1], exp3[1], Number.EPSILON)
|
|
28
28
|
|
|
29
29
|
// V-shape
|
|
30
30
|
const points = [
|
|
@@ -43,7 +43,7 @@ test('poly3: measureBoundingSphere() should return correct values', (t) => {
|
|
|
43
43
|
let exp4 = [[0, 4.5, 3], 4.6097722286464435]
|
|
44
44
|
let ret4 = measureBoundingSphere(ply4)
|
|
45
45
|
t.true(compareVectors(ret4[0], exp4[0]))
|
|
46
|
-
nearlyEqual(ret4[1], exp4[1], Number.EPSILON)
|
|
46
|
+
nearlyEqual(t, ret4[1], exp4[1], Number.EPSILON)
|
|
47
47
|
|
|
48
48
|
// rotated to various angles
|
|
49
49
|
const rotation = mat4.fromZRotation(mat4.create(), (45 * 0.017453292519943295))
|
|
@@ -57,14 +57,14 @@ test('poly3: measureBoundingSphere() should return correct values', (t) => {
|
|
|
57
57
|
ret4 = measureBoundingSphere(ply4)
|
|
58
58
|
exp1 = [[0, 0, 0], 0]
|
|
59
59
|
t.true(compareVectors(ret1[0], exp1[0]))
|
|
60
|
-
nearlyEqual(ret1[1], exp1[1], Number.EPSILON)
|
|
60
|
+
nearlyEqual(t, ret1[1], exp1[1], Number.EPSILON)
|
|
61
61
|
exp2 = [[-3.5355339059327373, 3.5355339059327378, 5], 7.0710678118654755]
|
|
62
62
|
t.true(compareVectors(ret2[0], exp2[0]))
|
|
63
|
-
nearlyEqual(ret2[1], exp2[1], Number.EPSILON)
|
|
63
|
+
nearlyEqual(t, ret2[1], exp2[1], Number.EPSILON)
|
|
64
64
|
exp3 = [[-3.5355339059327373, 3.5355339059327378, 5], 7.0710678118654755]
|
|
65
65
|
t.true(compareVectors(ret3[0], exp3[0]))
|
|
66
|
-
nearlyEqual(ret3[1], exp3[1], Number.EPSILON)
|
|
66
|
+
nearlyEqual(t, ret3[1], exp3[1], Number.EPSILON)
|
|
67
67
|
exp4 = [[-3.181980515339464, 3.1819805153394642, 3], 4.6097722286464435]
|
|
68
68
|
t.true(compareVectors(ret4[0], exp4[0]))
|
|
69
|
-
nearlyEqual(ret4[1], exp4[1], Number.EPSILON)
|
|
69
|
+
nearlyEqual(t, ret4[1], exp4[1], Number.EPSILON)
|
|
70
70
|
})
|
|
@@ -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()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const vec3 = require('../../maths/vec3')
|
|
2
|
+
const isA = require('./isA')
|
|
3
|
+
const isConvex = require('./isConvex')
|
|
4
|
+
const measureArea = require('./measureArea')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Determine if the given object is a valid polygon.
|
|
8
|
+
* Checks for valid data structure, convex polygons, and duplicate points.
|
|
9
|
+
*
|
|
10
|
+
* **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} object - the object to interrogate
|
|
13
|
+
* @throws {Error} error if the geometry is not valid
|
|
14
|
+
* @alias module:modeling/geometries/poly3.validate
|
|
15
|
+
*/
|
|
16
|
+
const validate = (object) => {
|
|
17
|
+
if (!isA(object)) {
|
|
18
|
+
throw new Error('invalid poly3 structure')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// check for empty polygon
|
|
22
|
+
if (object.vertices.length < 3) {
|
|
23
|
+
throw new Error(`poly3 not enough vertices ${object.vertices.length}`)
|
|
24
|
+
}
|
|
25
|
+
// check area
|
|
26
|
+
if (measureArea(object) <= 0) {
|
|
27
|
+
throw new Error('poly3 area must be greater than zero')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// check for duplicate points
|
|
31
|
+
for (let i = 0; i < object.vertices.length; i++) {
|
|
32
|
+
if (vec3.equals(object.vertices[i], object.vertices[(i + 1) % object.vertices.length])) {
|
|
33
|
+
throw new Error(`poly3 duplicate vertex ${object.vertices[i]}`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// check convexity
|
|
38
|
+
if (!isConvex(object)) {
|
|
39
|
+
throw new Error('poly3 must be convex')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// check for infinity, nan
|
|
43
|
+
object.vertices.forEach((vertex) => {
|
|
44
|
+
if (!vertex.every(Number.isFinite)) {
|
|
45
|
+
throw new Error(`poly3 invalid vertex ${vertex}`)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = validate
|
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]))
|
package/src/maths/mat4/invert.js
CHANGED
|
@@ -4,27 +4,27 @@
|
|
|
4
4
|
* code from https://github.com/jlmakes/rematrix/blob/master/src/index.js
|
|
5
5
|
*
|
|
6
6
|
* @param {mat4} out - receiving matrix
|
|
7
|
-
* @param {mat4}
|
|
7
|
+
* @param {mat4} matrix - matrix to invert
|
|
8
8
|
* @returns {mat4} out
|
|
9
9
|
* @alias module:modeling/maths/mat4.invert
|
|
10
10
|
*/
|
|
11
|
-
const invert = (out,
|
|
12
|
-
const a00 =
|
|
13
|
-
const a01 =
|
|
14
|
-
const a02 =
|
|
15
|
-
const a03 =
|
|
16
|
-
const a10 =
|
|
17
|
-
const a11 =
|
|
18
|
-
const a12 =
|
|
19
|
-
const a13 =
|
|
20
|
-
const a20 =
|
|
21
|
-
const a21 =
|
|
22
|
-
const a22 =
|
|
23
|
-
const a23 =
|
|
24
|
-
const a30 =
|
|
25
|
-
const a31 =
|
|
26
|
-
const a32 =
|
|
27
|
-
const a33 =
|
|
11
|
+
const invert = (out, matrix) => {
|
|
12
|
+
const a00 = matrix[0]
|
|
13
|
+
const a01 = matrix[1]
|
|
14
|
+
const a02 = matrix[2]
|
|
15
|
+
const a03 = matrix[3]
|
|
16
|
+
const a10 = matrix[4]
|
|
17
|
+
const a11 = matrix[5]
|
|
18
|
+
const a12 = matrix[6]
|
|
19
|
+
const a13 = matrix[7]
|
|
20
|
+
const a20 = matrix[8]
|
|
21
|
+
const a21 = matrix[9]
|
|
22
|
+
const a22 = matrix[10]
|
|
23
|
+
const a23 = matrix[11]
|
|
24
|
+
const a30 = matrix[12]
|
|
25
|
+
const a31 = matrix[13]
|
|
26
|
+
const a32 = matrix[14]
|
|
27
|
+
const a33 = matrix[15]
|
|
28
28
|
|
|
29
29
|
const b00 = a00 * a11 - a01 * a10
|
|
30
30
|
const b01 = a00 * a12 - a02 * a10
|
|
@@ -9,10 +9,10 @@ const fromValues = require('../vec3/fromValues')
|
|
|
9
9
|
* @returns {Boolean} true if matrix is a mirroring transformation
|
|
10
10
|
* @alias module:modeling/maths/mat4.isMirroring
|
|
11
11
|
*/
|
|
12
|
-
const isMirroring = (
|
|
13
|
-
const u = fromValues(
|
|
14
|
-
const v = fromValues(
|
|
15
|
-
const w = fromValues(
|
|
12
|
+
const isMirroring = (matrix) => {
|
|
13
|
+
const u = fromValues(matrix[0], matrix[4], matrix[8])
|
|
14
|
+
const v = fromValues(matrix[1], matrix[5], matrix[9])
|
|
15
|
+
const w = fromValues(matrix[2], matrix[6], matrix[10])
|
|
16
16
|
|
|
17
17
|
// for a true orthogonal, non-mirrored base, u.cross(v) == w
|
|
18
18
|
// If they have an opposite direction then we are mirroring
|
|
@@ -4,7 +4,7 @@ const plane = require('../plane')
|
|
|
4
4
|
|
|
5
5
|
const { isMirroring, fromScaling, create, mirrorByPlane, rotate, scale, translate } = require('./index')
|
|
6
6
|
|
|
7
|
-
test('mat4: isMirroring() should determine
|
|
7
|
+
test('mat4: isMirroring() should determine correctly', (t) => {
|
|
8
8
|
let matrix = create()
|
|
9
9
|
t.false(isMirroring(matrix))
|
|
10
10
|
|
|
@@ -8,7 +8,7 @@ const fromValues = require('../vec3/fromValues')
|
|
|
8
8
|
* @param {mat4} matrix the input matrix
|
|
9
9
|
* @returns {vec3} output
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
11
|
+
const leftMultiplyVec3 = (vector, matrix) => {
|
|
12
12
|
const [v0, v1, v2] = vector
|
|
13
13
|
const v3 = 1
|
|
14
14
|
let x = v0 * matrix[0] + v1 * matrix[4] + v2 * matrix[8] + v3 * matrix[12]
|
|
@@ -26,4 +26,4 @@ const lefttMultiplyVec3 = (vector, matrix) => {
|
|
|
26
26
|
return fromValues(x, y, z)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
module.exports =
|
|
29
|
+
module.exports = leftMultiplyVec3
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Return a string representing the given matrix.
|
|
3
3
|
*
|
|
4
|
-
* @param {mat4}
|
|
4
|
+
* @param {mat4} mat - matrix of reference
|
|
5
5
|
* @returns {String} string representation
|
|
6
6
|
* @alias module:modeling/maths/mat4.toString
|
|
7
7
|
*/
|
|
8
|
-
const toString = (mat) =>
|
|
8
|
+
const toString = (mat) => mat.map((n) => n.toFixed(7)).toString()
|
|
9
9
|
|
|
10
10
|
module.exports = toString
|
|
@@ -3,7 +3,7 @@ const { translate, create } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('mat4: translate() called with three
|
|
6
|
+
test('mat4: translate() called with three parameters should update a mat4 with correct values', (t) => {
|
|
7
7
|
const identityMatrix = [
|
|
8
8
|
1, 0, 0, 0,
|
|
9
9
|
0, 1, 0, 0,
|
|
@@ -3,7 +3,7 @@ const { create, flip } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('plane: flip() called with two
|
|
6
|
+
test('plane: flip() called with two parameters should update a plane with correct values', (t) => {
|
|
7
7
|
const org1 = create()
|
|
8
8
|
const ret1 = flip(org1, [0, 0, 0, 0])
|
|
9
9
|
t.true(compareVectors(org1, [-0, -0, -0, -0]))
|
|
@@ -4,9 +4,7 @@ const vec3 = require('../vec3')
|
|
|
4
4
|
* Create a plane from the given points.
|
|
5
5
|
*
|
|
6
6
|
* @param {plane} out - receiving plane
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {vec3} b - 3D point
|
|
9
|
-
* @param {vec3} c - 3D point
|
|
7
|
+
* @param {Array} vertices - points on the plane
|
|
10
8
|
* @returns {plane} out
|
|
11
9
|
* @alias module:modeling/maths/plane.fromPoints
|
|
12
10
|
*/
|
|
@@ -8,6 +8,6 @@ const vec3 = require('../vec3')
|
|
|
8
8
|
* @return {Number} signed distance to point
|
|
9
9
|
* @alias module:modeling/maths/plane.signedDistanceToPoint
|
|
10
10
|
*/
|
|
11
|
-
const signedDistanceToPoint = (plane,
|
|
11
|
+
const signedDistanceToPoint = (plane, point) => vec3.dot(plane, point) - plane[3]
|
|
12
12
|
|
|
13
13
|
module.exports = signedDistanceToPoint
|
|
@@ -3,7 +3,7 @@ const { transform, create, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('plane: transform() called with three
|
|
6
|
+
test('plane: transform() called with three parameters should return a plane with correct values', (t) => {
|
|
7
7
|
const identityMatrix = [
|
|
8
8
|
1, 0, 0, 0,
|
|
9
9
|
0, 1, 0, 0,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Normals are directional vectors with component values from 0 to 1.0, requiring specialized
|
|
2
|
-
// This EPS is derived from a
|
|
1
|
+
// Normals are directional vectors with component values from 0 to 1.0, requiring specialized comparison
|
|
2
|
+
// This EPS is derived from a series of tests to determine the optimal precision for comparing coplanar polygons,
|
|
3
3
|
// as provided by the sphere primitive at high segmentation
|
|
4
4
|
// This EPS is for 64 bit Number values
|
|
5
5
|
const NEPS = 1e-13
|
package/src/maths/vec2/abs.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ const { add, fromValues } = require('./index')
|
|
|
3
3
|
|
|
4
4
|
const { compareVectors } = require('../../../test/helpers/index')
|
|
5
5
|
|
|
6
|
-
test('vec2: add() called with three
|
|
6
|
+
test('vec2: add() called with three parameters should update a vec2 with correct values', (t) => {
|
|
7
7
|
const obs1 = fromValues(0, 0)
|
|
8
8
|
const ret1 = add(obs1, [0, 0], [0, 0])
|
|
9
9
|
t.true(compareVectors(obs1, [0, 0]))
|