@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.
Files changed (238) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/jscad-modeling.min.js +443 -398
  3. package/package.json +2 -2
  4. package/src/curves/bezier/tangentAt.test.js +1 -1
  5. package/src/curves/bezier/valueAt.test.js +1 -1
  6. package/src/geometries/geom2/index.d.ts +1 -0
  7. package/src/geometries/geom2/index.js +12 -1
  8. package/src/geometries/geom2/isA.js +2 -2
  9. package/src/geometries/geom2/toCompactBinary.js +4 -4
  10. package/src/geometries/geom2/toString.js +1 -1
  11. package/src/geometries/geom2/transform.test.js +1 -1
  12. package/src/geometries/geom2/validate.d.ts +3 -0
  13. package/src/geometries/geom2/validate.js +36 -0
  14. package/src/geometries/geom3/fromCompactBinary.js +1 -1
  15. package/src/geometries/geom3/index.d.ts +1 -0
  16. package/src/geometries/geom3/index.js +19 -1
  17. package/src/geometries/geom3/isA.js +2 -2
  18. package/src/geometries/geom3/toCompactBinary.js +4 -4
  19. package/src/geometries/geom3/toString.js +1 -1
  20. package/src/geometries/geom3/transform.test.js +1 -1
  21. package/src/geometries/geom3/validate.d.ts +3 -0
  22. package/src/geometries/geom3/validate.js +62 -0
  23. package/src/geometries/index.js +8 -1
  24. package/src/geometries/path2/eachPoint.js +3 -3
  25. package/src/geometries/path2/index.d.ts +1 -0
  26. package/src/geometries/path2/index.js +13 -1
  27. package/src/geometries/path2/isA.js +2 -2
  28. package/src/geometries/path2/reverse.js +4 -4
  29. package/src/geometries/path2/toCompactBinary.js +6 -6
  30. package/src/geometries/path2/toString.js +1 -1
  31. package/src/geometries/path2/transform.test.js +1 -1
  32. package/src/geometries/path2/validate.d.ts +3 -0
  33. package/src/geometries/path2/validate.js +41 -0
  34. package/src/geometries/poly2/arePointsInside.js +0 -35
  35. package/src/geometries/poly2/arePointsInside.test.js +1 -1
  36. package/src/geometries/poly2/index.js +6 -0
  37. package/src/geometries/poly3/index.d.ts +1 -0
  38. package/src/geometries/poly3/index.js +9 -2
  39. package/src/geometries/poly3/invert.js +7 -1
  40. package/src/geometries/poly3/isA.js +2 -2
  41. package/src/geometries/poly3/isConvex.js +2 -2
  42. package/src/geometries/poly3/measureArea.js +4 -4
  43. package/src/geometries/poly3/measureArea.test.js +16 -16
  44. package/src/geometries/poly3/measureBoundingBox.js +2 -2
  45. package/src/geometries/poly3/measureBoundingSphere.js +2 -2
  46. package/src/geometries/poly3/measureBoundingSphere.test.js +8 -8
  47. package/src/geometries/poly3/measureSignedVolume.js +4 -4
  48. package/src/geometries/poly3/toPoints.js +2 -2
  49. package/src/geometries/poly3/toString.js +2 -2
  50. package/src/geometries/poly3/transform.js +2 -2
  51. package/src/geometries/poly3/validate.d.ts +4 -0
  52. package/src/geometries/poly3/validate.js +50 -0
  53. package/src/maths/index.js +1 -1
  54. package/src/maths/line2/equals.js +2 -2
  55. package/src/maths/line2/fromValues.js +2 -2
  56. package/src/maths/line2/intersectPointOfLines.js +1 -1
  57. package/src/maths/line2/intersectPointOfLines.test.js +1 -1
  58. package/src/maths/line2/reverse.test.js +1 -1
  59. package/src/maths/line2/transform.test.js +1 -1
  60. package/src/maths/line3/equals.js +2 -2
  61. package/src/maths/line3/reverse.test.js +1 -1
  62. package/src/maths/line3/transform.test.js +1 -1
  63. package/src/maths/mat4/fromVectorRotation.js +1 -1
  64. package/src/maths/mat4/fromVectorRotation.test.js +1 -1
  65. package/src/maths/mat4/identity.test.js +1 -1
  66. package/src/maths/mat4/invert.js +18 -18
  67. package/src/maths/mat4/isIdentity.js +1 -1
  68. package/src/maths/mat4/isMirroring.js +4 -4
  69. package/src/maths/mat4/isMirroring.test.js +1 -1
  70. package/src/maths/mat4/leftMultiplyVec3.js +2 -2
  71. package/src/maths/mat4/toString.js +2 -2
  72. package/src/maths/mat4/translate.test.js +1 -1
  73. package/src/maths/plane/flip.test.js +1 -1
  74. package/src/maths/plane/fromPoints.d.ts +1 -1
  75. package/src/maths/plane/fromPoints.js +1 -3
  76. package/src/maths/plane/signedDistanceToPoint.js +1 -1
  77. package/src/maths/plane/transform.test.js +1 -1
  78. package/src/maths/utils/aboutEqualNormals.js +2 -2
  79. package/src/maths/vec2/abs.d.ts +1 -1
  80. package/src/maths/vec2/add.test.js +1 -1
  81. package/src/maths/vec2/angleDegrees.d.ts +1 -1
  82. package/src/maths/vec2/angleRadians.d.ts +1 -1
  83. package/src/maths/vec2/create.js +1 -1
  84. package/src/maths/vec2/cross.test.js +1 -1
  85. package/src/maths/vec2/divide.test.js +1 -1
  86. package/src/maths/vec2/fromAngleDegrees.js +1 -1
  87. package/src/maths/vec2/fromScalar.js +1 -1
  88. package/src/maths/vec2/length.d.ts +1 -1
  89. package/src/maths/vec2/length.js +1 -1
  90. package/src/maths/vec2/lerp.test.js +1 -1
  91. package/src/maths/vec2/multiply.test.js +1 -1
  92. package/src/maths/vec2/negate.test.js +1 -1
  93. package/src/maths/vec2/normal.js +1 -1
  94. package/src/maths/vec2/normalize.d.ts +1 -1
  95. package/src/maths/vec2/normalize.test.js +1 -1
  96. package/src/maths/vec2/rotate.test.js +1 -1
  97. package/src/maths/vec2/squaredLength.d.ts +1 -1
  98. package/src/maths/vec2/squaredLength.js +3 -3
  99. package/src/maths/vec2/subtract.test.js +1 -1
  100. package/src/maths/vec2/toString.js +1 -1
  101. package/src/maths/vec2/transform.test.js +1 -1
  102. package/src/maths/vec3/abs.d.ts +1 -1
  103. package/src/maths/vec3/add.test.js +1 -1
  104. package/src/maths/vec3/cross.test.js +1 -1
  105. package/src/maths/vec3/divide.test.js +1 -1
  106. package/src/maths/vec3/fromScalar.js +1 -1
  107. package/src/maths/vec3/fromVec2.d.ts +1 -1
  108. package/src/maths/vec3/fromVec2.js +3 -3
  109. package/src/maths/vec3/length.d.ts +1 -1
  110. package/src/maths/vec3/length.js +4 -4
  111. package/src/maths/vec3/lerp.test.js +1 -1
  112. package/src/maths/vec3/multiply.test.js +1 -1
  113. package/src/maths/vec3/negate.d.ts +1 -1
  114. package/src/maths/vec3/negate.test.js +1 -1
  115. package/src/maths/vec3/normalize.d.ts +1 -1
  116. package/src/maths/vec3/normalize.test.js +1 -1
  117. package/src/maths/vec3/rotateX.test.js +1 -1
  118. package/src/maths/vec3/rotateY.test.js +1 -1
  119. package/src/maths/vec3/rotateZ.test.js +1 -1
  120. package/src/maths/vec3/scale.test.js +1 -1
  121. package/src/maths/vec3/squaredLength.d.ts +1 -1
  122. package/src/maths/vec3/squaredLength.js +4 -4
  123. package/src/maths/vec3/subtract.test.js +1 -1
  124. package/src/maths/vec3/toString.js +1 -1
  125. package/src/maths/vec3/transform.test.js +1 -1
  126. package/src/maths/vec4/toString.js +1 -1
  127. package/src/maths/vec4/transform.test.js +1 -1
  128. package/src/measurements/measureBoundingSphere.js +4 -4
  129. package/src/measurements/measureCenterOfMass.js +1 -1
  130. package/src/measurements/measureCenterOfMass.test.js +2 -2
  131. package/src/operations/booleans/intersect.test.js +8 -0
  132. package/src/operations/booleans/mayOverlap.js +3 -3
  133. package/src/operations/booleans/retessellate.js +2 -2
  134. package/src/operations/booleans/scission.js +1 -1
  135. package/src/operations/booleans/scission.test.js +4 -4
  136. package/src/operations/booleans/subtract.js +1 -1
  137. package/src/operations/booleans/subtract.test.js +8 -0
  138. package/src/operations/booleans/trees/Node.js +10 -16
  139. package/src/operations/booleans/trees/PolygonTreeNode.js +13 -14
  140. package/src/operations/booleans/trees/Tree.js +1 -2
  141. package/src/operations/booleans/trees/splitPolygonByPlane.js +2 -3
  142. package/src/operations/booleans/union.test.js +28 -1
  143. package/src/operations/booleans/unionGeom3Sub.js +1 -1
  144. package/src/operations/expansions/expand.js +2 -2
  145. package/src/operations/expansions/expand.test.js +32 -55
  146. package/src/operations/expansions/expandShell.js +24 -18
  147. package/src/operations/expansions/offset.js +1 -1
  148. package/src/operations/expansions/offset.test.js +50 -89
  149. package/src/operations/expansions/offsetFromPoints.js +11 -6
  150. package/src/operations/extrusions/earcut/assignHoles.js +91 -0
  151. package/src/operations/extrusions/earcut/assignHoles.test.js +74 -0
  152. package/src/operations/extrusions/earcut/eliminateHoles.js +131 -0
  153. package/src/operations/extrusions/earcut/index.js +252 -0
  154. package/src/operations/extrusions/earcut/linkedList.js +58 -0
  155. package/src/operations/extrusions/earcut/linkedListSort.js +54 -0
  156. package/src/operations/extrusions/earcut/linkedPolygon.js +197 -0
  157. package/src/operations/extrusions/earcut/polygonHierarchy.js +64 -0
  158. package/src/operations/extrusions/earcut/triangle.js +16 -0
  159. package/src/operations/extrusions/extrudeFromSlices.js +10 -3
  160. package/src/operations/extrusions/extrudeFromSlices.test.js +47 -31
  161. package/src/operations/extrusions/extrudeLinear.js +10 -5
  162. package/src/operations/extrusions/extrudeLinear.test.js +91 -35
  163. package/src/operations/extrusions/extrudeLinearGeom2.js +5 -2
  164. package/src/operations/extrusions/extrudeLinearPath2.js +24 -0
  165. package/src/operations/extrusions/extrudeRectangular.js +1 -1
  166. package/src/operations/extrusions/extrudeRectangular.test.js +22 -15
  167. package/src/operations/extrusions/extrudeRotate.test.js +31 -27
  168. package/src/operations/extrusions/project.js +1 -1
  169. package/src/operations/extrusions/project.test.js +5 -5
  170. package/src/operations/extrusions/slice/calculatePlane.js +7 -4
  171. package/src/operations/extrusions/slice/isA.js +2 -2
  172. package/src/operations/extrusions/slice/repairSlice.js +47 -0
  173. package/src/operations/extrusions/slice/toPolygons.js +24 -60
  174. package/src/operations/hulls/hull.test.js +25 -2
  175. package/src/operations/hulls/hullChain.js +1 -1
  176. package/src/operations/hulls/hullChain.test.js +6 -4
  177. package/src/operations/hulls/hullGeom2.js +1 -1
  178. package/src/operations/hulls/hullPath2.js +6 -4
  179. package/src/operations/hulls/hullPath2.test.js +16 -0
  180. package/src/operations/hulls/hullPoints2.test.js +1 -1
  181. package/src/operations/modifiers/edges.js +1 -1
  182. package/src/operations/modifiers/generalize.js +1 -1
  183. package/src/operations/modifiers/generalize.test.js +6 -0
  184. package/src/operations/modifiers/snap.test.js +3 -3
  185. package/src/operations/transforms/align.d.ts +1 -1
  186. package/src/operations/transforms/align.test.js +12 -0
  187. package/src/operations/transforms/center.js +17 -17
  188. package/src/operations/transforms/center.test.js +12 -0
  189. package/src/operations/transforms/mirror.js +12 -12
  190. package/src/operations/transforms/mirror.test.js +16 -0
  191. package/src/operations/transforms/rotate.js +12 -12
  192. package/src/operations/transforms/rotate.test.js +10 -0
  193. package/src/operations/transforms/scale.js +19 -19
  194. package/src/operations/transforms/scale.test.js +15 -0
  195. package/src/operations/transforms/transform.js +3 -3
  196. package/src/operations/transforms/transform.test.js +5 -0
  197. package/src/operations/transforms/translate.js +14 -14
  198. package/src/operations/transforms/translate.test.js +16 -0
  199. package/src/primitives/arc.js +1 -1
  200. package/src/primitives/arc.test.js +11 -0
  201. package/src/primitives/circle.test.js +15 -9
  202. package/src/primitives/cube.test.js +3 -0
  203. package/src/primitives/cuboid.test.js +9 -24
  204. package/src/primitives/cylinder.test.js +7 -4
  205. package/src/primitives/cylinderElliptic.js +13 -6
  206. package/src/primitives/cylinderElliptic.test.js +72 -52
  207. package/src/primitives/ellipse.js +3 -1
  208. package/src/primitives/ellipse.test.js +14 -8
  209. package/src/primitives/ellipsoid.js +7 -5
  210. package/src/primitives/ellipsoid.test.js +84 -82
  211. package/src/primitives/geodesicSphere.d.ts +0 -1
  212. package/src/primitives/geodesicSphere.test.js +3 -0
  213. package/src/primitives/line.test.js +1 -0
  214. package/src/primitives/polygon.test.js +15 -10
  215. package/src/primitives/polyhedron.js +1 -1
  216. package/src/primitives/polyhedron.test.js +14 -42
  217. package/src/primitives/rectangle.test.js +3 -0
  218. package/src/primitives/roundedCuboid.test.js +5 -0
  219. package/src/primitives/roundedCylinder.js +6 -4
  220. package/src/primitives/roundedCylinder.test.js +40 -36
  221. package/src/primitives/roundedRectangle.test.js +5 -0
  222. package/src/primitives/sphere.test.js +52 -73
  223. package/src/primitives/square.test.js +3 -0
  224. package/src/primitives/star.test.js +6 -0
  225. package/src/primitives/torus.d.ts +0 -1
  226. package/src/primitives/torus.test.js +8 -1
  227. package/src/primitives/triangle.js +1 -1
  228. package/src/primitives/triangle.test.js +7 -0
  229. package/src/text/vectorText.js +2 -2
  230. package/src/utils/areAllShapesTheSameType.js +2 -2
  231. package/src/utils/areAllShapesTheSameType.test.js +17 -0
  232. package/src/utils/index.d.ts +1 -0
  233. package/src/utils/index.js +3 -1
  234. package/src/utils/padArrayToLength.js +1 -1
  235. package/src/utils/trigonometry.d.ts +2 -0
  236. package/src/utils/trigonometry.js +35 -0
  237. package/src/utils/trigonometry.test.js +25 -0
  238. package/test/helpers/nearlyEqual.js +4 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Determin if the given object is a polygon.
3
- * @param {Object} object - the object to interogate
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 interogate
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 = (poly3) => areVerticesConvex(poly3.vertices)
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 = (poly3) => {
11
- const n = poly3.vertices.length
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 = poly3.vertices
15
+ const vertices = polygon.vertices
16
16
 
17
17
  // calculate a normal vector
18
- const normal = plane(poly3)
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 = (poly3) => {
9
- const vertices = poly3.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 = (poly3) => {
11
- const box = measureBoundingBox(poly3)
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 tetrahedon connected to the axis [0,0,0],
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 = (poly3) => {
12
+ const measureSignedVolume = (polygon) => {
13
13
  let signedVolume = 0
14
- const vertices = poly3.vertices
15
- // calculate based on triangluar polygons
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 geometry as a list of points.
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 = (geometry) => geometry.vertices
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 = (poly3) => {
8
+ const toString = (polygon) => {
9
9
  let result = 'poly3: vertices: ['
10
- poly3.vertices.forEach((vertex) => {
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, poly3) => {
14
- const vertices = poly3.vertices.map((vertex) => vec3.transform(vec3.create(), vertex, matrix))
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,4 @@
1
+
2
+ export default validate
3
+
4
+ declare function validate(object: any): void
@@ -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
@@ -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 structues are consider immutable, so never change the contents directly.
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} a - first line to compare
5
- * @param {line2} b - second line to compare
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, w) => {
12
+ const fromValues = (x, y, d) => {
13
13
  const out = create()
14
14
  out[0] = x
15
15
  out[1] = y
16
- out[2] = w
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 paralell.
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
- // paralell lines
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 paramerters should update a line2 with proper values', (t) => {
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 paramerters should update a line2 with correct values', (t) => {
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} a - first line to compare
7
- * @param {line3} b - second line to compare
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 paramerters should update a line3 with proper values', (t) => {
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 paramerters should update a line3 with correct values', (t) => {
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 then zero.
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
- // differnt units
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 paramerters should update a mat4 with correct values', (t) => {
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]))
@@ -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} m - matrix to invert
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, a) => {
12
- const a00 = a[0]
13
- const a01 = a[1]
14
- const a02 = a[2]
15
- const a03 = a[3]
16
- const a10 = a[4]
17
- const a11 = a[5]
18
- const a12 = a[6]
19
- const a13 = a[7]
20
- const a20 = a[8]
21
- const a21 = a[9]
22
- const a22 = a[10]
23
- const a23 = a[11]
24
- const a30 = a[12]
25
- const a31 = a[13]
26
- const a32 = a[14]
27
- const a33 = a[15]
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Determine whether the given matris is the identity transform.
2
+ * Determine whether the given matrix is the identity transform.
3
3
  * This is equivalent to (but much faster than):
4
4
  *
5
5
  * mat4.equals(mat4.create(), matrix)
@@ -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 = (mat) => {
13
- const u = fromValues(mat[0], mat[4], mat[8])
14
- const v = fromValues(mat[1], mat[5], mat[9])
15
- const w = fromValues(mat[2], mat[6], mat[10])
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 correctlly', (t) => {
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 lefttMultiplyVec3 = (vector, matrix) => {
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 = lefttMultiplyVec3
29
+ module.exports = leftMultiplyVec3
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Return a string representing the given matrix.
3
3
  *
4
- * @param {mat4} matrix - matrix of reference
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) => `[${mat[0].toFixed(7)}, ${mat[1].toFixed(7)}, ${mat[2].toFixed(7)}, ${mat[3].toFixed(7)}, ${mat[4].toFixed(7)}, ${mat[5].toFixed(7)}, ${mat[6].toFixed(7)}, ${mat[7].toFixed(7)}, ${mat[8].toFixed(7)}, ${mat[9].toFixed(7)}, ${mat[10].toFixed(7)}, ${mat[11].toFixed(7)}, ${mat[12].toFixed(7)}, ${mat[13].toFixed(7)}, ${mat[14].toFixed(7)}, ${mat[15].toFixed(7)}]`
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 paramerters should update a mat4 with correct values', (t) => {
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 paramerters should update a plane with correct values', (t) => {
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]))
@@ -3,4 +3,4 @@ import Vec3 from '../vec3/type'
3
3
 
4
4
  export default fromPoints
5
5
 
6
- declare function fromPoints(out: Plane, a: Vec3, b: Vec3, c: Vec3): Plane
6
+ declare function fromPoints(out: Plane, ...vertices: Array<Vec3>): Plane
@@ -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 {vec3} a - 3D point
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, vector) => vec3.dot(plane, vector) - plane[3]
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 paramerters should return a plane with correct values', (t) => {
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 comparision
2
- // This EPS is derived from a serieas of tests to determine the optimal precision for comparing coplanar polygons,
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
@@ -2,4 +2,4 @@ import Vec2 from './type'
2
2
 
3
3
  export default abs
4
4
 
5
- declare function abs(out: Vec2, vec: Vec2): Vec2
5
+ declare function abs(out: Vec2, vector: Vec2): Vec2
@@ -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 paramerters should update a vec2 with correct values', (t) => {
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]))