@jscad/modeling 3.0.3-alpha.0 → 3.0.4-alpha.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.
Files changed (148) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/jscad-modeling.es.js +2 -7
  3. package/dist/jscad-modeling.min.js +2 -7
  4. package/package.json +6 -7
  5. package/rollup.config.js +8 -4
  6. package/src/curves/bezier/arcLengthToT.js +1 -1
  7. package/src/curves/bezier/create.js +1 -1
  8. package/src/curves/bezier/index.js +7 -7
  9. package/src/curves/bezier/length.js +1 -1
  10. package/src/curves/bezier/lengths.js +2 -1
  11. package/src/curves/bezier/tangentAt.js +1 -1
  12. package/src/curves/bezier/valueAt.js +1 -1
  13. package/src/curves/index.js +3 -3
  14. package/src/geometries/geom2/applyTransforms.js +3 -1
  15. package/src/geometries/geom2/clone.js +5 -1
  16. package/src/geometries/geom2/create.js +4 -14
  17. package/src/geometries/geom2/fromSides.js +4 -2
  18. package/src/geometries/geom2/index.js +21 -5
  19. package/src/geometries/geom2/isA.js +5 -1
  20. package/src/geometries/geom2/reverse.js +4 -2
  21. package/src/geometries/geom2/toOutlines.js +2 -1
  22. package/src/geometries/geom2/toPoints.js +5 -2
  23. package/src/geometries/geom2/toSides.js +4 -3
  24. package/src/geometries/geom2/toString.js +3 -2
  25. package/src/geometries/geom2/transform.js +4 -2
  26. package/src/geometries/geom2/validate.js +6 -2
  27. package/src/geometries/geom3/clone.js +5 -1
  28. package/src/geometries/geom3/create.js +5 -19
  29. package/src/geometries/geom3/fromVertices.js +13 -1
  30. package/src/geometries/geom3/fromVerticesConvex.js +1 -1
  31. package/src/geometries/geom3/index.d.ts +1 -0
  32. package/src/geometries/geom3/index.js +26 -4
  33. package/src/geometries/geom3/invert.js +5 -1
  34. package/src/geometries/geom3/isA.js +5 -1
  35. package/src/geometries/geom3/isConvex.d.ts +3 -0
  36. package/src/geometries/geom3/isConvex.js +65 -0
  37. package/src/geometries/geom3/isConvex.test.js +44 -0
  38. package/src/geometries/geom3/toPolygons.js +4 -2
  39. package/src/geometries/geom3/toString.js +3 -2
  40. package/src/geometries/geom3/toVertices.js +8 -4
  41. package/src/geometries/geom3/transform.js +5 -2
  42. package/src/geometries/geom3/validate.js +6 -2
  43. package/src/geometries/index.js +9 -7
  44. package/src/geometries/path2/appendArc.js +7 -5
  45. package/src/geometries/path2/appendArc.test.js +11 -15
  46. package/src/geometries/path2/appendBezier.js +6 -4
  47. package/src/geometries/path2/appendPoints.js +4 -2
  48. package/src/geometries/path2/applyTransforms.js +3 -0
  49. package/src/geometries/path2/clone.js +5 -1
  50. package/src/geometries/path2/close.js +5 -1
  51. package/src/geometries/path2/concat.js +3 -2
  52. package/src/geometries/path2/create.js +4 -15
  53. package/src/geometries/path2/equals.js +12 -7
  54. package/src/geometries/path2/fromPoints.js +5 -3
  55. package/src/geometries/path2/index.js +21 -4
  56. package/src/geometries/path2/isA.js +5 -1
  57. package/src/geometries/path2/reverse.js +4 -2
  58. package/src/geometries/path2/toPoints.js +5 -3
  59. package/src/geometries/path2/toString.js +3 -2
  60. package/src/geometries/path2/transform.js +4 -2
  61. package/src/geometries/path2/validate.js +5 -1
  62. package/src/geometries/path3/applyTransforms.js +1 -1
  63. package/src/geometries/path3/close.js +4 -2
  64. package/src/geometries/path3/concat.js +2 -3
  65. package/src/geometries/path3/create.js +4 -20
  66. package/src/geometries/path3/equals.js +4 -2
  67. package/src/geometries/path3/fromVertices.js +2 -3
  68. package/src/geometries/path3/index.js +17 -1
  69. package/src/geometries/path3/isA.js +4 -2
  70. package/src/geometries/path3/reverse.js +2 -3
  71. package/src/geometries/path3/toString.js +2 -3
  72. package/src/geometries/path3/toVertices.js +2 -3
  73. package/src/geometries/path3/transform.js +2 -3
  74. package/src/geometries/path3/validate.js +6 -3
  75. package/src/geometries/poly2/arePointsInside.js +4 -1
  76. package/src/geometries/poly2/clone.js +4 -1
  77. package/src/geometries/poly2/create.js +2 -9
  78. package/src/geometries/poly2/index.js +16 -4
  79. package/src/geometries/poly2/isA.js +5 -1
  80. package/src/geometries/poly2/isConvex.js +5 -1
  81. package/src/geometries/poly2/isSimple.js +5 -1
  82. package/src/geometries/poly2/measureArea.js +4 -1
  83. package/src/geometries/poly2/measureBoundingBox.js +6 -1
  84. package/src/geometries/poly2/reverse.js +4 -1
  85. package/src/geometries/poly2/toPoints.js +6 -1
  86. package/src/geometries/poly2/toString.js +5 -1
  87. package/src/geometries/poly2/transform.js +5 -1
  88. package/src/geometries/poly2/validate.js +6 -2
  89. package/src/geometries/poly3/clone.js +4 -1
  90. package/src/geometries/poly3/create.js +3 -11
  91. package/src/geometries/poly3/fromVerticesAndPlane.js +3 -1
  92. package/src/geometries/poly3/index.js +19 -4
  93. package/src/geometries/poly3/invert.js +4 -1
  94. package/src/geometries/poly3/isA.js +5 -1
  95. package/src/geometries/poly3/isConvex.js +5 -1
  96. package/src/geometries/poly3/measureArea.js +5 -1
  97. package/src/geometries/poly3/measureBoundingBox.js +4 -1
  98. package/src/geometries/poly3/measureBoundingSphere.js +4 -3
  99. package/src/geometries/poly3/measureSignedVolume.js +6 -1
  100. package/src/geometries/poly3/plane.js +6 -0
  101. package/src/geometries/poly3/toString.js +5 -1
  102. package/src/geometries/poly3/toVertices.js +6 -1
  103. package/src/geometries/poly3/transform.js +5 -1
  104. package/src/geometries/poly3/validate.js +6 -2
  105. package/src/geometries/slice/calculatePlane.js +3 -3
  106. package/src/geometries/slice/clone.js +4 -1
  107. package/src/geometries/slice/create.js +5 -10
  108. package/src/geometries/slice/equals.js +5 -1
  109. package/src/geometries/slice/fromGeom2.js +1 -1
  110. package/src/geometries/slice/fromVertices.js +3 -3
  111. package/src/geometries/slice/index.js +19 -4
  112. package/src/geometries/slice/isA.js +5 -1
  113. package/src/geometries/slice/reverse.js +5 -2
  114. package/src/geometries/slice/toEdges.js +5 -3
  115. package/src/geometries/slice/toPolygons.js +5 -1
  116. package/src/geometries/slice/toString.js +5 -1
  117. package/src/geometries/slice/toVertices.js +5 -3
  118. package/src/geometries/slice/transform.js +4 -3
  119. package/src/geometries/slice/validate.js +3 -2
  120. package/src/index.d.ts +1 -0
  121. package/src/index.js +4 -0
  122. package/src/maths/constants.js +11 -7
  123. package/src/maths/index.js +2 -1
  124. package/src/maths/mat4/isOnlyTransformScale.js +1 -1
  125. package/src/operations/booleans/index.js +2 -0
  126. package/src/operations/booleans/intersect.js +0 -1
  127. package/src/operations/booleans/scission.js +0 -1
  128. package/src/operations/booleans/trees/splitLineSegmentByPlane.js +1 -4
  129. package/src/operations/booleans/trees/splitPolygonByPlane.test.js +138 -0
  130. package/src/operations/booleans/unionGeom3.test.js +35 -0
  131. package/src/operations/extrusions/extrudeFromSlices.js +15 -5
  132. package/src/operations/extrusions/extrudeRotate.js +2 -1
  133. package/src/operations/extrusions/extrudeRotate.test.js +34 -0
  134. package/src/operations/extrusions/extrudeWalls.test.js +60 -0
  135. package/src/operations/minkowski/index.d.ts +1 -0
  136. package/src/operations/minkowski/index.js +15 -0
  137. package/src/operations/minkowski/minkowskiSum.d.ts +4 -0
  138. package/src/operations/minkowski/minkowskiSum.js +223 -0
  139. package/src/operations/minkowski/minkowskiSum.test.js +199 -0
  140. package/src/operations/modifiers/reTesselateCoplanarPolygons.js +10 -3
  141. package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +36 -1
  142. package/src/operations/modifiers/retessellate.js +4 -2
  143. package/src/operations/modifiers/snap.test.js +24 -15
  144. package/src/operations/offsets/offsetGeom3.test.js +5 -7
  145. package/src/primitives/arc.js +2 -2
  146. package/src/primitives/arc.test.js +104 -113
  147. package/src/utils/flatten.js +1 -1
  148. package/src/utils/flatten.test.js +94 -0
@@ -4,13 +4,17 @@ import { isA } from './isA.js'
4
4
 
5
5
  /**
6
6
  * Determine if the given object is a valid path2.
7
+ *
7
8
  * Checks for valid data points, and duplicate points.
8
9
  *
9
10
  * **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
10
11
  *
11
12
  * @param {object} object - the object to interrogate
12
13
  * @throws {Error} error if the geometry is not valid
13
- * @alias module:modeling/geometries/path2.validate
14
+ * @alias module:modeling/path2.validate
15
+ *
16
+ * @example
17
+ * path2.validate(geometry)
14
18
  */
15
19
  export const validate = (object) => {
16
20
  if (!isA(object)) {
@@ -11,7 +11,7 @@ import * as vec3 from '../../maths/vec3/index.js'
11
11
  * @function
12
12
  *
13
13
  * @example
14
- * geometry = applyTransforms(geometry)
14
+ * geometry = path3.applyTransforms(geometry)
15
15
  */
16
16
  export const applyTransforms = (geometry) => {
17
17
  if (mat4.isIdentity(geometry.transforms)) return geometry
@@ -7,8 +7,10 @@ import * as vec3 from '../../maths/vec3/index.js'
7
7
  *
8
8
  * @param {Path3} geometry - the path to close
9
9
  * @returns {Path3} a new path
10
- * @function
11
- * @alias module:modeling/geometries/path3.close
10
+ * @alias module:modeling/path3.close
11
+ *
12
+ * @example
13
+ * const newPath = path3.close(oldPath)
12
14
  */
13
15
  export const close = (geometry) => {
14
16
  if (geometry.isClosed) return geometry
@@ -13,11 +13,10 @@ import { toVertices } from './toVertices.js'
13
13
  *
14
14
  * @param {...Path3} paths - the paths to concatenate
15
15
  * @returns {Path3} a new path
16
- * @function
17
- * @alias module:modeling/geometries/path3.concat
16
+ * @alias module:modeling/path3.concat
18
17
  *
19
18
  * @example
20
- * let newPath = concat(fromVertices({}, [[1, 2, 3]]), fromVertices({}, [[4, 5, 6]]))
19
+ * let newPath = path3.concat(path3.fromVertices({}, [[1, 2, 3]]), path3.fromVertices({}, [[4, 5, 6]]))
21
20
  */
22
21
  export const concat = (...paths) => {
23
22
  // Only the last path can be closed, producing a closed path.
@@ -1,30 +1,14 @@
1
1
  import * as mat4 from '../../maths/mat4/index.js'
2
2
 
3
- /**
4
- * Represents a 3D geometry consisting of a list of ordered vertices.
5
- *
6
- * @typedef {Object} Path3
7
- * @property {Array} vertices - list of ordered vertices
8
- * @property {boolean} isClosed - true if the path is closed where start and end vertices are the same
9
- * @property {Mat4} transforms - transforms to apply to the vertices, see transform()
10
- *
11
- * @example
12
- * {
13
- * vertices: [[0,0,0], [4,0,0], [4,3,0]],
14
- * isClosed: true,
15
- * transforms: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
16
- * }
17
- */
18
-
19
3
  /**
20
4
  * Create an empty, open path.
21
5
  *
6
+ * @param {Array} [vertices] - a list of vertices of which to create the path
22
7
  * @returns {Path3} a new path
23
- * @function
24
- * @alias module:modeling/geometries/path3.create
8
+ * @alias module:modeling/path3.create
25
9
  *
26
10
  * @example
27
- * let pathA = create()
28
- * let pathB = create([[0,0,0], [4,0,0], [4,3,0]])
11
+ * let pathA = path3.create()
12
+ * let pathB = path3.create([[0,0,0], [4,0,0], [4,3,0]])
29
13
  */
30
14
  export const create = (vertices = []) => ({ vertices: vertices, isClosed: false, transforms: mat4.create() })
@@ -10,8 +10,10 @@ import { toVertices } from './toVertices.js'
10
10
  * @param {Path3} a - the first path to compare
11
11
  * @param {Path3} b - the second path to compare
12
12
  * @returns {boolean}
13
- * @function
14
- * @alias module:modeling/geometries/path3.equals
13
+ * @alias module:modeling/path3.equals
14
+ *
15
+ * @example
16
+ * if (path3.equals(pathA, pathB)) { ... }
15
17
  */
16
18
  export const equals = (a, b) => {
17
19
  if (a.isClosed !== b.isClosed) {
@@ -15,11 +15,10 @@ import { create } from './create.js'
15
15
  * @param {boolean} [options.closed=false] - if the path should be open or closed
16
16
  * @param {Array} vertices - array of vertices (3D) from which to create the path
17
17
  * @returns {Path3} a new path
18
- * @function
19
- * @alias module:modeling/geometries/path3.fromVertices
18
+ * @alias module:modeling/path3.fromVertices
20
19
  *
21
20
  * @example
22
- * my newPath = fromVertices({closed: true}, [[10, 10, 10], [-10, 10, -10]])
21
+ * my newPath = path3.fromVertices({closed: true}, [[10, 10, 10], [-10, 10, -10]])
23
22
  */
24
23
  export const fromVertices = (options, vertices) => {
25
24
  const defaults = { closed: false }
@@ -2,12 +2,28 @@
2
2
  * Represents a 3D geometry consisting of a list of ordered vertices.
3
3
  *
4
4
  * @see {@link Path3} for data structure information.
5
- * @module modeling/geometries/path3
5
+ * @module modeling/path3
6
6
  *
7
7
  * @example
8
8
  * import { path3 } from '@jscad/modeling'
9
9
  * let myShape = path3.fromVertices({ closed: true }, [[0,0,0], [4,0,0], [4,3,0]])
10
10
  */
11
+
12
+ /**
13
+ * @typedef {Object} Path3
14
+ * @property {Array} vertices - list of ordered vertices
15
+ * @property {boolean} isClosed - true if the path is closed where start and end vertices are the same
16
+ * @property {Mat4} transforms - transforms to apply to the vertices, see transform()
17
+ *
18
+ * @example
19
+ * // data structure
20
+ * {
21
+ * vertices: [[0,0,0], [4,0,0], [4,3,0]],
22
+ * isClosed: true,
23
+ * transforms: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
24
+ * }
25
+ */
26
+
11
27
  export { close } from './close.js'
12
28
  export { concat } from './concat.js'
13
29
  export { create } from './create.js'
@@ -3,8 +3,10 @@
3
3
  *
4
4
  * @param {Object} object - the object to interrogate
5
5
  * @returns {boolean} true if the object matches a path3
6
- * @function
7
- * @alias module:modeling/geometries/path3.isA
6
+ * @alias module:modeling/path3.isA
7
+ *
8
+ * @example
9
+ * if (path3.isA(geometry)) { ... }
8
10
  */
9
11
  export const isA = (object) => {
10
12
  if (object && typeof object === 'object') {
@@ -5,11 +5,10 @@
5
5
  *
6
6
  * @param {Path3} geometry - the path to reverse
7
7
  * @returns {Path3} a new path
8
- * @function
9
- * @alias module:modeling/geometries/path3.reverse
8
+ * @alias module:modeling/path3.reverse
10
9
  *
11
10
  * @example
12
- * let newPath = reverse(path)
11
+ * let newPath = path3.reverse(oldPath)
13
12
  */
14
13
  export const reverse = (geometry) => {
15
14
  // NOTE: this only updates the order of the vertices
@@ -7,11 +7,10 @@ import { toVertices } from './toVertices.js'
7
7
  *
8
8
  * @param {path} geometry - the path
9
9
  * @returns {string} a representative string
10
- * @function
11
- * @alias module:modeling/geometries/path3.toString
10
+ * @alias module:modeling/path3.toString
12
11
  *
13
12
  * @example
14
- * console.out(toString(path))
13
+ * console.out(path3.toString(geometry))
15
14
  */
16
15
  export const toString = (geometry) => {
17
16
  const vertices = toVertices(geometry)
@@ -7,10 +7,9 @@ import { applyTransforms } from './applyTransforms.js'
7
7
  *
8
8
  * @param {Path3} geometry - the geometry
9
9
  * @returns {Array} an array of vertices
10
- * @function
11
- * @alias module:modeling/geometries/path3.toVertices
10
+ * @alias module:modeling/path3.toVertices
12
11
  *
13
12
  * @example
14
- * let sharedVertices = toVertices(path)
13
+ * let sharedVertices = path3.toVertices(geometry)
15
14
  */
16
15
  export const toVertices = (geometry) => applyTransforms(geometry).vertices
@@ -9,11 +9,10 @@ import * as mat4 from '../../maths/mat4/index.js'
9
9
  * @param {Mat4} matrix - the matrix to transform with
10
10
  * @param {Path3} geometry - the geometry to transform
11
11
  * @returns {Path3} a new path
12
- * @function
13
- * @alias module:modeling/geometries/path3.transform
12
+ * @alias module:modeling/path3.transform
14
13
  *
15
14
  * @example
16
- * let newPath = transform(fromZRotation(TAU / 8), path)
15
+ * let newPath = path3.transform(mat4.fromZRotation(TAU / 8), oldPath)
17
16
  */
18
17
  export const transform = (matrix, geometry) => {
19
18
  const transforms = mat4.multiply(mat4.create(), matrix, geometry.transforms)
@@ -4,14 +4,17 @@ import { isA } from './isA.js'
4
4
 
5
5
  /**
6
6
  * Determine if the given object is a valid path3.
7
+ *
7
8
  * Checks for valid vertices, and duplicate vertices.
8
9
  *
9
- * **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
10
+ * **NOTE: If the geometry is not valid, an exception will be thrown with details of the geometry error.**
10
11
  *
11
12
  * @param {Object} object - the object to interrogate
12
13
  * @throws {Error} error if the geometry is not valid
13
- * @function
14
- * @alias module:modeling/geometries/path3.validate
14
+ * @alias module:modeling/path3.validate
15
+ *
16
+ * @example
17
+ * path3.vaidate(geometry)
15
18
  */
16
19
  export const validate = (object) => {
17
20
  if (!isA(object)) {
@@ -7,7 +7,10 @@ import { reverse } from './reverse.js'
7
7
  * @param {Array} points - a list of points, where each point is an array with X and Y values
8
8
  * @param {Poly2} polygon - a 2D polygon
9
9
  * @return {number} 1 if all points are inside, 0 if some or none are inside
10
- * @alias module:modeling/geometries/poly2.arePointsInside
10
+ * @alias module:modeling/poly2.arePointsInside
11
+ *
12
+ * @example
13
+ * if (poly2.arePointsInside([[0,0], [4,0], [4,3]], geometry) { ... }
11
14
  */
12
15
  export const arePointsInside = (points, polygon) => {
13
16
  if (points.length === 0) return 0 // nothing to check
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * @param {Poly2} polygon - polygon to clone
5
5
  * @returns {Poly2} a new polygon
6
- * @alias module:modeling/geometries/poly2.clone
6
+ * @alias module:modeling/poly2.clone
7
+ *
8
+ * @example
9
+ * const newPoly = poly2.clone(oldPoly)
7
10
  */
8
11
  export const clone = (polygon) => Object.assign({}, polygon)
@@ -1,18 +1,11 @@
1
- /**
2
- * Represents a 2D polygon consisting of a list of ordered points
3
- * which is closed between start and end points.
4
- * @see https://en.wikipedia.org/wiki/Polygon
5
- * @property {Array} points - list of ordered points (2D)
6
- */
7
-
8
1
  /**
9
2
  * Creates a new polygon with initial values.
10
3
  *
11
4
  * @param {Array} [points] - list of points (2D)
12
5
  * @returns {Poly2} a new polygon
13
- * @alias module:modeling/geometries/poly2.create
6
+ * @alias module:modeling/poly2.create
14
7
  *
15
8
  * @example
16
- * let polygon = create([[0,0], [4,0], [4,3]])
9
+ * let polygon = poly2.create([[0,0], [4,0], [4,3]])
17
10
  */
18
11
  export const create = (points = []) => ({ points })
@@ -1,12 +1,24 @@
1
1
  /**
2
2
  * Represents a 2D polygon consisting of a list of ordered points.
3
- * @see {@link poly2} for data structure information.
4
- * @module modeling/geometries/poly2
3
+ * @see {@link Poly2} for data structure information.
4
+ * @module modeling/poly2
5
5
  *
6
6
  * @example
7
- * import { geometries } from '@jscad/modeling'
8
- * const p1 = geometries.poly2.create([[0,0], [4,0], [4,3]])
7
+ * import { poly2 } from '@jscad/modeling'
8
+ * const p1 = poly2.create([[0,0], [4,0], [4,3]])
9
9
  */
10
+
11
+ /**
12
+ * @typedef {Object} Poly2
13
+ * @property {Array} points - list of ordered points (2D)
14
+ *
15
+ * @example
16
+ * // data structure
17
+ * {
18
+ * points: [[0,0], [4,0], [4,3]],
19
+ * }
20
+ */
21
+
10
22
  export { arePointsInside } from './arePointsInside.js'
11
23
  export { clone } from './clone.js'
12
24
  export { create } from './create.js'
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * Determine if the given object is a 2D polygon.
3
+ *
3
4
  * @param {object} object - the object to interrogate
4
5
  * @returns {Boolean} true if the object matches a poly2
5
- * @alias module:modeling/geometries/poly2.isA
6
+ * @alias module:modeling/poly2.isA
7
+ *
8
+ * @example
9
+ * if (poly2.isA(geometry)) { ... }
6
10
  */
7
11
  export const isA = (object) => {
8
12
  if (object && typeof object === 'object') {
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * Check whether the given polygon is convex.
3
+ *
3
4
  * @param {Poly2} polygon - the polygon to interrogate
4
5
  * @returns {Boolean} true if convex
5
- * @alias module:modeling/geometries/poly2.isConvex
6
+ * @alias module:modeling/poly2.isConvex
7
+ *
8
+ * @example
9
+ * if (poly2.isConvex(geometry)) { ... }
6
10
  */
7
11
  export const isConvex = (polygon) => {
8
12
  const numPoints = polygon.points.length
@@ -3,9 +3,13 @@ import { intersect } from '../../maths/utils/intersect.js'
3
3
  /**
4
4
  * Check whether the given polygon is simple, i.e. does not intersect itself.
5
5
  * @see https://en.wikipedia.org/wiki/Simple_polygon
6
+ *
6
7
  * @param {Poly2} polygon - the polygon to interrogate
7
8
  * @returns {Boolean} true if simple
8
- * @alias module:modeling/geometries/poly2.isSimple
9
+ * @alias module:modeling/poly2.isSimple
10
+ *
11
+ * @example
12
+ * if (poly2.isSimple(geometry)) { ... }
9
13
  */
10
14
  export const isSimple = (polygon) => {
11
15
  const numPoints = polygon.points.length
@@ -5,6 +5,9 @@ import { area } from '../../maths/utils/area.js'
5
5
  *
6
6
  * @param {Poly2} polygon - the polygon to measure
7
7
  * @return {number} the area of the polygon
8
- * @alias module:modeling/geometries/poly2.measureArea
8
+ * @alias module:modeling/poly2.measureArea
9
+ *
10
+ * @example
11
+ * const area = poly2.measureArea(geometry)
9
12
  */
10
13
  export const measureArea = (polygon) => area(polygon.points)
@@ -1,9 +1,14 @@
1
1
  import * as vec2 from '../../maths/vec2/index.js'
2
2
 
3
3
  /**
4
+ * Measure the min and max bounds of the given polygon.
5
+ *
4
6
  * @param {Poly2} polygon - the polygon to measure
5
7
  * @returns {Array} an array of two vectors (2D); minimum and maximum coordinates
6
- * @alias module:modeling/geometries/poly2.measureBoundingBox
8
+ * @alias module:modeling/poly2.measureBoundingBox
9
+ *
10
+ * @example
11
+ * const bounds = poly2.measureBoundingBox(geometry)
7
12
  */
8
13
  export const measureBoundingBox = (polygon) => {
9
14
  const points = polygon.points
@@ -5,7 +5,10 @@ import { create } from './create.js'
5
5
  *
6
6
  * @param {Poly2} polygon - the polygon to reverse
7
7
  * @returns {Poly2} a new polygon
8
- * @alias module:modeling/geometries/poly2.reverse
8
+ * @alias module:modeling/poly2.reverse
9
+ *
10
+ * @example
11
+ * let newPoly = poly2.reverse(oldPoly)
9
12
  */
10
13
  export const reverse = (polygon) => {
11
14
  const points = polygon.points.slice().reverse()
@@ -1,8 +1,13 @@
1
1
  /**
2
2
  * Return the given polygon as a list of points.
3
+ *
3
4
  * NOTE: The returned array should not be modified as the points are shared with the geometry.
5
+ *
4
6
  * @param {Poly2} polygon - the polygon
5
7
  * @return {Array} list of points (2D)
6
- * @alias module:modeling/geometries/poly2.toPoints
8
+ * @alias module:modeling/poly2.toPoints
9
+ *
10
+ * @example
11
+ * const sharedPoints = poly2.toPoints(geometry)
7
12
  */
8
13
  export const toPoints = (polygon) => polygon.points
@@ -2,8 +2,12 @@ import * as vec2 from '../../maths/vec2/index.js'
2
2
 
3
3
  /**
4
4
  * Convert the given polygon to a readable string.
5
+ *
5
6
  * @param {Poly2} polygon - the polygon to convert
6
7
  * @return {String} the string representation
7
- * @alias module:modeling/geometries/poly2.toString
8
+ * @alias module:modeling/poly2.toString
9
+ *
10
+ * @example
11
+ * console.log(poly2.toString(geometry))
8
12
  */
9
13
  export const toString = (polygon) => `poly2: [${polygon.points.map(vec2.toString).join(', ')}]`
@@ -5,10 +5,14 @@ import { create } from './create.js'
5
5
 
6
6
  /**
7
7
  * Transform the given polygon using the given matrix.
8
+ *
8
9
  * @param {Mat4} matrix - the matrix to transform with
9
10
  * @param {Poly2} polygon - the polygon to transform
10
11
  * @returns {Poly2} a new polygon
11
- * @alias module:modeling/geometries/poly2.transform
12
+ * @alias module:modeling/poly2.transform
13
+ *
14
+ * @example
15
+ * let newPoly = poly2.transfrom(oldPoly)
12
16
  */
13
17
  export const transform = (matrix, polygon) => {
14
18
  const points = polygon.points.map((point) => vec2.transform(vec2.create(), point, matrix))
@@ -5,13 +5,17 @@ import { measureArea } from './measureArea.js'
5
5
 
6
6
  /**
7
7
  * Determine if the given object is a valid polygon.
8
+ *
8
9
  * Checks for valid data structure, convex polygons, and duplicate points.
9
10
  *
10
- * **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
11
+ * **NOTE: If the geometry is not valid, an exception will be thrown with details of the geometry error.**
11
12
  *
12
13
  * @param {object} object - the object to interrogate
13
14
  * @throws {Error} error if the geometry is not valid
14
- * @alias module:modeling/geometries/poly2.validate
15
+ * @alias module:modeling/poly2.validate
16
+ *
17
+ * @example
18
+ * poly2.validate(geometry)
15
19
  */
16
20
  export const validate = (object) => {
17
21
  if (!isA(object)) {
@@ -8,7 +8,10 @@ import { create } from './create.js'
8
8
  * @param {Poly3} [out] - receiving polygon
9
9
  * @param {Poly3} polygon - polygon to clone
10
10
  * @returns {Poly3} a new polygon
11
- * @alias module:modeling/geometries/poly3.clone
11
+ * @alias module:modeling/poly3.clone
12
+ *
13
+ * @example
14
+ * const newPoly = poly3.clone(oldPoly)
12
15
  */
13
16
  export const clone = (...params) => {
14
17
  let out
@@ -1,19 +1,11 @@
1
- /**
2
- * Represents a convex 3D polygon. The vertices used to initialize a polygon must
3
- * be coplanar and form a convex shape. The vertices do not have to be `vec3`
4
- * instances but they must behave similarly.
5
- * @property {Array} vertices - list of ordered vertices (3D)
6
- * @example
7
- * {"vertices": [[0,0,0], [4,0,0], [4,3,12]]}
8
- */
9
-
10
1
  /**
11
2
  * Creates a new 3D polygon with initial values.
12
3
  *
13
4
  * @param {Array} [vertices] - a list of vertices (3D)
14
5
  * @returns {Poly3} a new polygon
15
- * @alias module:modeling/geometries/poly3.create
6
+ * @alias module:modeling/poly3.create
7
+ *
16
8
  * @example
17
- * const polygon = create([[1, 0], [0, 1], [0, 0]])
9
+ * const polygon = poly3.create([[1, 0], [0, 1], [0, 0]])
18
10
  */
19
11
  export const create = (vertices = []) => ({ vertices })
@@ -2,11 +2,13 @@ import { create } from './create.js'
2
2
 
3
3
  /**
4
4
  * Create a polygon from the given vertices and plane.
5
+ *
5
6
  * NOTE: No checks are performed on the parameters.
7
+ *
6
8
  * @param {Array} vertices - list of vertices (3D)
7
9
  * @param {Plane} plane - plane of the polygon
8
10
  * @returns {Poly3} a new polygon
9
- * @alias module:modeling/geometries/poly3.fromVerticesAndPlane
11
+ * @alias module:modeling/poly3.fromVerticesAndPlane
10
12
  */
11
13
  export const fromVerticesAndPlane = (vertices, plane) => {
12
14
  const poly = create(vertices)
@@ -1,12 +1,27 @@
1
1
  /**
2
2
  * Represents a convex 3D polygon consisting of a list of ordered vertices.
3
- * @see {@link poly3} for data structure information.
4
- * @module modeling/geometries/poly3
3
+ *
4
+ * The vertices used to initialize a polygon must be coplanar and form a convex shape.
5
+ *
6
+ * @see {@link Poly3} for data structure information.
7
+ * @module modeling/poly3
8
+ *
9
+ * @example
10
+ * import { poly3 } from '@jscad/modeling'
11
+ * const polygon = poly3.create([[0,0,0], [4,0,0], [4,3,12]])
12
+ */
13
+
14
+ /**
15
+ * @typedef {Object} Poly3
16
+ * @property {Array} vertices - list of ordered vertices (3D)
5
17
  *
6
18
  * @example
7
- * import { geometries } from '@jscad/modeling'
8
- * const polygon = geometries.poly3.create([[0,0,0], [4,0,0], [4,3,12]])
19
+ * // data structure
20
+ * {
21
+ * vertices: [[0,0,0], [4,0,0], [4,3,12]]
22
+ * }
9
23
  */
24
+
10
25
  export { clone } from './clone.js'
11
26
  export { create } from './create.js'
12
27
  export { fromVerticesAndPlane } from './fromVerticesAndPlane.js'
@@ -7,7 +7,10 @@ import { create } from './create.js'
7
7
  *
8
8
  * @param {Poly3} polygon - the polygon to invert
9
9
  * @returns {Poly3} a new poly3
10
- * @alias module:modeling/geometries/poly3.invert
10
+ * @alias module:modeling/poly3.invert
11
+ *
12
+ * @example
13
+ * const newPoly = poly3.invert(oldPoly)
11
14
  */
12
15
  export const invert = (polygon) => {
13
16
  const vertices = polygon.vertices.slice().reverse()
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * Determine if the given object is a polygon.
3
+ *
3
4
  * @param {object} object - the object to interrogate
4
5
  * @returns {Boolean} true if the object matches a poly3
5
- * @alias module:modeling/geometries/poly3.isA
6
+ * @alias module:modeling/poly3.isA
7
+ *
8
+ * @example
9
+ * if (poly3.isA(geometry)) { ... }
6
10
  */
7
11
  export const isA = (object) => {
8
12
  if (object && typeof object === 'object') {
@@ -3,9 +3,13 @@ import * as vec3 from '../../maths/vec3/index.js'
3
3
 
4
4
  /**
5
5
  * Check whether the given polygon is convex.
6
+ *
6
7
  * @param {Poly3} polygon - the polygon to interrogate
7
8
  * @returns {Boolean} true if convex
8
- * @alias module:modeling/geometries/poly3.isConvex
9
+ * @alias module:modeling/poly3.isConvex
10
+ *
11
+ * @example
12
+ * if (poly3.isConvex(geometry)) { ... }
9
13
  */
10
14
  export const isConvex = (polygon) => areVerticesConvex(polygon.vertices)
11
15
 
@@ -3,9 +3,13 @@ import { plane } from './plane.js'
3
3
  /**
4
4
  * Measure the area of the given polygon.
5
5
  * @see 2000 softSurfer http://geomalgorithms.com
6
+ *
6
7
  * @param {Poly3} polygon - the polygon to measure
7
8
  * @return {number} area of the polygon
8
- * @alias module:modeling/geometries/poly3.measureArea
9
+ * @alias module:modeling/poly3.measureArea
10
+ *
11
+ * @example
12
+ * const area = poly3.measureArea(polyA)
9
13
  */
10
14
  export const measureArea = (polygon) => {
11
15
  const n = polygon.vertices.length
@@ -5,7 +5,10 @@ import * as vec3 from '../../maths/vec3/index.js'
5
5
  *
6
6
  * @param {Poly3} polygon - the polygon to measure
7
7
  * @returns {Array} an array of two vectors (3D); minimum and maximum coordinates
8
- * @alias module:modeling/geometries/poly3.measureBoundingBox
8
+ * @alias module:modeling/poly3.measureBoundingBox
9
+ *
10
+ * @example
11
+ * const bounds = poly3.measureBoundingBox(polyA)
9
12
  */
10
13
  export const measureBoundingBox = (polygon) => {
11
14
  const vertices = polygon.vertices