@jscad/modeling 2.12.4 → 2.12.5

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 CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.12.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/modeling@2.12.4...@jscad/modeling@2.12.5) (2024-12-29)
7
+
8
+ **Note:** Version bump only for package @jscad/modeling
9
+
10
+
11
+
12
+
13
+
6
14
  ## [2.12.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/modeling@2.12.3...@jscad/modeling@2.12.4) (2024-11-10)
7
15
 
8
16
  **Note:** Version bump only for package @jscad/modeling
package/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  The MIT License (MIT)
3
3
 
4
- Copyright (c) 2017-2021 JSCAD Organization
4
+ Copyright (c) 2017-2024 JSCAD Organization
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
@@ -1163,7 +1163,7 @@ const rectangle=require("./rectangle"),{isGTE:isGTE}=require("./commonChecks"),s
1163
1163
  const{TAU:TAU}=require("../maths/constants"),vec2=require("../maths/vec2"),geom2=require("../geometries/geom2"),{isGT:isGT,isGTE:isGTE,isNumberArray:isNumberArray}=require("./commonChecks"),getRadiusRatio=(e,r)=>e>0&&r>1&&r<e/2?Math.cos(Math.PI*r/e)/Math.cos(Math.PI*(r-1)/e):0,getPoints=(e,r,t,s)=>{const o=TAU/e,i=[];for(let a=0;a<e;a++){const e=vec2.fromAngleRadians(vec2.create(),o*a+t);vec2.scale(e,e,r),vec2.add(e,s,e),i.push(e)}return i},star=e=>{let{center:r,vertices:t,outerRadius:s,innerRadius:o,density:i,startAngle:a}=Object.assign({},{center:[0,0],vertices:5,outerRadius:1,innerRadius:0,density:2,startAngle:0},e);if(!isNumberArray(r,2))throw new Error("center must be an array of X and Y values");if(!isGTE(t,2))throw new Error("vertices must be two or more");if(!isGT(s,0))throw new Error("outerRadius must be greater than zero");if(!isGTE(o,0))throw new Error("innerRadius must be greater than zero");if(!isGTE(a,0))throw new Error("startAngle must be greater than zero");if(t=Math.floor(t),i=Math.floor(i),a%=TAU,0===o){if(!isGTE(i,2))throw new Error("density must be two or more");o=s*getRadiusRatio(t,i)}const n=vec2.clone(r),u=getPoints(t,s,a,n),c=getPoints(t,o,a+Math.PI/t,n),h=[];for(let e=0;e<t;e++)h.push(u[e]),h.push(c[e]);return geom2.fromPoints(h)};module.exports=star;
1164
1164
 
1165
1165
  },{"../geometries/geom2":25,"../maths/constants":94,"../maths/vec2":191,"./commonChecks":370}],389:[function(require,module,exports){
1166
- const{TAU:TAU}=require("../maths/constants"),extrudeRotate=require("../operations/extrusions/extrudeRotate"),{rotate:rotate}=require("../operations/transforms/rotate"),{translate:translate}=require("../operations/transforms/translate"),circle=require("./circle"),{isGT:isGT,isGTE:isGTE}=require("./commonChecks"),torus=e=>{const r={innerRadius:1,innerSegments:32,outerRadius:4,outerSegments:32,innerRotation:0,startAngle:0,outerRotation:TAU},{innerRadius:t,innerSegments:o,outerRadius:n,outerSegments:s,innerRotation:i,startAngle:a,outerRotation:u}=Object.assign({},r,e);if(!isGT(t,0))throw new Error("innerRadius must be greater than zero");if(!isGTE(o,3))throw new Error("innerSegments must be three or more");if(!isGT(n,0))throw new Error("outerRadius must be greater than zero");if(!isGTE(s,3))throw new Error("outerSegments must be three or more");if(!isGTE(a,0))throw new Error("startAngle must be positive");if(!isGT(u,0))throw new Error("outerRotation must be greater than zero");if(t>=n)throw new Error("inner circle is two large to rotate about the outer circle");let m=circle({radius:t,segments:o});return 0!==i&&(m=rotate([0,0,i],m)),m=translate([n,0],m),extrudeRotate({startAngle:a,angle:u,segments:s},m)};module.exports=torus;
1166
+ const{TAU:TAU}=require("../maths/constants"),extrudeRotate=require("../operations/extrusions/extrudeRotate"),{rotate:rotate}=require("../operations/transforms/rotate"),{translate:translate}=require("../operations/transforms/translate"),circle=require("./circle"),{isGT:isGT,isGTE:isGTE}=require("./commonChecks"),torus=e=>{const r={innerRadius:1,innerSegments:32,outerRadius:4,outerSegments:32,innerRotation:0,startAngle:0,outerRotation:TAU},{innerRadius:t,innerSegments:o,outerRadius:n,outerSegments:s,innerRotation:i,startAngle:a,outerRotation:u}=Object.assign({},r,e);if(!isGT(t,0))throw new Error("innerRadius must be greater than zero");if(!isGTE(o,3))throw new Error("innerSegments must be three or more");if(!isGT(n,0))throw new Error("outerRadius must be greater than zero");if(!isGTE(s,3))throw new Error("outerSegments must be three or more");if(!isGTE(a,0))throw new Error("startAngle must be positive");if(!isGT(u,0))throw new Error("outerRotation must be greater than zero");if(t>=n)throw new Error("inner circle is too large to rotate about the outer circle");let m=circle({radius:t,segments:o});return 0!==i&&(m=rotate([0,0,i],m)),m=translate([n,0],m),extrudeRotate({startAngle:a,angle:u,segments:s},m)};module.exports=torus;
1167
1167
 
1168
1168
  },{"../maths/constants":94,"../operations/extrusions/extrudeRotate":316,"../operations/transforms/rotate":364,"../operations/transforms/translate":367,"./circle":369,"./commonChecks":370}],390:[function(require,module,exports){
1169
1169
  const{NEPS:NEPS}=require("../maths/constants"),vec2=require("../maths/vec2"),geom2=require("../geometries/geom2"),{isNumberArray:isNumberArray}=require("./commonChecks"),solveAngleFromSSS=(e,r,t)=>Math.acos((e*e+r*r-t*t)/(2*e*r)),solveSideFromSAS=(e,r,t)=>r>NEPS?Math.sqrt(e*e+t*t-2*e*t*Math.cos(r)):Math.sqrt((e-t)*(e-t)+e*t*r*r*(1-r*r/12)),solveAAA=e=>{if(Math.abs(e[0]+e[1]+e[2]-Math.PI)>NEPS)throw new Error("AAA triangles require angles that sum to PI");const r=e[0],t=e[1],s=Math.PI-r-t,a=1/Math.sin(s)*Math.sin(r),n=1/Math.sin(s)*Math.sin(t);return createTriangle(r,t,s,a,n,1)},solveAAS=e=>{const r=e[0],t=e[1],s=Math.PI+NEPS-r-t;if(s<NEPS)throw new Error("AAS triangles require angles that sum to PI");const a=e[2],n=a/Math.sin(r)*Math.sin(t),o=a/Math.sin(r)*Math.sin(s);return createTriangle(r,t,s,a,n,o)},solveASA=e=>{const r=e[0],t=e[2],s=Math.PI+NEPS-r-t;if(s<NEPS)throw new Error("ASA triangles require angles that sum to PI");const a=e[1],n=a/Math.sin(s)*Math.sin(r),o=a/Math.sin(s)*Math.sin(t);return createTriangle(r,t,s,n,o,a)},solveSAS=e=>{const r=e[0],t=e[1],s=e[2],a=solveSideFromSAS(r,t,s),n=solveAngleFromSSS(a,r,s),o=Math.PI-n-t;return createTriangle(n,t,o,s,a,r)},solveSSA=e=>{const r=e[0],t=e[1],s=e[2],a=Math.asin(t*Math.sin(s)/r),n=Math.PI-a-s,o=r/Math.sin(s)*Math.sin(n);return createTriangle(a,n,s,t,o,r)},solveSSS=e=>{const r=e[1],t=e[2],s=e[0];if(r+t<=s||t+s<=r||s+r<=t)throw new Error("SSS triangle is incorrect, as the longest side is longer than the sum of the other sides");const a=solveAngleFromSSS(t,s,r),n=solveAngleFromSSS(s,r,t),o=Math.PI-a-n;return createTriangle(a,n,o,r,t,s)},createTriangle=(e,r,t,s,a,n)=>{const o=vec2.fromValues(0,0),i=vec2.fromValues(n,0),S=vec2.fromValues(s,0);return vec2.add(S,vec2.rotate(S,S,[0,0],Math.PI-r),i),geom2.fromPoints([o,i,S])},triangle=e=>{let{type:r,values:t}=Object.assign({},{type:"SSS",values:[1,1,1]},e);if("string"!=typeof r)throw new Error("triangle type must be a string");if("A"!==(r=r.toUpperCase())[0]&&"S"!==r[0]||"A"!==r[1]&&"S"!==r[1]||"A"!==r[2]&&"S"!==r[2])throw new Error("triangle type must contain three letters; A or S");if(!isNumberArray(t,3))throw new Error("triangle values must contain three values");if(!t.every(e=>e>0))throw new Error("triangle values must be greater than zero");switch(r){case"AAA":return solveAAA(t);case"AAS":return solveAAS(t);case"ASA":return solveASA(t);case"SAS":return solveSAS(t);case"SSA":return solveSSA(t);case"SSS":return solveSSS(t);default:throw new Error("invalid triangle type, try again")}};module.exports=triangle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscad/modeling",
3
- "version": "2.12.4",
3
+ "version": "2.12.5",
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",
@@ -61,5 +61,5 @@
61
61
  "nyc": "15.1.0",
62
62
  "uglifyify": "5.0.2"
63
63
  },
64
- "gitHead": "ce4978ee40c30803cba05d1c96ba8b6aaf3abc61"
64
+ "gitHead": "d8010c4f1d70685404a510d604f8b6d5c362f93a"
65
65
  }
@@ -3,7 +3,6 @@
3
3
  * @module modeling/curves
4
4
  * @example
5
5
  * const { bezier } = require('@jscad/modeling').curves
6
-
7
6
  */
8
7
  module.exports = {
9
8
  bezier: require('./bezier')
@@ -4,8 +4,7 @@
4
4
  * @see Most computations are based upon the glMatrix library (glmatrix.net)
5
5
  * @module modeling/maths
6
6
  * @example
7
- * const { constants, line2, mat4, vec2, vec3 } = require('@jscad/modeling').maths
8
-
7
+ * const { constants, line2, line3, mat4, plane, utils, vec2, vec3, vec4 } = require('@jscad/modeling').maths
9
8
  */
10
9
  module.exports = {
11
10
  constants: require('./constants'),
@@ -17,7 +17,7 @@ const intersectGeom3 = require('./intersectGeom3')
17
17
  * @alias module:modeling/booleans.intersect
18
18
  *
19
19
  * @example
20
- * let myshape = intersect(cube({size: [5,5,5]}), cube({size: [5,5,5], center: [5,5,5]}))
20
+ * let myshape = intersect(cube({size: 5}), cube({size: 5, center: [3,3,3]}))
21
21
  *
22
22
  * @example
23
23
  * +-------+
@@ -9,6 +9,8 @@ const scissionGeom3 = require('./scissionGeom3')
9
9
  /**
10
10
  * Scission (divide) the given geometry into the component pieces.
11
11
  *
12
+ * NOTE: Currently only 3D geometries are supported.
13
+ *
12
14
  * @param {...Object} objects - list of geometries
13
15
  * @returns {Array} list of pieces from each geometry
14
16
  * @alias module:modeling/booleans.scission
@@ -17,7 +17,7 @@ const subtractGeom3 = require('./subtractGeom3')
17
17
  * @alias module:modeling/booleans.subtract
18
18
  *
19
19
  * @example
20
- * let myshape = subtract(cuboid({size: [5,5,5]}), cuboid({size: [5,5,5], center: [5,5,5]}))
20
+ * let myshape = subtract(cuboid({size: 5}), cuboid({size: 5, center: [3,3,3]}))
21
21
  *
22
22
  * @example
23
23
  * +-------+ +-------+
@@ -16,7 +16,7 @@ const unionGeom3 = require('./unionGeom3')
16
16
  * @alias module:modeling/booleans.union
17
17
  *
18
18
  * @example
19
- * let myshape = union(cube({size: [5,5,5]}), cube({size: [5,5,5], center: [5,5,5]}))
19
+ * let myshape = union(cube({size: 5}), cube({size: 5, center: [3,3,3]}))
20
20
  *
21
21
  * @example
22
22
  * +-------+ +-------+
@@ -24,7 +24,7 @@ const expandPath2 = require('./expandPath2')
24
24
  * @example
25
25
  * let newarc = expand({delta: 5, corners: 'edge'}, arc({}))
26
26
  * let newsquare = expand({delta: 5, corners: 'chamfer'}, square({size: 30}))
27
- * let newsphere = expand({delta: 2, corners: 'round'}, cuboid({size: [20, 25, 5]}))
27
+ * let newcuboid = expand({delta: 2, corners: 'round'}, cuboid({size: [20, 25, 5]}))
28
28
  */
29
29
  const expand = (options, ...objects) => {
30
30
  objects = flatten(objects)
@@ -19,14 +19,8 @@ const geom2 = require('../../geometries/geom2')
19
19
  * @alias module:modeling/extrusions.extrudeHelical
20
20
  *
21
21
  * @example
22
- * const myshape = extrudeHelical(
23
- * {
24
- * angle: Math.PI * 4,
25
- * pitch: 10,
26
- * segmentsPerRotation: 64
27
- * },
28
- * circle({size: 3, center: [10, 0]})
29
- * )
22
+ * const myshape = circle({size: 3, center: [10, 0]}) // position for extrusion about Z
23
+ * const mycoil = extrudeHelical({angle: TAU*2, pitch: 10, segmentsPerRotation: 64}, myshape))
30
24
  */
31
25
  const extrudeHelical = (options, geometry) => {
32
26
  const defaults = {
@@ -3,7 +3,7 @@
3
3
  * In all cases, the function returns the results, and never changes the original shapes.
4
4
  * @module modeling/extrusions
5
5
  * @example
6
- * const { extrudeLinear, extrudeRectangular, extrudeRotate } = require('@jscad/modeling').extrusions
6
+ * const { extrudeHelical, extrudeLinear, extrudeRectangular, extrudeRotate, project, slice } = require('@jscad/modeling').extrusions
7
7
  */
8
8
  module.exports = {
9
9
  extrudeFromSlices: require('./extrudeFromSlices'),
@@ -4,7 +4,7 @@
4
4
  * In all cases, the function returns the results, and never changes the original shapes.
5
5
  * @module modeling/hulls
6
6
  * @example
7
- * const { hull, hullChain } = require('@jscad/modeling').hulls
7
+ * const { hull, hullChain, hullPoints2, hullPoints3 } = require('@jscad/modeling').hulls
8
8
  */
9
9
  module.exports = {
10
10
  hull: require('./hull'),
@@ -3,7 +3,7 @@
3
3
  * In all cases, these functions returns the results, and never changes the original geometry.
4
4
  * @module modeling/modifiers
5
5
  * @example
6
- * const { snap } = require('@jscad/modeling').modifiers
6
+ * const { generalize, snap, retessellate } = require('@jscad/modeling').modifiers
7
7
  */
8
8
  module.exports = {
9
9
  generalize: require('./generalize'),
@@ -35,7 +35,7 @@ const snapGeom3 = (geometry) => {
35
35
  }
36
36
 
37
37
  /**
38
- * Snap the given geometries to the overall precision (epsilon) of the geometry.
38
+ * Snap the given geometries to the precision (calculated epsilon) of the geometry.
39
39
  * @see measurements.measureEpsilon()
40
40
  * @param {...Object} geometries - the geometries to snap
41
41
  * @return {Object|Array} the snapped geometry, or a list of snapped geometries
@@ -17,6 +17,8 @@ const { isGT, isGTE, isNumberArray } = require('./commonChecks')
17
17
  * @param {Boolean} [options.makeTangent=false] - adds line segments at both ends of the arc to ensure that the gradients at the edges are tangent
18
18
  * @returns {path2} new 2D path
19
19
  * @alias module:modeling/primitives.arc
20
+ * @example
21
+ * let myshape = arc({ center: [-1, -1], radius: 2, endAngle: (TAU / 4)})
20
22
  */
21
23
  const arc = (options) => {
22
24
  const defaults = {
@@ -5,6 +5,7 @@ const { isNumberArray } = require('./commonChecks')
5
5
 
6
6
  /**
7
7
  * Construct a polyhedron in three dimensional space from the given set of 3D points and faces.
8
+ *
8
9
  * The faces can define outward or inward facing polygons (orientation).
9
10
  * However, each face must define a counter clockwise rotation of points which follows the right hand rule.
10
11
  * @param {Object} options - options for construction
@@ -18,7 +19,7 @@ const { isNumberArray } = require('./commonChecks')
18
19
  * @example
19
20
  * let mypoints = [ [10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10] ]
20
21
  * let myfaces = [ [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3] ]
21
- * let myshape = polyhedron({points: mypoint, faces: myfaces, orientation: 'inward'})
22
+ * let myshape = polyhedron({points: mypoints, faces: myfaces, orientation: 'inward'})
22
23
  */
23
24
  const polyhedron = (options) => {
24
25
  const defaults = {
@@ -43,7 +43,7 @@ const torus = (options) => {
43
43
  if (!isGTE(startAngle, 0)) throw new Error('startAngle must be positive')
44
44
  if (!isGT(outerRotation, 0)) throw new Error('outerRotation must be greater than zero')
45
45
 
46
- if (innerRadius >= outerRadius) throw new Error('inner circle is two large to rotate about the outer circle')
46
+ if (innerRadius >= outerRadius) throw new Error('inner circle is too large to rotate about the outer circle')
47
47
 
48
48
  let innerCircle = circle({ radius: innerRadius, segments: innerSegments })
49
49
 
@@ -22,11 +22,8 @@ const vectorParams = require('./vectorParams')
22
22
  *
23
23
  * @example
24
24
  * let vectorCharObject = vectorChar()
25
- * or
26
25
  * let vectorCharObject = vectorChar('A')
27
- * or
28
26
  * let vectorCharObject = vectorChar({ xOffset: 57 }, 'C')
29
- * or
30
27
  * let vectorCharObject = vectorChar({ xOffset: 78, input: '!' })
31
28
  */
32
29
  const vectorChar = (options, char) => {
@@ -35,11 +35,8 @@ const translateLine = (options, line) => {
35
35
  *
36
36
  * @example
37
37
  * let textSegments = vectorText()
38
- * or
39
38
  * let textSegments = vectorText('OpenJSCAD')
40
- * or
41
39
  * let textSegments = vectorText({ yOffset: -50 }, 'OpenJSCAD')
42
- * or
43
40
  * let textSegments = vectorText({ yOffset: -80, input: 'OpenJSCAD' })
44
41
  */
45
42
  const vectorText = (options, text) => {
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Utility functions of various sorts.
2
+ * Utility functions of various sorts, including conversions from different angular measures.
3
3
  * @module modeling/utils
4
4
  * @example
5
- * const { flatten, insertSorted } = require('@jscad/modeling').utils
5
+ * const { areAllShapesTheSameType, degToRad, radiusToSegments, radToDeg } = require('@jscad/modeling').utils
6
6
  */
7
7
  module.exports = {
8
8
  areAllShapesTheSameType: require('./areAllShapesTheSameType'),