@jscad/modeling 2.12.1 → 2.12.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscad/modeling",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
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": "e07bb27d61f638348c73cc1383dfb5339060a02a"
64
+ "gitHead": "5fbb5fea458c28b0d96450dde9231e1d4d8ce6a4"
65
65
  }
@@ -0,0 +1,6 @@
1
+ import Geom3 from './type'
2
+ import Vec3 from '../../maths/vec3/type'
3
+
4
+ export default fromPointsConvex
5
+
6
+ declare function fromPointsConvex(points: Array<Array<Vec3>>): Geom3
@@ -0,0 +1,26 @@
1
+ const quickhull = require('../../operations/hulls/quickhull')
2
+ const create = require('./create')
3
+ const poly3 = require('../poly3')
4
+
5
+ /**
6
+ * Construct a new convex 3D geometry from a list of unique points.
7
+ * @param {Array} uniquePoints - list of points to construct convex 3D geometry
8
+ * @returns {geom3} a new geometry
9
+ * @alias module:modeling/geometries/geom3.fromPointsConvex
10
+ */
11
+ const fromPointsConvex = (uniquePoints) => {
12
+ if (!Array.isArray(uniquePoints)) {
13
+ throw new Error('the given points must be an array')
14
+ }
15
+
16
+ const faces = quickhull(uniquePoints, { skipTriangulation: true })
17
+
18
+ const polygons = faces.map((face) => {
19
+ const vertices = face.map((index) => uniquePoints[index])
20
+ return poly3.create(vertices)
21
+ })
22
+
23
+ return create(polygons)
24
+ }
25
+
26
+ module.exports = fromPointsConvex
@@ -0,0 +1,26 @@
1
+ const test = require('ava')
2
+
3
+ const { fromPointsConvex, validate } = require('./index')
4
+
5
+ test('fromPointsConvex (uniquePoints)', (t) => {
6
+ let out = []
7
+ for(x=-9;x<=9;++x)
8
+ for(y=-9;y<=9;++y)
9
+ for(z=-9;z<=9;++z)
10
+ if (x*x+y*y+z*z <= 96)
11
+ out.push([x,y,z])
12
+
13
+ let obs = fromPointsConvex(out)
14
+ validate(obs)
15
+ t.is(obs.polygons.length, 170)
16
+ t.true(obs.polygons.every((f) => ([3,4,8,9].indexOf(f.vertices.length) !== -1)))
17
+ let c = [0,0,0,0,0,0,0,0,0,0]
18
+ obs.polygons.forEach((f) => c[f.vertices.length]++)
19
+ t.is(c[3], 120);
20
+ t.is(c[4], 24);
21
+ t.is(c[8], 18);
22
+ t.is(c[9], 8);
23
+ let edges2 = 336*2
24
+ obs.polygons.forEach((f) => edges2 -= f.vertices.length)
25
+ t.is(edges2, 0);
26
+ })
@@ -1,5 +1,6 @@
1
1
  export { default as clone } from './clone'
2
2
  export { default as create } from './create'
3
+ export { default as fromPointsConvex } from './fromPointsConvex'
3
4
  export { default as fromPoints } from './fromPoints'
4
5
  export { default as fromCompactBinary } from './fromCompactBinary'
5
6
  export { default as invert } from './invert'
@@ -23,6 +23,7 @@
23
23
  module.exports = {
24
24
  clone: require('./clone'),
25
25
  create: require('./create'),
26
+ fromPointsConvex: require('./fromPointsConvex'),
26
27
  fromPoints: require('./fromPoints'),
27
28
  fromCompactBinary: require('./fromCompactBinary'),
28
29
  invert: require('./invert'),
@@ -12,6 +12,7 @@ export { default as fromXRotation } from './fromXRotation'
12
12
  export { default as fromYRotation } from './fromYRotation'
13
13
  export { default as fromZRotation } from './fromZRotation'
14
14
  export { default as identity } from './identity'
15
+ export { default as isIdentity } from './isIdentity'
15
16
  export { default as isMirroring } from './isMirroring'
16
17
  export { default as mirrorByPlane } from './mirrorByPlane'
17
18
  export { default as multiply } from './multiply'
@@ -0,0 +1,5 @@
1
+ import Mat4 from './type'
2
+
3
+ export default isIdentity
4
+
5
+ declare function isIdentity(matrix: Mat4): boolean
@@ -1,5 +1,6 @@
1
1
  export { default as intersect } from './intersect'
2
2
  export { default as subtract } from './subtract'
3
3
  export { default as union } from './union'
4
+ export { default as scission } from './scission'
4
5
 
5
6
  export as namespace booleans
@@ -0,0 +1,7 @@
1
+ import { Geom2, Geom3 } from '../../geometries/types'
2
+ import RecursiveArray from '../../utils/recursiveArray'
3
+
4
+ export default scission
5
+
6
+ declare function scission(...geometries: RecursiveArray<Geom2>): Geom2
7
+ declare function scission(...geometries: RecursiveArray<Geom3>): Geom3
@@ -0,0 +1,33 @@
1
+ import { Poly3 } from '../../../geometries/types';
2
+ import { Plane } from '../../../maths/types';
3
+
4
+ enum ResType
5
+ {
6
+ coplanar_front = 0,
7
+ coplanar_back = 1,
8
+ front = 2,
9
+ back = 3,
10
+ spanning = 4,
11
+ }
12
+
13
+
14
+ interface SplitRes
15
+ {
16
+ type: ResType,
17
+ front: Poly3,
18
+ back: Poly3;
19
+ }
20
+
21
+ // Returns object:
22
+ // .type:
23
+ // 0: coplanar-front
24
+ // 1: coplanar-back
25
+ // 2: front
26
+ // 3: back
27
+ // 4: spanning
28
+ // In case the polygon is spanning, returns:
29
+ // .front: a Polygon3 of the front part
30
+ // .back: a Polygon3 of the back part
31
+ declare function splitPolygonByPlane(plane: Plane, polygon: Poly3): SplitRes;
32
+
33
+ export default splitPolygonByPlane;
@@ -150,7 +150,7 @@ const roundedCuboid = (options) => {
150
150
 
151
151
  if (roundRadius > (size[0] - EPS) ||
152
152
  roundRadius > (size[1] - EPS) ||
153
- roundRadius > (size[2] - EPS)) throw new Error('roundRadius must be smaller then the radius of all dimensions')
153
+ roundRadius > (size[2] - EPS)) throw new Error('roundRadius must be smaller than the radius of all dimensions')
154
154
 
155
155
  segments = Math.floor(segments / 4)
156
156
 
@@ -38,7 +38,7 @@ const roundedCylinder = (options) => {
38
38
  if (!isGTE(height, 0)) throw new Error('height must be positive')
39
39
  if (!isGTE(radius, 0)) throw new Error('radius must be positive')
40
40
  if (!isGTE(roundRadius, 0)) throw new Error('roundRadius must be positive')
41
- if (roundRadius > radius) throw new Error('roundRadius must be smaller then the radius')
41
+ if (roundRadius > radius) throw new Error('roundRadius must be smaller than the radius')
42
42
  if (!isGTE(segments, 4)) throw new Error('segments must be four or more')
43
43
 
44
44
  // if size is zero return empty geometry
@@ -44,7 +44,7 @@ const roundedRectangle = (options) => {
44
44
  size = size.map((v) => v / 2) // convert to radius
45
45
 
46
46
  if (roundRadius > (size[0] - EPS) ||
47
- roundRadius > (size[1] - EPS)) throw new Error('roundRadius must be smaller then the radius of all dimensions')
47
+ roundRadius > (size[1] - EPS)) throw new Error('roundRadius must be smaller than the radius of all dimensions')
48
48
 
49
49
  const cornersegments = Math.floor(segments / 4)
50
50