@jscad/modeling 3.0.4-alpha.0 → 3.0.6-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 +12 -0
- package/dist/jscad-modeling.es.js +2 -2
- package/dist/jscad-modeling.min.js +2 -2
- package/package.json +4 -4
- package/rollup.config.js +1 -1
- package/src/colors/colorize.js +17 -1
- package/src/colors/hsvToRgb.js +1 -0
- package/src/colors/rgbToHsl.js +3 -1
- package/src/colors/rgbToHsv.js +1 -0
- package/src/curves/bezier/create.js +1 -1
- package/src/geometries/geom2/fromPoints.d.ts +4 -0
- package/src/geometries/geom2/fromPoints.js +28 -0
- package/src/geometries/geom2/fromPoints.test.js +22 -0
- package/src/geometries/geom2/index.d.ts +1 -0
- package/src/geometries/geom2/index.js +1 -0
- package/src/geometries/geom2/transform.js +1 -0
- package/src/geometries/geom3/transform.js +1 -0
- package/src/geometries/geom3/validate.js +11 -1
- package/src/geometries/path2/appendArc.js +19 -25
- package/src/geometries/path2/appendBezier.js +8 -11
- package/src/geometries/path2/appendPoints.js +21 -3
- package/src/geometries/path2/appendPoints.test.js +16 -4
- package/src/geometries/path2/close.js +7 -10
- package/src/geometries/path2/concat.js +2 -2
- package/src/geometries/path2/fromPoints.js +7 -7
- package/src/geometries/path2/reverse.js +3 -3
- package/src/geometries/path2/transform.js +1 -0
- package/src/geometries/path2/validate.js +2 -2
- package/src/geometries/path3/clone.d.ts +3 -0
- package/src/geometries/path3/clone.js +11 -0
- package/src/geometries/path3/close.js +7 -8
- package/src/geometries/path3/index.d.ts +1 -0
- package/src/geometries/path3/index.js +1 -0
- package/src/geometries/path3/transform.js +1 -0
- package/src/geometries/poly2/type.d.ts +1 -5
- package/src/geometries/slice/earcut/index.js +4 -2
- package/src/geometries/slice/earcut/linkedPolygon.js +4 -2
- package/src/geometries/slice/fromOutlines.d.ts +5 -0
- package/src/geometries/slice/fromOutlines.js +16 -0
- package/src/geometries/slice/fromOutlines.test.js +17 -0
- package/src/geometries/slice/index.d.ts +1 -1
- package/src/geometries/slice/index.js +1 -1
- package/src/geometries/slice/transform.js +2 -1
- package/src/maths/line2/intersectPointOfLines.js +1 -4
- package/src/maths/plane/fromNormalAndPoint.js +4 -6
- package/src/maths/plane/fromPoints.js +8 -7
- package/src/maths/plane/fromPointsRandom.js +13 -13
- package/src/measurements/measureAggregateEpsilon.js +3 -1
- package/src/measurements/measureAggregateEpsilon.test.js +1 -1
- package/src/measurements/measureArea.js +6 -4
- package/src/measurements/measureArea.test.js +4 -1
- package/src/measurements/measureBoundingBox.js +16 -2
- package/src/measurements/measureBoundingBox.test.js +4 -1
- package/src/measurements/measureBoundingSphere.js +38 -29
- package/src/measurements/measureBoundingSphere.test.js +4 -1
- package/src/measurements/measureCenterOfMass.js +3 -2
- package/src/measurements/measureEpsilon.js +4 -2
- package/src/operations/booleans/martinez/computeFields.js +6 -0
- package/src/operations/booleans/martinez/divideSegment.js +2 -1
- package/src/operations/booleans/martinez/fillQueue.js +3 -1
- package/src/operations/booleans/martinez/subdivideSegments.js +5 -4
- package/src/operations/booleans/subtractGeom3Sub.js +1 -1
- package/src/operations/booleans/trees/PolygonTreeNode.js +3 -0
- package/src/operations/booleans/trees/splitPolygonByPlane.d.ts +1 -3
- package/src/operations/booleans/union.js +1 -1
- package/src/operations/extrusions/extrudeFromSlices.js +1 -1
- package/src/operations/extrusions/extrudeFromSlices.test.js +1 -1
- package/src/operations/extrusions/extrudeHelical.js +2 -1
- package/src/operations/extrusions/extrudeLinear.js +1 -1
- package/src/operations/extrusions/extrudeLinearGeom2.js +12 -8
- package/src/operations/extrusions/extrudeRotate.js +1 -1
- package/src/operations/hulls/hull.js +3 -2
- package/src/operations/hulls/quickhull/Face.js +8 -3
- package/src/operations/hulls/quickhull/QuickHull.js +10 -5
- package/src/operations/hulls/quickhull/VertexList.js +2 -1
- package/src/operations/hulls/toUniquePoints.js +3 -0
- package/src/operations/modifiers/generalize.js +9 -2
- package/src/operations/modifiers/reTesselateCoplanarPolygons.js +2 -2
- package/src/operations/modifiers/reTesselateCoplanarPolygons.test.js +29 -3
- package/src/operations/modifiers/retessellate.js +1 -0
- package/src/operations/modifiers/snap.js +22 -3
- package/src/operations/modifiers/snap.test.js +12 -2
- package/src/operations/offsets/offsetGeom3.test.js +2 -2
- package/src/operations/transforms/align.js +2 -1
- package/src/operations/transforms/align.test.js +1 -1
- package/src/operations/transforms/mirror.js +6 -2
- package/src/operations/transforms/rotate.js +6 -2
- package/src/operations/transforms/scale.js +6 -2
- package/src/operations/transforms/transform.js +6 -2
- package/src/operations/transforms/transform.test.js +16 -5
- package/src/operations/transforms/translate.js +12 -4
- package/src/primitives/arc.js +14 -14
- package/src/primitives/circle.js +10 -9
- package/src/primitives/cube.js +5 -6
- package/src/primitives/cuboid.js +6 -6
- package/src/primitives/cylinder.js +8 -8
- package/src/primitives/cylinderElliptic.js +11 -11
- package/src/primitives/ellipse.js +12 -12
- package/src/primitives/ellipsoid.js +8 -8
- package/src/primitives/geodesicSphere.js +6 -6
- package/src/primitives/line.js +2 -0
- package/src/primitives/polygon.js +6 -7
- package/src/primitives/polyhedron.js +7 -8
- package/src/primitives/rectangle.js +6 -6
- package/src/primitives/roundedCuboid.js +8 -8
- package/src/primitives/roundedCylinder.js +9 -9
- package/src/primitives/roundedRectangle.js +8 -8
- package/src/primitives/sphere.js +7 -8
- package/src/primitives/square.js +6 -6
- package/src/primitives/star.js +12 -14
- package/src/primitives/torus.js +11 -11
- package/src/primitives/triangle.js +7 -6
- package/src/utils/areAllShapesTheSameType.js +4 -0
- package/test/helpers/nearlyEqual.js +1 -0
- package/src/geometries/slice/fromGeom2.d.ts +0 -5
- package/src/geometries/slice/fromGeom2.js +0 -17
package/src/primitives/torus.js
CHANGED
|
@@ -10,6 +10,7 @@ import { isGT, isGTE } from './commonChecks.js'
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Construct a torus by revolving a small circle (inner) about the circumference of a large (outer) circle.
|
|
13
|
+
*
|
|
13
14
|
* @param {object} [options] - options for construction
|
|
14
15
|
* @param {number} [options.innerRadius=1] - radius of small (inner) circle
|
|
15
16
|
* @param {number} [options.outerRadius=4] - radius of large (outer) circle
|
|
@@ -24,17 +25,16 @@ import { isGT, isGTE } from './commonChecks.js'
|
|
|
24
25
|
* @example
|
|
25
26
|
* let myshape = torus({ innerRadius: 10, outerRadius: 100 })
|
|
26
27
|
*/
|
|
27
|
-
export const torus = (options) => {
|
|
28
|
-
const
|
|
29
|
-
innerRadius
|
|
30
|
-
innerSegments
|
|
31
|
-
outerRadius
|
|
32
|
-
outerSegments
|
|
33
|
-
innerRotation
|
|
34
|
-
startAngle
|
|
35
|
-
outerRotation
|
|
36
|
-
}
|
|
37
|
-
const { innerRadius, innerSegments, outerRadius, outerSegments, innerRotation, startAngle, outerRotation } = Object.assign({}, defaults, options)
|
|
28
|
+
export const torus = (options = {}) => {
|
|
29
|
+
const {
|
|
30
|
+
innerRadius = 1,
|
|
31
|
+
innerSegments = 32,
|
|
32
|
+
outerRadius = 4,
|
|
33
|
+
outerSegments = 32,
|
|
34
|
+
innerRotation = 0,
|
|
35
|
+
startAngle = 0,
|
|
36
|
+
outerRotation = TAU
|
|
37
|
+
} = options
|
|
38
38
|
|
|
39
39
|
if (!isGT(innerRadius, 0)) throw new Error('innerRadius must be greater than zero')
|
|
40
40
|
if (!isGTE(innerSegments, 3)) throw new Error('innerSegments must be three or more')
|
|
@@ -115,7 +115,9 @@ const createTriangle = (A, B, C, a, b, c) => {
|
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* Construct a triangle in two dimensional space from the given options.
|
|
118
|
+
*
|
|
118
119
|
* The triangle is always constructed CCW from the origin, [0, 0, 0].
|
|
120
|
+
*
|
|
119
121
|
* @see https://www.mathsisfun.com/algebra/trig-solving-triangles.html
|
|
120
122
|
* @param {object} [options] - options for construction
|
|
121
123
|
* @param {string} [options.type='SSS'] - type of triangle to construct; A ~ angle, S ~ side
|
|
@@ -126,12 +128,11 @@ const createTriangle = (A, B, C, a, b, c) => {
|
|
|
126
128
|
* @example
|
|
127
129
|
* let myshape = triangle({type: 'AAS', values: [degToRad(62), degToRad(35), 7]})
|
|
128
130
|
*/
|
|
129
|
-
export const triangle = (options) => {
|
|
130
|
-
|
|
131
|
-
type
|
|
132
|
-
values
|
|
133
|
-
}
|
|
134
|
-
let { type, values } = Object.assign({}, defaults, options)
|
|
131
|
+
export const triangle = (options = {}) => {
|
|
132
|
+
let {
|
|
133
|
+
type = 'SSS',
|
|
134
|
+
values = [1, 1, 1]
|
|
135
|
+
} = options
|
|
135
136
|
|
|
136
137
|
if (typeof (type) !== 'string') throw new Error('triangle type must be a string')
|
|
137
138
|
type = type.toUpperCase()
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import * as geom2 from '../geometries/geom2/index.js'
|
|
3
3
|
import * as geom3 from '../geometries/geom3/index.js'
|
|
4
4
|
import * as path2 from '../geometries/path2/index.js'
|
|
5
|
+
import * as path3 from '../geometries/path3/index.js'
|
|
6
|
+
import * as slice from '../geometries/slice/index.js'
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* @param {Array} shapes - list of shapes to compare
|
|
@@ -15,6 +17,8 @@ export const areAllShapesTheSameType = (shapes) => {
|
|
|
15
17
|
if (geom2.isA(shape)) currentType = 1
|
|
16
18
|
if (geom3.isA(shape)) currentType = 2
|
|
17
19
|
if (path2.isA(shape)) currentType = 3
|
|
20
|
+
if (path3.isA(shape)) currentType = 4
|
|
21
|
+
if (slice.isA(shape)) currentType = 5
|
|
18
22
|
|
|
19
23
|
if (previousType && currentType !== previousType) return false
|
|
20
24
|
previousType = currentType
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as vec3 from '../../maths/vec3/index.js'
|
|
2
|
-
import { toOutlines } from '../geom2/index.js'
|
|
3
|
-
|
|
4
|
-
import { create } from './create.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Create a slice from a geom2.
|
|
8
|
-
*
|
|
9
|
-
* @param {object} geometry - the 2D geometry to create a slice from
|
|
10
|
-
* @returns {Slice} a new slice
|
|
11
|
-
* @alias module:modeling/slice.fromGeom2
|
|
12
|
-
*/
|
|
13
|
-
export const fromGeom2 = (geometry) => {
|
|
14
|
-
// Convert from 2D points to 3D vertices
|
|
15
|
-
const contours = toOutlines(geometry).map((outline) => outline.map((point) => vec3.fromVec2(vec3.create(), point)))
|
|
16
|
-
return create(contours)
|
|
17
|
-
}
|