@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscad/modeling",
3
- "version": "3.0.3-alpha.0",
3
+ "version": "3.0.4-alpha.0",
4
4
  "description": "Constructive Solid Geometry (CSG) Library for JSCAD",
5
5
  "homepage": "https://openjscad.xyz/",
6
6
  "repository": "https://github.com/jscad/OpenJSCAD.org",
@@ -58,11 +58,10 @@
58
58
  "access": "public"
59
59
  },
60
60
  "devDependencies": {
61
- "@rollup/plugin-terser": "^0.4.3",
62
- "ava": "^4.3.3",
63
- "c8": "^8.0.0",
64
- "rollup": "^2.79.1",
65
- "rollup-plugin-banner": "^0.2.1"
61
+ "@rollup/plugin-terser": "^0.4.0",
62
+ "ava": "^6.3.0",
63
+ "c8": "^10.1.0",
64
+ "rollup": "^4.52.0"
66
65
  },
67
- "gitHead": "b0a83db054ec02ccddd9e19e51f86bf30f72a69e"
66
+ "gitHead": "1de52a2b7b6bd31134fd0b72a2842f31ecf8f237"
68
67
  }
package/rollup.config.js CHANGED
@@ -1,21 +1,25 @@
1
- import banner from 'rollup-plugin-banner'
1
+ import * as fs from 'fs'
2
+
2
3
  import terser from '@rollup/plugin-terser'
3
4
 
5
+ const {name, version, license} = JSON.parse(fs.readFileSync('package.json'))
6
+
4
7
  export default {
5
8
  input: 'src/index.js',
6
9
  output: [
7
10
  {
8
11
  file: 'dist/jscad-modeling.min.js',
9
12
  format: 'umd',
10
- name: 'jscadModeling'
13
+ name: 'jscadModeling',
14
+ banner: `/*! ${name} V${version} (${license}) */`
11
15
  },
12
16
  {
13
17
  file: 'dist/jscad-modeling.es.js',
14
- format: 'es'
18
+ format: 'es',
19
+ banner: `/*! ${name} V${version} (${license}) */`
15
20
  }
16
21
  ],
17
22
  plugins: [
18
- banner('<%= pkg.description %>\n@module <%= pkg.name %>\n@version <%= pkg.version %>\n@license <%= pkg.license %>'),
19
23
  terser({ compress: { module: true }, mangle: false, format: { comments: 'some' } })
20
24
  ]
21
25
  }
@@ -20,7 +20,7 @@ import { lengths } from './lengths.js'
20
20
  * @param {number} [options.segments=100] the number of segments to use when approximating the curve length.
21
21
  * @param {object} bezier a bezier curve.
22
22
  * @returns a number in the [0, 1] interval or NaN if the arcLength is negative or greater than the total length of the curve.
23
- * @alias module:modeling/curves/bezier.arcLengthToT
23
+ * @alias module:modeling/bezier.arcLengthToT
24
24
  */
25
25
  export const arcLengthToT = (options, bezier) => {
26
26
  const defaults = {
@@ -23,7 +23,7 @@
23
23
  *
24
24
  * @param {Array} points An array with at least 2 elements of either all numbers, or all arrays of numbers that are the same size.
25
25
  * @returns {bezier} a new bezier data object
26
- * @alias module:modeling/curves/bezier.create
26
+ * @alias module:modeling/bezier.create
27
27
  */
28
28
  export const create = (points) => {
29
29
  if (!Array.isArray(points)) throw new Error('Bezier points must be a valid array/')
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * Represents a bezier easing function.
3
3
  * @see {@link bezier} for data structure information.
4
- * @module modeling/curves/bezier
4
+ * @module modeling/bezier
5
+ *
5
6
  * @example
6
- * import { curves } from '@jscad/modeling'
7
- * const { bezier } = curves
7
+ * import { bezier } from '@jscad/modeling'
8
8
  */
9
+ export { arcLengthToT } from './arcLengthToT.js'
9
10
  export { create } from './create.js'
10
- export { valueAt } from './valueAt.js'
11
- export { tangentAt } from './tangentAt.js'
12
- export { lengths } from './lengths.js'
13
11
  export { length } from './length.js'
14
- export { arcLengthToT } from './arcLengthToT.js'
12
+ export { lengths } from './lengths.js'
13
+ export { tangentAt } from './tangentAt.js'
14
+ export { valueAt } from './valueAt.js'
@@ -11,6 +11,6 @@ import { lengths } from './lengths.js'
11
11
  * @param {number} segments the number of segments to use when approximating the curve length.
12
12
  * @param {object} bezier a bezier curve.
13
13
  * @returns an approximation of the curve's length.
14
- * @alias module:modeling/curves/bezier.length
14
+ * @alias module:modeling/bezier.length
15
15
  */
16
16
  export const length = (segments, bezier) => lengths(segments, bezier)[segments]
@@ -11,6 +11,7 @@ import { valueAt } from './valueAt.js'
11
11
  * @param {number} segments the number of segments to use when approximating the curve length.
12
12
  * @param {object} bezier a bezier curve.
13
13
  * @returns an array containing the cumulative length of the segments.
14
+ * @alias module:modeling/bezier.lengths
14
15
  */
15
16
  export const lengths = (segments, bezier) => {
16
17
  let sum = 0
@@ -25,7 +26,7 @@ export const lengths = (segments, bezier) => {
25
26
  return lengths
26
27
  }
27
28
 
28
- /**
29
+ /*
29
30
  * Calculates the Euclidean distance between two n-dimensional points.
30
31
  *
31
32
  * @example
@@ -10,7 +10,7 @@
10
10
  * @param {number} t : the position of which to calculate the bezier's tangent value; 0 < t < 1
11
11
  * @param {object} bezier : an array with at least 2 elements of either all numbers, or all arrays of numbers that are the same size.
12
12
  * @return {array | number} the tangent at the requested position.
13
- * @alias module:modeling/curves/bezier.tangentAt
13
+ * @alias module:modeling/bezier.tangentAt
14
14
  */
15
15
  export const tangentAt = (t, bezier) => {
16
16
  if (t < 0 || t > 1) {
@@ -11,7 +11,7 @@
11
11
  * @param {number} t : the position of which to calculate the value; 0 < t < 1
12
12
  * @param {object} bezier : a Bézier curve created with bezier.create().
13
13
  * @returns {array | number} the value at the requested position.
14
- * @alias module:modeling/curves/bezier.valueAt
14
+ * @alias module:modeling/bezier.valueAt
15
15
  */
16
16
  export const valueAt = (t, bezier) => {
17
17
  if (t < 0 || t > 1) {
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Curves are n-dimensional mathematical constructs that define a path from vertex 0 to vertex 1.
3
- * @module modeling/curves
3
+ * @alias module:modeling.curves
4
+ *
4
5
  * @example
5
- * import { curves } from '@jscad/modeling'
6
- * const { bezier } = curves
6
+ * import { bezier } from '@jscad/modeling'
7
7
  */
8
8
  export * as bezier from './bezier/index.js'
@@ -3,12 +3,14 @@ import * as vec2 from '../../maths/vec2/index.js'
3
3
 
4
4
  /*
5
5
  * Apply the transforms of the given geometry.
6
+ *
6
7
  * NOTE: This function must be called BEFORE exposing any data. See toOutlines().
8
+ *
7
9
  * @param {Geom2} geometry - the geometry to transform
8
10
  * @returns {Geom2} the given geometry
9
11
  *
10
12
  * @example
11
- * geometry = applyTransforms(geometry)
13
+ * const geometry = geom2.applyTransforms(geometry)
12
14
  */
13
15
  export const applyTransforms = (geometry) => {
14
16
  if (mat4.isIdentity(geometry.transforms)) return geometry
@@ -1,7 +1,11 @@
1
1
  /**
2
2
  * Performs a shallow clone of the given geometry.
3
+ *
3
4
  * @param {Geom2} geometry - the geometry to clone
4
5
  * @returns {Geom2} new geometry
5
- * @alias module:modeling/geometries/geom2.clone
6
+ * @alias module:modeling/geom2.clone
7
+ *
8
+ * @example
9
+ * const geometry = geom2.clone(geometry)
6
10
  */
7
11
  export const clone = (geometry) => Object.assign({}, geometry)
@@ -1,24 +1,14 @@
1
1
  import * as mat4 from '../../maths/mat4/index.js'
2
2
 
3
- /**
4
- * Represents a 2D geometry consisting of outlines, where each outline is an ordered list of points.
5
- * @property {Array} outlines - list of polygon outlines
6
- * @property {Mat4} transforms - transforms to apply to the geometry, see transform()
7
- * @example
8
- * // data structure
9
- * {
10
- * "outlines": [[[-1,-1],[1,-1],[1,1],[-1,1]]],
11
- * "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
12
- * }
13
- */
14
-
15
3
  /**
16
4
  * Create a new 2D geometry composed of polygon outlines.
5
+ *
17
6
  * @param {Array} [outlines] - list of outlines where each outline is an array of points
18
7
  * @returns {Geom2} a new geometry
19
- * @alias module:modeling/geometries/geom2.create
8
+ * @alias module:modeling/geom2.create
9
+ *
20
10
  * @example
21
- * let myShape = create([ [[-1,-1], [1,-1], [1,1], [-1,1]] ])
11
+ * let myShape = geom2.create([ [[-1,-1], [1,-1], [1,1], [-1,1]] ])
22
12
  */
23
13
  export const create = (outlines = []) => ({
24
14
  outlines,
@@ -26,7 +26,7 @@ const toSharedPoints = (sides) => {
26
26
  */
27
27
  const toPointMap = (sides) => {
28
28
  const pointMap = new Map()
29
- // first map to edges with shared vertices
29
+ // first map to edges with shared points
30
30
  const edges = toSharedPoints(sides)
31
31
  // construct adjacent edges map
32
32
  edges.forEach((edge) => {
@@ -41,11 +41,13 @@ const toPointMap = (sides) => {
41
41
 
42
42
  /**
43
43
  * Create a new 2D geometry from a list of sides.
44
+ *
44
45
  * @param {Array} sides - list of sides to create outlines from
45
46
  * @returns {Geom2} a new geometry
47
+ * @alias module:modeling/geom2.fromSides
46
48
  *
47
49
  * @example
48
- * let geometry = fromSides([[[0, 0], [1, 0]], [[1, 0], [1, 1]], [[1, 1], [0, 0]]])
50
+ * let geometry = geom2.fromSides([[[0, 0], [1, 0]], [[1, 0], [1, 1]], [[1, 1], [0, 0]]])
49
51
  */
50
52
  export const fromSides = (sides) => {
51
53
  const pointMap = toPointMap(sides) // {point: [edges]}
@@ -1,12 +1,28 @@
1
1
  /**
2
2
  * Represents a 2D geometry consisting of outlines, where each outline is an ordered list of points.
3
- * The outline is always closed between the first and last points.
4
- * @see {@link geom2} for data structure information.
5
- * @module modeling/geometries/geom2
3
+ *
4
+ * Each outline is always closed between the first and last points.
5
+ *
6
+ * @see {@link Geom2} for data structure information.
7
+ * @module modeling/geom2
8
+ *
9
+ * @example
10
+ * import { geom2 } from '@jscad/modeling'
11
+ * let myShape = geom2.create([ [[-1,-1], [1,-1], [1,1], [-1,1]] ])
12
+ */
13
+
14
+ /**
15
+ * @typedef Geom2
16
+ * @type {Object}
17
+ * @property {Array} outlines - list of outlines, each outline is an ordered list of points
18
+ * @property {Mat4} transforms - transforms to apply to the polygons, see transform()
6
19
  *
7
20
  * @example
8
- * import { geometries } from '@jscad/modeling'
9
- * let myShape = geometries.geom2.create([ [[-1,-1], [1,-1], [1,1], [-1,1]] ])
21
+ * // data structure
22
+ * {
23
+ * "outlines": [[[-1,-1],[1,-1],[1,1],[-1,1]]],
24
+ * "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]
25
+ * }
10
26
  */
11
27
  export { clone } from './clone.js'
12
28
  export { create } from './create.js'
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * Determine if the given object is a 2D geometry.
3
+ *
3
4
  * @param {object} object - the object to interrogate
4
5
  * @returns {Boolean} true, if the object matches a geom2 based object
5
- * @alias module:modeling/geometries/geom2.isA
6
+ * @alias module:modeling/geom2.isA
7
+ *
8
+ * @example
9
+ * const geometry = geom2.isA(geometry)
6
10
  */
7
11
  export const isA = (object) => {
8
12
  if (object && typeof object === 'object') {
@@ -3,13 +3,15 @@ import { toOutlines } from './toOutlines.js'
3
3
 
4
4
  /**
5
5
  * Reverses the given geometry so that the outline points are flipped in the opposite order.
6
+ *
6
7
  * This swaps the left (interior) and right (exterior) edges.
8
+ *
7
9
  * @param {Geom2} geometry - the geometry to reverse
8
10
  * @returns {Geom2} the new reversed geometry
9
- * @alias module:modeling/geometries/geom2.reverse
11
+ * @alias module:modeling/geom2.reverse
10
12
  *
11
13
  * @example
12
- * let newGeometry = reverse(geometry)
14
+ * let newGeometry = geom2.reverse(geometry)
13
15
  */
14
16
  export const reverse = (geometry) => {
15
17
  const outlines = toOutlines(geometry)
@@ -2,9 +2,10 @@ import { applyTransforms } from './applyTransforms.js'
2
2
 
3
3
  /**
4
4
  * Create the outline(s) of the given geometry.
5
+ *
5
6
  * @param {Geom2} geometry - geometry to create outlines from
6
7
  * @returns {Array} an array of outlines, where each outline is an array of ordered points
7
- * @alias module:modeling/geometries/geom2.toOutlines
8
+ * @alias module:modeling/geom2.toOutlines
8
9
  *
9
10
  * @example
10
11
  * let geometry = subtract(rectangle({size: [5, 5]}), rectangle({size: [3, 3]}))
@@ -2,14 +2,17 @@ import { toOutlines } from './toOutlines.js'
2
2
 
3
3
  /**
4
4
  * Produces an array of points from the given geometry.
5
+ *
5
6
  * The returned array should not be modified as the points are shared with the geometry.
7
+ *
6
8
  * NOTE: The points returned do NOT define an order. Use toOutlines() for ordered points.
9
+ *
7
10
  * @param {Geom2} geometry - the geometry
8
11
  * @returns {Array} an array of points
9
- * @alias module:modeling/geometries/geom2.toPoints
12
+ * @alias module:modeling/geom2.toPoints
10
13
  *
11
14
  * @example
12
- * let sharedPoints = toPoints(geometry)
15
+ * let sharedPoints = geom2.toPoints(geometry)
13
16
  */
14
17
  export const toPoints = (geometry) => {
15
18
  const points = []
@@ -2,14 +2,15 @@ import { toOutlines } from './toOutlines.js'
2
2
 
3
3
  /**
4
4
  * Produces an array of sides from the given geometry.
5
- * The returned array should not be modified as the data is shared with the geometry.
5
+ *
6
6
  * NOTE: The sides returned do NOT define an order. Use toOutlines() for ordered points.
7
+ *
7
8
  * @param {Geom2} geometry - the geometry
8
9
  * @returns {Array} an array of sides
9
- * @alias module:modeling/geometries/geom2.toSides
10
+ * @alias module:modeling/geom2.toSides
10
11
  *
11
12
  * @example
12
- * let sharedSides = toSides(geometry)
13
+ * let sharedSides = geom2.toSides(geometry)
13
14
  */
14
15
  export const toSides = (geometry) => {
15
16
  const sides = []
@@ -4,12 +4,13 @@ import { toOutlines } from './toOutlines.js'
4
4
 
5
5
  /**
6
6
  * Create a string representing the contents of the given geometry.
7
+ *
7
8
  * @param {Geom2} geometry - the geometry
8
9
  * @returns {string} a representative string
9
- * @alias module:modeling/geometries/geom2.toString
10
+ * @alias module:modeling/geom2.toString
10
11
  *
11
12
  * @example
12
- * console.out(toString(geometry))
13
+ * console.out(geom2.toString(geometry))
13
14
  */
14
15
  export const toString = (geometry) => {
15
16
  const outlines = toOutlines(geometry)
@@ -4,15 +4,17 @@ import { reverse } from './reverse.js'
4
4
 
5
5
  /**
6
6
  * Transform the given geometry using the given matrix.
7
+ *
7
8
  * This is a lazy transform of the outlines, as this function only adjusts the transforms.
8
9
  * The transforms are applied when accessing the outlines via toOutlines().
10
+ *
9
11
  * @param {Mat4} matrix - the matrix to transform with
10
12
  * @param {Geom2} geometry - the geometry to transform
11
13
  * @returns {Geom2} a new geometry
12
- * @alias module:modeling/geometries/geom2.transform
14
+ * @alias module:modeling/geom2.transform
13
15
  *
14
16
  * @example
15
- * let newGeometry = transform(fromZRotation(TAU / 4), geometry)
17
+ * let newGeometry = geom2.transform(fromZRotation(TAU / 4), geometry)
16
18
  */
17
19
  export const transform = (matrix, geometry) => {
18
20
  const transforms = mat4.multiply(mat4.create(), matrix, geometry.transforms)
@@ -7,13 +7,17 @@ import { toOutlines } from './toOutlines.js'
7
7
 
8
8
  /**
9
9
  * Determine if the given object is a valid geom2.
10
+ *
10
11
  * Checks for closedness, self-edges, and valid data points.
11
12
  *
12
- * **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
13
+ * **NOTE: If the geometry is not valid, an exception will be thrown with details of the geometry error.**
13
14
  *
14
15
  * @param {object} object - the object to interrogate
15
16
  * @throws {Error} error if the geometry is not valid
16
- * @alias module:modeling/geometries/geom2.validate
17
+ * @alias module:modeling/geom2.validate
18
+ *
19
+ * @example
20
+ * const geometry = geom2.validate(geometry)
17
21
  */
18
22
  export const validate = (object) => {
19
23
  if (!isA(object)) {
@@ -1,7 +1,11 @@
1
1
  /**
2
2
  * Performs a shallow clone of the given geometry.
3
+ *
3
4
  * @param {Geom3} geometry - the geometry to clone
4
5
  * @returns {Geom3} a new geometry
5
- * @alias module:modeling/geometries/geom3.clone
6
+ * @alias module:modeling/geom3.clone
7
+ *
8
+ * @example
9
+ * let clone = geom3.clone(geometry)
6
10
  */
7
11
  export const clone = (geometry) => Object.assign({}, geometry)
@@ -1,27 +1,13 @@
1
1
  import * as mat4 from '../../maths/mat4/index.js'
2
2
 
3
- /**
4
- * Represents a 3D geometry consisting of a list of polygons.
5
- * @property {Array} polygons - list of polygons, each polygon containing three or more vertices
6
- * @property {Mat4} transforms - transforms to apply to the polygons, see transform()
7
- * @example
8
- * {
9
- * "polygons": [
10
- * {"vertices": [[-1,-1,-1], [-1,-1,1], [-1,1,1], [-1,1,-1]]},
11
- * {"vertices": [[1,-1,-1], [1,1,-1], [1,1,1], [1,-1,1]]},
12
- * {"vertices": [[-1,-1,-1], [1,-1,-1], [1,-1,1], [-1,-1,1]]},
13
- * {"vertices": [[-1,1,-1], [-1,1,1], [1,1,1], [1,1,-1]]},
14
- * {"vertices": [[-1,-1,-1], [-1,1,-1], [1,1,-1], [1,-1,-1]]},
15
- * {"vertices": [[-1,-1,1], [1,-1,1], [1,1,1], [-1,1,1]]}
16
- * ],
17
- * "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
18
- * }
19
- */
20
-
21
3
  /**
22
4
  * Create a new 3D geometry composed of the given polygons.
5
+ *
23
6
  * @param {Array} [polygons] - list of polygons, or undefined
24
7
  * @returns {Geom3} a new geometry
25
- * @alias module:modeling/geometries/geom3.create
8
+ * @alias module:modeling/geom3.create
9
+ *
10
+ * @example
11
+ * let geometry = geom3.create()
26
12
  */
27
13
  export const create = (polygons = []) => ({ polygons, transforms: mat4.create() })
@@ -8,9 +8,21 @@ import { create } from './create.js'
8
8
  * The list of vertices should contain sub-arrays, each defining a single polygon of vertices.
9
9
  * In addition, the vertices should follow the right-hand rule for rotation in order to
10
10
  * define an external facing polygon.
11
+ *
11
12
  * @param {Array} listOfLists - list of lists, where each list is a set of vertices to construct a polygon
12
13
  * @returns {Geom3} a new geometry
13
- * @alias module:modeling/geometries/geom3.fromVertices
14
+ * @alias module:modeling/geom3.fromVertices
15
+ *
16
+ * @example
17
+ * let vertices = [
18
+ * [[-1,-1,-1], [-1,-1,1], [-1,1,1], [-1,1,-1]],
19
+ * [[1,-1,-1], [1,1,-1], [1,1,1], [1,-1,1]],
20
+ * [[-1,-1,-1], [1,-1,-1], [1,-1,1], [-1,-1,1]]
21
+ * [[-1,1,-1], [-1,1,1], [1,1,1], [1,1,-1]],
22
+ * [[-1,-1,-1], [-1,1,-1], [1,1,-1], [1,-1,-1]],
23
+ * [[-1,-1,1], [1,-1,1], [1,1,1], [-1,1,1]]
24
+ * ]
25
+ * let geometry = geom3.fromVertices(vertices)
14
26
  */
15
27
  export const fromVertices = (listOfLists) => {
16
28
  if (!Array.isArray(listOfLists)) {
@@ -7,7 +7,7 @@ import * as poly3 from '../poly3/index.js'
7
7
  *
8
8
  * @param {Array} uniqueVertices - list of vertices to construct convex 3D geometry
9
9
  * @returns {geom3} a new geometry
10
- * @alias module:modeling/geometries/geom3.fromVerticesConvex
10
+ * @alias module:modeling/geom3.fromVerticesConvex
11
11
  */
12
12
  export const fromVerticesConvex = (uniqueVertices) => {
13
13
  if (!Array.isArray(uniqueVertices)) {
@@ -4,6 +4,7 @@ export { fromVertices } from './fromVertices.js'
4
4
  export { fromVerticesConvex } from './fromVerticesConvex.js'
5
5
  export { invert } from './invert.js'
6
6
  export { isA } from './isA.js'
7
+ export { isConvex } from './isConvex.js'
7
8
  export { toPolygons } from './toPolygons.js'
8
9
  export { toString } from './toString.js'
9
10
  export { toVertices } from './toVertices.js'
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Represents a 3D geometry consisting of a list of polygons.
3
- * @see {@link geom3} for data structure information.
4
- * @module modeling/geometries/geom3
3
+ *
4
+ * @see {@link Geom3} for data structure information
5
+ * @module modeling/geom3
5
6
  *
6
7
  * @example
7
- * import { geometries } from '@jscad/modeling'
8
- * const myShape = geometries.geom3.fromVertices([
8
+ * import { geom3 } from '@jscad/modeling'
9
+ * const myShape = geom3.fromVertices([
9
10
  * [[-1,-1,-1], [-1,-1,1], [-1,1,1], [-1,1,-1]],
10
11
  * [[1,-1,-1], [1,1,-1], [1,1,1], [1,-1,1]],
11
12
  * [[-1,-1,-1], [1,-1,-1], [1,-1,1], [-1,-1,1]]
@@ -14,12 +15,33 @@
14
15
  * [[-1,-1,1], [1,-1,1], [1,1,1], [-1,1,1]]
15
16
  * ])
16
17
  */
18
+
19
+ /**
20
+ * @typedef Geom3
21
+ * @type {Object}
22
+ * @property {Array} polygons - list of polygons, each polygon containing three or more vertices
23
+ * @property {Mat4} transforms - transforms to apply to the polygons, see transform()
24
+ *
25
+ * @example
26
+ * {
27
+ * "polygons": [
28
+ * {"vertices": [[-1,-1,-1], [-1,-1,1], [-1,1,1], [-1,1,-1]]},
29
+ * {"vertices": [[1,-1,-1], [1,1,-1], [1,1,1], [1,-1,1]]},
30
+ * {"vertices": [[-1,-1,-1], [1,-1,-1], [1,-1,1], [-1,-1,1]]},
31
+ * {"vertices": [[-1,1,-1], [-1,1,1], [1,1,1], [1,1,-1]]},
32
+ * {"vertices": [[-1,-1,-1], [-1,1,-1], [1,1,-1], [1,-1,-1]]},
33
+ * {"vertices": [[-1,-1,1], [1,-1,1], [1,1,1], [-1,1,1]]}
34
+ * ],
35
+ * "transforms": [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],
36
+ * }
37
+ */
17
38
  export { clone } from './clone.js'
18
39
  export { create } from './create.js'
19
40
  export { fromVertices } from './fromVertices.js'
20
41
  export { fromVerticesConvex } from './fromVerticesConvex.js'
21
42
  export { invert } from './invert.js'
22
43
  export { isA } from './isA.js'
44
+ export { isConvex } from './isConvex.js'
23
45
  export { toPolygons } from './toPolygons.js'
24
46
  export { toString } from './toString.js'
25
47
  export { toVertices } from './toVertices.js'
@@ -5,9 +5,13 @@ import { toPolygons } from './toPolygons.js'
5
5
 
6
6
  /**
7
7
  * Invert the given geometry, transposing solid and empty space.
8
+ *
8
9
  * @param {Geom3} geometry - the geometry to invert
9
10
  * @returns {Geom3} a new geometry
10
- * @alias module:modeling/geometries/geom3.invert
11
+ * @alias module:modeling/geom3.invert
12
+ *
13
+ * @example
14
+ * let inverted = geom3.invert(geometry)
11
15
  */
12
16
  export const invert = (geometry) => {
13
17
  const polygons = toPolygons(geometry)
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * Determine if the given object is a 3D geometry.
3
+ *
3
4
  * @param {object} object - the object to interrogate
4
5
  * @returns {Boolean} true if the object matches a geom3
5
- * @alias module:modeling/geometries/geom3.isA
6
+ * @alias module:modeling/geom3.isA
7
+ *
8
+ * @example
9
+ * if (geom3.isA(geometry)) { ... }
6
10
  */
7
11
  export const isA = (object) => {
8
12
  if (object && typeof object === 'object') {
@@ -0,0 +1,3 @@
1
+ import type { Geom3 } from './type.d.ts'
2
+
3
+ export function isConvex(geometry: Geom3): boolean