@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.
- package/CHANGELOG.md +17 -0
- package/dist/jscad-modeling.es.js +2 -7
- package/dist/jscad-modeling.min.js +2 -7
- package/package.json +6 -7
- package/rollup.config.js +8 -4
- package/src/curves/bezier/arcLengthToT.js +1 -1
- package/src/curves/bezier/create.js +1 -1
- package/src/curves/bezier/index.js +7 -7
- package/src/curves/bezier/length.js +1 -1
- package/src/curves/bezier/lengths.js +2 -1
- package/src/curves/bezier/tangentAt.js +1 -1
- package/src/curves/bezier/valueAt.js +1 -1
- package/src/curves/index.js +3 -3
- package/src/geometries/geom2/applyTransforms.js +3 -1
- package/src/geometries/geom2/clone.js +5 -1
- package/src/geometries/geom2/create.js +4 -14
- package/src/geometries/geom2/fromSides.js +4 -2
- package/src/geometries/geom2/index.js +21 -5
- package/src/geometries/geom2/isA.js +5 -1
- package/src/geometries/geom2/reverse.js +4 -2
- package/src/geometries/geom2/toOutlines.js +2 -1
- package/src/geometries/geom2/toPoints.js +5 -2
- package/src/geometries/geom2/toSides.js +4 -3
- package/src/geometries/geom2/toString.js +3 -2
- package/src/geometries/geom2/transform.js +4 -2
- package/src/geometries/geom2/validate.js +6 -2
- package/src/geometries/geom3/clone.js +5 -1
- package/src/geometries/geom3/create.js +5 -19
- package/src/geometries/geom3/fromVertices.js +13 -1
- package/src/geometries/geom3/fromVerticesConvex.js +1 -1
- package/src/geometries/geom3/index.d.ts +1 -0
- package/src/geometries/geom3/index.js +26 -4
- package/src/geometries/geom3/invert.js +5 -1
- package/src/geometries/geom3/isA.js +5 -1
- package/src/geometries/geom3/isConvex.d.ts +3 -0
- package/src/geometries/geom3/isConvex.js +65 -0
- package/src/geometries/geom3/isConvex.test.js +44 -0
- package/src/geometries/geom3/toPolygons.js +4 -2
- package/src/geometries/geom3/toString.js +3 -2
- package/src/geometries/geom3/toVertices.js +8 -4
- package/src/geometries/geom3/transform.js +5 -2
- package/src/geometries/geom3/validate.js +6 -2
- package/src/geometries/index.js +9 -7
- package/src/geometries/path2/appendArc.js +7 -5
- package/src/geometries/path2/appendArc.test.js +11 -15
- package/src/geometries/path2/appendBezier.js +6 -4
- package/src/geometries/path2/appendPoints.js +4 -2
- package/src/geometries/path2/applyTransforms.js +3 -0
- package/src/geometries/path2/clone.js +5 -1
- package/src/geometries/path2/close.js +5 -1
- package/src/geometries/path2/concat.js +3 -2
- package/src/geometries/path2/create.js +4 -15
- package/src/geometries/path2/equals.js +12 -7
- package/src/geometries/path2/fromPoints.js +5 -3
- package/src/geometries/path2/index.js +21 -4
- package/src/geometries/path2/isA.js +5 -1
- package/src/geometries/path2/reverse.js +4 -2
- package/src/geometries/path2/toPoints.js +5 -3
- package/src/geometries/path2/toString.js +3 -2
- package/src/geometries/path2/transform.js +4 -2
- package/src/geometries/path2/validate.js +5 -1
- package/src/geometries/path3/applyTransforms.js +1 -1
- package/src/geometries/path3/close.js +4 -2
- package/src/geometries/path3/concat.js +2 -3
- package/src/geometries/path3/create.js +4 -20
- package/src/geometries/path3/equals.js +4 -2
- package/src/geometries/path3/fromVertices.js +2 -3
- package/src/geometries/path3/index.js +17 -1
- package/src/geometries/path3/isA.js +4 -2
- package/src/geometries/path3/reverse.js +2 -3
- package/src/geometries/path3/toString.js +2 -3
- package/src/geometries/path3/toVertices.js +2 -3
- package/src/geometries/path3/transform.js +2 -3
- package/src/geometries/path3/validate.js +6 -3
- package/src/geometries/poly2/arePointsInside.js +4 -1
- package/src/geometries/poly2/clone.js +4 -1
- package/src/geometries/poly2/create.js +2 -9
- package/src/geometries/poly2/index.js +16 -4
- package/src/geometries/poly2/isA.js +5 -1
- package/src/geometries/poly2/isConvex.js +5 -1
- package/src/geometries/poly2/isSimple.js +5 -1
- package/src/geometries/poly2/measureArea.js +4 -1
- package/src/geometries/poly2/measureBoundingBox.js +6 -1
- package/src/geometries/poly2/reverse.js +4 -1
- package/src/geometries/poly2/toPoints.js +6 -1
- package/src/geometries/poly2/toString.js +5 -1
- package/src/geometries/poly2/transform.js +5 -1
- package/src/geometries/poly2/validate.js +6 -2
- package/src/geometries/poly3/clone.js +4 -1
- package/src/geometries/poly3/create.js +3 -11
- package/src/geometries/poly3/fromVerticesAndPlane.js +3 -1
- package/src/geometries/poly3/index.js +19 -4
- package/src/geometries/poly3/invert.js +4 -1
- package/src/geometries/poly3/isA.js +5 -1
- package/src/geometries/poly3/isConvex.js +5 -1
- package/src/geometries/poly3/measureArea.js +5 -1
- package/src/geometries/poly3/measureBoundingBox.js +4 -1
- package/src/geometries/poly3/measureBoundingSphere.js +4 -3
- package/src/geometries/poly3/measureSignedVolume.js +6 -1
- package/src/geometries/poly3/plane.js +6 -0
- package/src/geometries/poly3/toString.js +5 -1
- package/src/geometries/poly3/toVertices.js +6 -1
- package/src/geometries/poly3/transform.js +5 -1
- package/src/geometries/poly3/validate.js +6 -2
- package/src/geometries/slice/calculatePlane.js +3 -3
- package/src/geometries/slice/clone.js +4 -1
- package/src/geometries/slice/create.js +5 -10
- package/src/geometries/slice/equals.js +5 -1
- package/src/geometries/slice/fromGeom2.js +1 -1
- package/src/geometries/slice/fromVertices.js +3 -3
- package/src/geometries/slice/index.js +19 -4
- package/src/geometries/slice/isA.js +5 -1
- package/src/geometries/slice/reverse.js +5 -2
- package/src/geometries/slice/toEdges.js +5 -3
- package/src/geometries/slice/toPolygons.js +5 -1
- package/src/geometries/slice/toString.js +5 -1
- package/src/geometries/slice/toVertices.js +5 -3
- package/src/geometries/slice/transform.js +4 -3
- package/src/geometries/slice/validate.js +3 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +4 -0
- package/src/maths/constants.js +11 -7
- package/src/maths/index.js +2 -1
- package/src/maths/mat4/isOnlyTransformScale.js +1 -1
- package/src/operations/booleans/index.js +2 -0
- package/src/operations/booleans/intersect.js +0 -1
- package/src/operations/booleans/scission.js +0 -1
- package/src/operations/booleans/trees/splitLineSegmentByPlane.js +1 -4
- package/src/operations/booleans/trees/splitPolygonByPlane.test.js +138 -0
- package/src/operations/booleans/unionGeom3.test.js +35 -0
- package/src/operations/extrusions/extrudeFromSlices.js +15 -5
- package/src/operations/extrusions/extrudeRotate.js +2 -1
- package/src/operations/extrusions/extrudeRotate.test.js +34 -0
- package/src/operations/extrusions/extrudeWalls.test.js +60 -0
- package/src/operations/minkowski/index.d.ts +1 -0
- package/src/operations/minkowski/index.js +15 -0
- package/src/operations/minkowski/minkowskiSum.d.ts +4 -0
- package/src/operations/minkowski/minkowskiSum.js +223 -0
- package/src/operations/minkowski/minkowskiSum.test.js +199 -0
- package/src/operations/modifiers/reTesselateCoplanarPolygons.js +10 -3
- package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +36 -1
- package/src/operations/modifiers/retessellate.js +4 -2
- package/src/operations/modifiers/snap.test.js +24 -15
- package/src/operations/offsets/offsetGeom3.test.js +5 -7
- package/src/primitives/arc.js +2 -2
- package/src/primitives/arc.test.js +104 -113
- package/src/utils/flatten.js +1 -1
- package/src/utils/flatten.test.js +94 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as vec4 from '../../maths/vec4/index.js'
|
|
2
|
-
|
|
3
1
|
const cache = new WeakMap()
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -8,7 +6,10 @@ const cache = new WeakMap()
|
|
|
8
6
|
* @param {Vec4} out - receiving vector
|
|
9
7
|
* @param {Poly3} polygon - the polygon to measure
|
|
10
8
|
* @returns {Vec4} the computed bounding sphere; center vertex (3D) and radius
|
|
11
|
-
* @alias module:modeling/
|
|
9
|
+
* @alias module:modeling/poly3.measureBoundingSphere
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const bounds = poly2.measureBoundingSphere(polyA)
|
|
12
13
|
*/
|
|
13
14
|
export const measureBoundingSphere = (out, polygon) => {
|
|
14
15
|
const vertices = polygon.vertices
|
|
@@ -2,12 +2,17 @@ import * as vec3 from '../../maths/vec3/index.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Measure the signed volume of the given polygon, which must be convex.
|
|
5
|
+
*
|
|
5
6
|
* The volume is that formed by the tetrahedron connected to the axis [0,0,0],
|
|
6
7
|
* and will be positive or negative based on the rotation of the vertices.
|
|
7
8
|
* @see http://chenlab.ece.cornell.edu/Publication/Cha/icip01_Cha.pdf
|
|
9
|
+
*
|
|
8
10
|
* @param {Poly3} polygon - the polygon to measure
|
|
9
11
|
* @return {number} volume of the polygon
|
|
10
|
-
* @alias module:modeling/
|
|
12
|
+
* @alias module:modeling/poly3.measureSignedVolume
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const volume = poly3.measureSignedVolumne(polyA)
|
|
11
16
|
*/
|
|
12
17
|
export const measureSignedVolume = (polygon) => {
|
|
13
18
|
let signedVolume = 0
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import * as mplane from '../../maths/plane/index.js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Determine the plane of the given polygon.
|
|
5
|
+
*
|
|
6
|
+
* @param {Poly3} polygon - the polygon of which to fetch the plane
|
|
7
|
+
* @alias module:modeling/poly3.plane
|
|
8
|
+
*/
|
|
3
9
|
export const plane = (polygon) => {
|
|
4
10
|
if (!polygon.plane) {
|
|
5
11
|
polygon.plane = mplane.fromPoints(mplane.create(), ...polygon.vertices)
|
|
@@ -2,8 +2,12 @@ import * as vec3 from '../../maths/vec3/index.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Convert the given polygon to a readable string.
|
|
5
|
+
*
|
|
5
6
|
* @param {Poly3} polygon - the polygon to convert
|
|
6
7
|
* @return {String} the string representation
|
|
7
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/poly3.toString
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* console.log(poly3.toString(polyA))
|
|
8
12
|
*/
|
|
9
13
|
export const toString = (polygon) => `poly3: [${polygon.vertices.map(vec3.toString).join(', ')}]`
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Return the given polygon as a list of vertices.
|
|
3
|
+
*
|
|
3
4
|
* NOTE: The returned array should not be modified as the vertices are shared with the geometry.
|
|
5
|
+
*
|
|
4
6
|
* @param {Poly3} polygon - the polygon
|
|
5
7
|
* @return {Array} list of vertices (3D)
|
|
6
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/poly3.toVertices
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const sharedVertices = poly3.toVertices(polyA)
|
|
7
12
|
*/
|
|
8
13
|
export const toVertices = (polygon) => polygon.vertices
|
|
@@ -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 {Poly3} polygon - the polygon to transform
|
|
10
11
|
* @returns {Poly3} a new polygon
|
|
11
|
-
* @alias module:modeling/
|
|
12
|
+
* @alias module:modeling/poly3.transform
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const newPoly = poly3.transform(oldPoly)
|
|
12
16
|
*/
|
|
13
17
|
export const transform = (matrix, polygon) => {
|
|
14
18
|
const vertices = polygon.vertices.map((vertex) => vec3.transform(vec3.create(), vertex, matrix))
|
|
@@ -9,13 +9,17 @@ import { plane } from './plane.js'
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Determine if the given object is a valid polygon.
|
|
12
|
+
*
|
|
12
13
|
* Checks for valid data structure, convex polygons, and duplicate vertices.
|
|
13
14
|
*
|
|
14
|
-
* **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
|
|
15
|
+
* **NOTE: If the geometry is not valid, an exception will be thrown with details of the geometry error.**
|
|
15
16
|
*
|
|
16
17
|
* @param {object} object - the object to interrogate
|
|
17
18
|
* @throws {Error} error if the geometry is not valid
|
|
18
|
-
* @alias module:modeling/
|
|
19
|
+
* @alias module:modeling/poly3.validate
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* poly3.validate(geometry)
|
|
19
23
|
*/
|
|
20
24
|
export const validate = (object) => {
|
|
21
25
|
if (!isA(object)) {
|
|
@@ -3,13 +3,13 @@ import * as vec3 from '../../maths/vec3/index.js'
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculate the plane of the given slice.
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @param {Slice} slice - the slice
|
|
8
8
|
* @returns {Plane} the plane of the slice
|
|
9
|
-
* @alias module:modeling/
|
|
9
|
+
* @alias module:modeling/slice.calculatePlane
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
*
|
|
12
|
+
* const plane = slice.calculatePlane(sliceA)
|
|
13
13
|
*/
|
|
14
14
|
export const calculatePlane = (slice) => {
|
|
15
15
|
if (slice.contours.length < 1) {
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param {Slice} slice - slice to clone
|
|
6
6
|
* @returns {Slice} a new slice
|
|
7
|
-
* @alias module:modeling/
|
|
7
|
+
* @alias module:modeling/slice.clone
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const newSlice = slice.clone(oldSlice)
|
|
8
11
|
*/
|
|
9
12
|
export const clone = (slice) => Object.assign({}, slice)
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a 3D geometry consisting of a list of contours,
|
|
3
|
-
* where each contour consists of a list of planar vertices.
|
|
4
|
-
* @property {Array} contours - list of contours, each contour containing a list of 3D vertices
|
|
5
|
-
* @example
|
|
6
|
-
* {"contours": [[[0,0,1], [4,0,1], [4,3,1]]]}
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
1
|
/**
|
|
10
2
|
* Creates a new slice from the given contours.
|
|
11
3
|
*
|
|
4
|
+
* NOTE: The slice (and all vertices) are assumed to be planar from the beginning.
|
|
5
|
+
*
|
|
12
6
|
* @param {Array} [contours] - a list of contours, where each contour contains a list of vertices (3D)
|
|
13
7
|
* @returns {Slice} a new slice
|
|
14
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/slice.create
|
|
9
|
+
*
|
|
15
10
|
* @example
|
|
16
|
-
* const slice = create([ [[0,0,1], [4,0,1], [4,3,1]] ])
|
|
11
|
+
* const slice = slice.create([ [[0,0,1], [4,0,1], [4,3,1]] ])
|
|
17
12
|
*/
|
|
18
13
|
export const create = (contours = []) => ({ contours })
|
|
@@ -2,10 +2,14 @@ import * as vec3 from '../../maths/vec3/index.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Determine if the given slices have the same contours.
|
|
5
|
+
*
|
|
5
6
|
* @param {Slice} a - the first slice to compare
|
|
6
7
|
* @param {Slice} b - the second slice to compare
|
|
7
8
|
* @returns {Boolean} true if the slices are equal
|
|
8
|
-
* @alias module:modeling/
|
|
9
|
+
* @alias module:modeling/slice.equals
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* if (slice.equals(sliceA, sliceB)) { ... }
|
|
9
13
|
*/
|
|
10
14
|
export const equals = (a, b) => {
|
|
11
15
|
if (a.contours.length !== b.contours.length) {
|
|
@@ -8,7 +8,7 @@ import { create } from './create.js'
|
|
|
8
8
|
*
|
|
9
9
|
* @param {object} geometry - the 2D geometry to create a slice from
|
|
10
10
|
* @returns {Slice} a new slice
|
|
11
|
-
* @alias module:modeling/
|
|
11
|
+
* @alias module:modeling/slice.fromGeom2
|
|
12
12
|
*/
|
|
13
13
|
export const fromGeom2 = (geometry) => {
|
|
14
14
|
// Convert from 2D points to 3D vertices
|
|
@@ -3,11 +3,11 @@ import * as vec3 from '../../maths/vec3/index.js'
|
|
|
3
3
|
import { create } from './create.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Create a slice from the given vertices.
|
|
6
|
+
* Create a slice with a single contour from the given vertices.
|
|
7
7
|
*
|
|
8
8
|
* @param {Array} vertices - list of vertices, where each vertex is either 2D or 3D
|
|
9
9
|
* @returns {Slice} a new slice
|
|
10
|
-
* @alias module:modeling/
|
|
10
|
+
* @alias module:modeling/slice.fromVertices
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* const vertices = [
|
|
@@ -15,7 +15,7 @@ import { create } from './create.js'
|
|
|
15
15
|
* [0, 10, 3],
|
|
16
16
|
* [0, 10, 6]
|
|
17
17
|
* ]
|
|
18
|
-
* const slice = fromVertices(vertices)
|
|
18
|
+
* const slice = slice.fromVertices(vertices)
|
|
19
19
|
*/
|
|
20
20
|
export const fromVertices = (vertices) => {
|
|
21
21
|
if (!Array.isArray(vertices)) throw new Error('the given vertices must be an array')
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a 3D geometry consisting of a list of contours, where each contour consists of a list of planar vertices.
|
|
3
|
-
* @see {@link
|
|
4
|
-
* @module modeling/
|
|
3
|
+
* @see {@link Slice} for data structure information.
|
|
4
|
+
* @module modeling/slice
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* import {
|
|
8
|
-
* const slice =
|
|
7
|
+
* import { slice } from '@jscad/modeling'
|
|
8
|
+
* const slice = slice.create([[[0,0,0], [4,0,0], [4,3,12]]])
|
|
9
9
|
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef Slice
|
|
13
|
+
* @type {Object}
|
|
14
|
+
* @property {Array} contours - list of contours, each contour containing a list of 3D vertices
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // data structure
|
|
18
|
+
* {
|
|
19
|
+
* contours: [
|
|
20
|
+
* [[0,0,1], [4,0,1], [4,3,1]]
|
|
21
|
+
* ]
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
|
|
10
25
|
export { calculatePlane } from './calculatePlane.js'
|
|
11
26
|
export { clone } from './clone.js'
|
|
12
27
|
export { create } from './create.js'
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Determine if the given object is a slice.
|
|
3
|
+
*
|
|
3
4
|
* @param {Slice} object - the object to interrogate
|
|
4
5
|
* @returns {Boolean} true if the object matches a slice
|
|
5
|
-
* @alias module:modeling/
|
|
6
|
+
* @alias module:modeling/slice.isA
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* if (slice.isA(geometry)) { ... }
|
|
6
10
|
*/
|
|
7
11
|
export const isA = (object) => {
|
|
8
12
|
if (object && typeof object === 'object') {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { create } from './create.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Reverse the
|
|
4
|
+
* Reverse the contours of the given slice.
|
|
5
5
|
*
|
|
6
6
|
* @param {Slice} slice - slice to reverse
|
|
7
7
|
* @returns {Slice} reverse of the slice
|
|
8
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/slice.reverse
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const newSlice = slice.reverse(oldSlice)
|
|
9
12
|
*/
|
|
10
13
|
export const reverse = (slice) => {
|
|
11
14
|
// reverse each contour
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Produces an array of edges from the given slice.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* NOTE: The returned array should not be modified as the data is shared with the slice.
|
|
5
|
+
*
|
|
4
6
|
* @param {Slice} slice - the slice
|
|
5
7
|
* @returns {Array} an array of edges, each edge contains an array of two vertices (3D)
|
|
6
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/slice.toEdges
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
9
|
-
* let sharedEdges = toEdges(slice)
|
|
11
|
+
* let sharedEdges = slice.toEdges(slice)
|
|
10
12
|
*/
|
|
11
13
|
export const toEdges = (slice) => {
|
|
12
14
|
const edges = []
|
|
@@ -5,9 +5,13 @@ import { PolygonHierarchy } from './earcut/polygonHierarchy.js'
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Return a list of polygons which are enclosed by the slice.
|
|
8
|
+
*
|
|
8
9
|
* @param {Slice} slice - the slice
|
|
9
10
|
* @return {Array} a list of polygons (3D)
|
|
10
|
-
* @alias module:modeling/
|
|
11
|
+
* @alias module:modeling/slice.toPolygons
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const polygons = slice.toPolygons(sliceA)
|
|
11
15
|
*/
|
|
12
16
|
export const toPolygons = (slice) => {
|
|
13
17
|
const hierarchy = new PolygonHierarchy(slice)
|
|
@@ -2,9 +2,13 @@ import * as vec3 from '../../maths/vec3/index.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Convert the given slice to a readable string.
|
|
5
|
+
*
|
|
5
6
|
* @param {Slice} slice - the slice
|
|
6
7
|
* @return {String} the string representation
|
|
7
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/slice.toString
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* console.log(slice.toString(sliceA))
|
|
8
12
|
*/
|
|
9
13
|
export const toString = (slice) => {
|
|
10
14
|
let result = 'slice (' + slice.contours.length + ' contours):\n[\n'
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Produces an array of vertices from the given slice.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* NOTE: The returned array should not be modified as the data is shared with the slice.
|
|
5
|
+
*
|
|
4
6
|
* @param {Slice} slice - the slice
|
|
5
7
|
* @returns {Array} an array of 3D vertices
|
|
6
|
-
* @alias module:modeling/
|
|
8
|
+
* @alias module:modeling/slice.toVertices
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
9
|
-
* let sharedVertices = toVertices(slice)
|
|
11
|
+
* let sharedVertices = slice.toVertices(slice)
|
|
10
12
|
*/
|
|
11
13
|
export const toVertices = (slice) => {
|
|
12
14
|
const vertices = []
|
|
@@ -4,14 +4,15 @@ import { create } from './create.js'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Transform the given slice using the given matrix.
|
|
7
|
+
*
|
|
7
8
|
* @param {Mat4} matrix - transform matrix
|
|
8
9
|
* @param {Slice} slice - slice to transform
|
|
9
10
|
* @returns {Slice} the transformed slice
|
|
10
|
-
* @alias module:modeling/
|
|
11
|
+
* @alias module:modeling/slice.transform
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* const matrix = mat4.fromTranslation([1, 2, 3])
|
|
15
|
+
* const newSlice = slice.transform(matrix, oldSlice)
|
|
15
16
|
*/
|
|
16
17
|
export const transform = (matrix, slice) => {
|
|
17
18
|
const contours = slice.contours.map((contour) => contour.map((vertex) => vec3.transform(vec3.create(), vertex, matrix)))
|
|
@@ -6,13 +6,14 @@ import { isA } from './isA.js'
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Determine if the given object is a valid slice.
|
|
9
|
+
*
|
|
9
10
|
* Checks for valid data points.
|
|
10
11
|
*
|
|
11
|
-
* **If the geometry is not valid, an exception will be thrown with details of the geometry error.**
|
|
12
|
+
* **NOTE: If the geometry is not valid, an exception will be thrown with details of the geometry error.**
|
|
12
13
|
*
|
|
13
14
|
* @param {object} object - the object to interrogate
|
|
14
15
|
* @throws {Error} error if the geometry is not valid
|
|
15
|
-
* @alias module:modeling/
|
|
16
|
+
* @alias module:modeling/slice.validate
|
|
16
17
|
*/
|
|
17
18
|
export const validate = (object) => {
|
|
18
19
|
if (!isA(object)) {
|
package/src/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { degToRad, flatten, radiusToSegments, radToDeg } from './utils'
|
|
|
10
10
|
export * as booleans from './operations/booleans'
|
|
11
11
|
export * as extrusions from './operations/extrusions'
|
|
12
12
|
export * as hulls from './operations/hulls'
|
|
13
|
+
export * as minkowski from './operations/minkowski'
|
|
13
14
|
export * as modifiers from './operations/modifiers'
|
|
14
15
|
export * as offsets from './operations/offsets'
|
|
15
16
|
export * as transforms from './operations/transforms'
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modeling
|
|
3
|
+
*/
|
|
1
4
|
export * from './colors/index.js'
|
|
2
5
|
export * from './curves/index.js'
|
|
3
6
|
export * from './geometries/index.js'
|
|
@@ -10,6 +13,7 @@ export { degToRad, flatten, radiusToSegments, radToDeg } from './utils/index.js'
|
|
|
10
13
|
export * from './operations/booleans/index.js'
|
|
11
14
|
export * from './operations/extrusions/index.js'
|
|
12
15
|
export * from './operations/hulls/index.js'
|
|
16
|
+
export * from './operations/minkowski/index.js'
|
|
13
17
|
export * from './operations/modifiers/index.js'
|
|
14
18
|
export * from './operations/offsets/index.js'
|
|
15
19
|
export * from './operations/transforms/index.js'
|
package/src/maths/constants.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Epsilon used during determination of near zero distances.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @constant
|
|
5
5
|
* @alias module:modeling/maths.EPS
|
|
6
6
|
* @example
|
|
7
|
-
*
|
|
7
|
+
* import { EPS } from '@jscad/modeling'
|
|
8
8
|
*/
|
|
9
9
|
export const EPS = 1e-5
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Smaller epsilon used for measuring near zero distances.
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @constant
|
|
15
|
+
* @static
|
|
14
16
|
* @alias module:modeling/maths.NEPS
|
|
15
17
|
* @example
|
|
16
|
-
*
|
|
18
|
+
* import { NEPS } from '@jscad/modeling'
|
|
17
19
|
*/
|
|
18
20
|
export const NEPS = 1e-13
|
|
19
21
|
// NEPS is derived from a series of tests to determine the optimal precision
|
|
@@ -22,10 +24,12 @@ export const NEPS = 1e-13
|
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* The TAU property represents the ratio of the circumference of a circle to its radius.
|
|
27
|
+
*
|
|
25
28
|
* Approximately 6.28318530717958647692
|
|
29
|
+
*
|
|
30
|
+
* @constant
|
|
26
31
|
* @alias module:modeling/maths.TAU
|
|
27
|
-
* @default
|
|
28
32
|
* @example
|
|
29
|
-
*
|
|
33
|
+
* import { TAU } from '@jscad/modeling'
|
|
30
34
|
*/
|
|
31
35
|
export const TAU = Math.PI * 2
|
package/src/maths/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Maths are computational units for fundamental Euclidean geometry. All maths operate upon array data structures.
|
|
3
|
+
*
|
|
3
4
|
* Note: Maths data structures are considered immutable, so never change the contents directly.
|
|
4
5
|
* @see Most computations are based upon the glMatrix library (glmatrix.net)
|
|
5
6
|
* @module modeling/maths
|
|
6
7
|
* @example
|
|
7
|
-
* import {
|
|
8
|
+
* import { TAU, line2, line3, mat4, plane, utils, vec2, vec3, vec4 } from '@jscad/modeling'
|
|
8
9
|
*/
|
|
9
10
|
export * from './constants.js'
|
|
10
11
|
export * as line2 from './line2/index.js'
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* All shapes (primitives or the results of operations) can be passed to boolean functions
|
|
3
3
|
* to perform logical operations, e.g. remove a hole from a board.
|
|
4
|
+
*
|
|
4
5
|
* In all cases, the function returns the results, and never changes the original shapes.
|
|
5
6
|
* @module modeling/booleans
|
|
7
|
+
*
|
|
6
8
|
* @example
|
|
7
9
|
* import { intersect, scission, subtract, union } from '@jscad/modeling'
|
|
8
10
|
*/
|
|
@@ -6,7 +6,6 @@ import * as geom3 from '../../geometries/geom3/index.js'
|
|
|
6
6
|
|
|
7
7
|
import { intersectGeom2 } from './intersectGeom2.js'
|
|
8
8
|
import { intersectGeom3 } from './intersectGeom3.js'
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* Return a new geometry representing space in both the first geometry and
|
|
12
11
|
* all subsequent geometries.
|
|
@@ -4,10 +4,7 @@ export const splitLineSegmentByPlane = (plane, p1, p2) => {
|
|
|
4
4
|
const direction = vec3.subtract(vec3.create(), p2, p1)
|
|
5
5
|
let lambda = (plane[3] - vec3.dot(plane, p1)) / vec3.dot(plane, direction)
|
|
6
6
|
|
|
7
|
-
Number.isNaN(lambda) ? lambda = 0
|
|
8
|
-
: lambda > 1 ? lambda = 1
|
|
9
|
-
: lambda < 0 ? lambda = 0
|
|
10
|
-
: lambda
|
|
7
|
+
Number.isNaN(lambda) ? lambda = 0 : lambda > 1 ? lambda = 1 : lambda < 0 ? lambda = 0 : lambda
|
|
11
8
|
|
|
12
9
|
vec3.scale(direction, direction, lambda)
|
|
13
10
|
vec3.add(direction, p1, direction)
|