@jscad/vtree 2.0.13 → 2.0.16

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 (48) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +2 -2
  3. package/core/api-measurements.js +8 -12
  4. package/core/buildCachedGeometryFromTree.js +2 -4
  5. package/core/cacheWithInvalidation.js +2 -2
  6. package/core/findDisconnectedSubGraphs.js +3 -3
  7. package/core/generators/geometry-generator-cached-csg.js +11 -13
  8. package/core/geometry-generator-cached.js +17 -19
  9. package/core/index.js +5 -5
  10. package/core/modeling/index-old.js +2 -2
  11. package/core/modeling/operations/measurements/measureArea.js +2 -2
  12. package/core/modeling/operations/measurements/measureBounds.js +2 -2
  13. package/core/modeling/operations/measurements/measureVolume.js +2 -2
  14. package/core/modeling/primitives/arc.js +1 -1
  15. package/core/modeling/primitives/cuboid.js +2 -2
  16. package/core/modeling/primitives/cylinderElliptic.js +2 -2
  17. package/core/modeling/primitives/line.js +1 -1
  18. package/core/modeling/primitives/rectangle.js +1 -1
  19. package/core/objectUtils.js +3 -5
  20. package/package.json +6 -6
  21. package/prototyping/examples/basic-base.js +1 -3
  22. package/prototyping/examples/basic-vtree.js +2 -4
  23. package/prototyping/examples/caching-shape-measurements.js +3 -3
  24. package/prototyping/examples/caching-test-vanilla-changed.js +18 -21
  25. package/prototyping/examples/caching-test-vanilla-changed2.js +16 -19
  26. package/prototyping/examples/caching-test-vanilla.js +15 -19
  27. package/prototyping/examples/caching-test-vtree-changed.js +18 -21
  28. package/prototyping/examples/caching-test-vtree-changed2.js +16 -19
  29. package/prototyping/examples/caching-test-vtree.js +15 -19
  30. package/prototyping/examples/caching-test.js +8 -10
  31. package/prototyping/examples/complex-base.js +19 -26
  32. package/prototyping/examples/complex-vtree-changed.js +19 -26
  33. package/prototyping/examples/complex-vtree.js +18 -25
  34. package/prototyping/examples/logo-base.js +9 -11
  35. package/prototyping/examples/logo-vtree.js +9 -11
  36. package/prototyping/examples/shapes-array-base.js +1 -3
  37. package/prototyping/examples/shapes-array-nested-vtree.js +15 -13
  38. package/prototyping/examples/shapes-array-vtree.js +2 -4
  39. package/prototyping/examples/single-shape-vtree.js +1 -3
  40. package/prototyping/examples/transforms-vtree.js +6 -9
  41. package/prototyping/examples/union-base.js +1 -3
  42. package/prototyping/examples/union-vtree.js +1 -3
  43. package/prototyping/io/deserializeGeometryCache.js +1 -1
  44. package/prototyping/io/serializeGeometryCache.js +1 -1
  45. package/prototyping/runBenchmark.js +9 -9
  46. package/prototyping/runCompare.js +6 -6
  47. package/vtree-api.js +1 -1
  48. package/prototyping/io/convertToBlob.js +0 -13
@@ -1,24 +1,20 @@
1
1
  const { cube, sphere } = require('@jscad/csg/api').primitives3d
2
- const { union, difference, intersection } = require('@jscad/csg/api').booleanOps
3
- const { translate, rotate, scale } = require('@jscad/csg/api').transformations
2
+ const { union } = require('@jscad/csg/api').booleanOps
3
+ const { translate } = require('@jscad/csg/api').transformations
4
4
 
5
- function foo () {
6
- return [
7
- cube(),
8
- translate([13, 0, 0], cube()),
9
- sphere({ fn: 128 })
10
- ]
11
- }
5
+ const foo = () => [
6
+ cube(),
7
+ translate([13, 0, 0], cube()),
8
+ sphere({ fn: 128 })
9
+ ]
12
10
 
13
- function main () {
14
- return [
15
- foo(),
16
- cube(),
17
- translate([13, 0, 0], cube()),
18
- translate([0, 0, 2], sphere()),
19
- union(cube(), sphere()),
20
- sphere({ fn: 128 })
21
- ]
22
- }
11
+ const main = () => [
12
+ foo(),
13
+ cube(),
14
+ translate([13, 0, 0], cube()),
15
+ translate([0, 0, 2], sphere()),
16
+ union(cube(), sphere()),
17
+ sphere({ fn: 128 })
18
+ ]
23
19
 
24
20
  module.exports = main
@@ -1,27 +1,24 @@
1
1
  const {
2
2
  cube, sphere,
3
- difference, intersection, union,
4
- scale, rotate, translate
3
+ union,
4
+ rotate, translate
5
5
  } = require('../../core/index')
6
6
 
7
- function foo () {
8
- return [
9
- cube(),
10
- translate([13, 0, 0], cube()),
11
- sphere({ fn: 128 })
12
- ]
13
- }
14
- function main () {
15
- return [
16
- foo(),
17
- cube(),
18
- translate([13, 0, 0], cube()),
19
- translate([0, 0, 2], sphere()),
20
- union(cube(), sphere()),
21
- translate([23, 0, 0], cube()),
22
- rotate([13, 0, 0], cube()),
23
- sphere({ fn: 128 })
24
- ]
25
- }
7
+ const foo = () => [
8
+ cube(),
9
+ translate([13, 0, 0], cube()),
10
+ sphere({ fn: 128 })
11
+ ]
12
+
13
+ const main = () => [
14
+ foo(),
15
+ cube(),
16
+ translate([13, 0, 0], cube()),
17
+ translate([0, 0, 2], sphere()),
18
+ union(cube(), sphere()),
19
+ translate([23, 0, 0], cube()),
20
+ rotate([13, 0, 0], cube()),
21
+ sphere({ fn: 128 })
22
+ ]
26
23
 
27
24
  module.exports = main
@@ -1,25 +1,22 @@
1
1
  const {
2
2
  cube, sphere,
3
- difference, intersection, union,
4
- scale, rotate, translate
3
+ union,
4
+ rotate, translate
5
5
  } = require('../../core/index')
6
6
 
7
- function foo () {
8
- return [
9
- cube(),
10
- translate([13, 0, 0], cube())
11
- ]
12
- }
13
- function main () {
14
- return [
15
- foo(),
16
- cube(),
17
- translate([13, 0, 0], cube()),
18
- translate([0, 0, 2], sphere()),
19
- union(cube(), sphere()),
20
- translate([23, 0, 0], cube()),
21
- rotate([13, 0, 0], cube())
22
- ]
23
- }
7
+ const foo = () => [
8
+ cube(),
9
+ translate([13, 0, 0], cube())
10
+ ]
11
+
12
+ const main = () => [
13
+ foo(),
14
+ cube(),
15
+ translate([13, 0, 0], cube()),
16
+ translate([0, 0, 2], sphere()),
17
+ union(cube(), sphere()),
18
+ translate([23, 0, 0], cube()),
19
+ rotate([13, 0, 0], cube())
20
+ ]
24
21
 
25
22
  module.exports = main
@@ -1,26 +1,22 @@
1
1
  const {
2
2
  cube, sphere,
3
- difference, intersection, union,
4
- scale, rotate, translate
3
+ union,
4
+ translate
5
5
  } = require('../../core/index')
6
6
 
7
- function foo () {
8
- return [
9
- cube(),
10
- translate([13, 0, 0], cube()),
11
- sphere({ fn: 128 })
12
- ]
13
- }
7
+ const foo = () => [
8
+ cube(),
9
+ translate([13, 0, 0], cube()),
10
+ sphere({ fn: 128 })
11
+ ]
14
12
 
15
- function main () {
16
- return [
17
- foo(),
18
- cube(),
19
- translate([13, 0, 0], cube()),
20
- translate([0, 0, 2], sphere()),
21
- union(cube(), sphere()),
22
- sphere({ fn: 128 })
23
- ]
24
- }
13
+ const main = () => [
14
+ foo(),
15
+ cube(),
16
+ translate([13, 0, 0], cube()),
17
+ translate([0, 0, 2], sphere()),
18
+ union(cube(), sphere()),
19
+ sphere({ fn: 128 })
20
+ ]
25
21
 
26
22
  module.exports = main
@@ -1,14 +1,12 @@
1
- // not that API is injected so it is independant of implementation ! (vanilla vs vtree)
2
- function main (api) {
3
- const { cube, sphere, difference, intersection, union, scale, rotate, translate } = api
1
+ // note that API is injected so it is independent of implementation ! (vanilla vs vtree)
2
+ const main = (api) => {
3
+ const { cube, sphere, union, translate } = api
4
4
 
5
- function foo () {
6
- return [
7
- cube(),
8
- translate([13, 0, 0], cube()),
9
- sphere({ fn: 128 })
10
- ]
11
- }
5
+ const foo = () => [
6
+ cube(),
7
+ translate([13, 0, 0], cube()),
8
+ sphere({ fn: 128 })
9
+ ]
12
10
 
13
11
  return [
14
12
  foo(),
@@ -1,38 +1,31 @@
1
1
  const { cube, sphere } = require('@jscad/csg/api').primitives3d
2
- const { union, difference, intersection } = require('@jscad/csg/api').booleanOps
3
- const { translate, rotate, scale } = require('@jscad/csg/api').transformations
2
+ const { difference } = require('@jscad/csg/api').booleanOps
3
+ const { translate } = require('@jscad/csg/api').transformations
4
4
 
5
- function aCoolPart () {
6
- return [
7
- cube({ name: 'c1' }),
8
- translate([13, 0, 0], cube({ name: 's1' })),
9
- translate([0, 0, 2], sphere({ name: 's2' }))
10
- ]
11
- }
5
+ const aCoolPart = () => [
6
+ cube({ name: 'c1' }),
7
+ translate([13, 0, 0], cube({ name: 's1' })),
8
+ translate([0, 0, 2], sphere({ name: 's2' }))
9
+ ]
12
10
 
13
- function anotherCoolPart () {
14
- return difference(
15
- cube({ name: 'c2', size: 1, center: true }),
16
- sphere({ name: 's3', r: 0.6, fn: 128 })
17
- )
18
- }
11
+ const anotherCoolPart = () => difference(
12
+ cube({ name: 'c2', size: 1, center: true }),
13
+ sphere({ name: 's3', r: 0.6, fn: 128 })
14
+ )
19
15
 
20
- function wowPart () {
21
- return { type: 'part', children: [cube(), sphere()] }
22
- }
16
+ const wowPart = () => ({ type: 'part', children: [cube(), sphere()] })
23
17
 
24
- const flatten = arr =>
18
+ const flatten = (arr) =>
25
19
  arr.reduce(
26
20
  (flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten),
27
21
  []
28
22
  )
29
23
 
30
- function main () {
31
- return flatten([
32
- translate([0, 5, 0], aCoolPart()),
33
- anotherCoolPart(),
34
- anotherCoolPart()
35
- ])
36
- }
24
+ const main = () => flatten([
25
+ translate([0, 5, 0], aCoolPart()),
26
+ anotherCoolPart(),
27
+ anotherCoolPart(),
28
+ wowPart()
29
+ ])
37
30
 
38
31
  module.exports = main
@@ -1,40 +1,33 @@
1
1
  const {
2
2
  cube, sphere,
3
- difference, intersection, union,
4
- scale, rotate, translate
3
+ difference,
4
+ translate
5
5
  } = require('../../core/index')
6
6
 
7
- function aCoolPart () {
8
- return [
9
- cube({ name: 'c1' }),
10
- translate([13, 0, 0], cube({ name: 's1' })),
11
- translate([0, 0, 2], sphere({ name: 's2' }))
12
- ]
13
- }
7
+ const aCoolPart = () => [
8
+ cube({ name: 'c1' }),
9
+ translate([13, 0, 0], cube({ name: 's1' })),
10
+ translate([0, 0, 2], sphere({ name: 's2' }))
11
+ ]
14
12
 
15
- function anotherCoolPart () {
16
- return difference(
17
- cube({ name: 'c2', size: 1, center: true }),
18
- sphere({ name: 's3', r: 0.6, fn: 128 })
19
- )
20
- }
13
+ const anotherCoolPart = () => difference(
14
+ cube({ name: 'c2', size: 1, center: true }),
15
+ sphere({ name: 's3', r: 0.6, fn: 128 })
16
+ )
21
17
 
22
- function wowPart () {
23
- return { type: 'part', children: [cube(), sphere()] }
24
- }
18
+ const wowPart = () => ({ type: 'part', children: [cube(), sphere()] })
25
19
 
26
- const flatten = arr =>
20
+ const flatten = (arr) =>
27
21
  arr.reduce(
28
22
  (flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten),
29
23
  []
30
24
  )
31
25
 
32
- function main () {
33
- return flatten([
34
- translate([0, 5, 0], aCoolPart()),
35
- anotherCoolPart(),
36
- anotherCoolPart()
37
- ])
38
- }
26
+ const main = () => flatten([
27
+ translate([0, 5, 0], aCoolPart()),
28
+ anotherCoolPart(),
29
+ anotherCoolPart(),
30
+ wowPart()
31
+ ])
39
32
 
40
33
  module.exports = main
@@ -1,39 +1,32 @@
1
1
  const {
2
2
  cube, sphere,
3
- difference, intersection, union,
4
- scale, rotate, translate
3
+ difference,
4
+ translate
5
5
  } = require('../../core/index')
6
6
 
7
- function aCoolPart () {
8
- return [
9
- cube({ name: 'c1' }),
10
- translate([3, 0, 0], cube({ name: 's1' })),
11
- translate([0, 0, 2], sphere({ name: 's2' }))
12
- ]
13
- }
7
+ const aCoolPart = () => [
8
+ cube({ name: 'c1' }),
9
+ translate([3, 0, 0], cube({ name: 's1' })),
10
+ translate([0, 0, 2], sphere({ name: 's2' }))
11
+ ]
14
12
 
15
- function anotherCoolPart () {
16
- return difference(
17
- cube({ name: 'c2', size: 1, center: true }),
18
- sphere({ name: 's3', r: 0.6, fn: 128 })
19
- )
20
- }
13
+ const anotherCoolPart = () => difference(
14
+ cube({ name: 'c2', size: 1, center: true }),
15
+ sphere({ name: 's3', r: 0.6, fn: 128 })
16
+ )
21
17
 
22
- function wowPart () {
23
- return { type: 'part', children: [cube(), sphere()] }
24
- }
18
+ const wowPart = () => ({ type: 'part', children: [cube(), sphere()] })
25
19
 
26
- const flatten = arr =>
20
+ const flatten = (arr) =>
27
21
  arr.reduce(
28
22
  (flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten),
29
23
  []
30
24
  )
31
25
 
32
- function main () {
33
- return flatten([
34
- translate([0, 5, 0], aCoolPart()),
35
- anotherCoolPart()
36
- ])
37
- }
26
+ const main = () => flatten([
27
+ translate([0, 5, 0], aCoolPart()),
28
+ anotherCoolPart(),
29
+ wowPart()
30
+ ])
38
31
 
39
32
  module.exports = main
@@ -1,17 +1,15 @@
1
1
  const { cube, sphere } = require('@jscad/csg/api').primitives3d
2
2
  const { union, difference, intersection } = require('@jscad/csg/api').booleanOps
3
3
 
4
- function main () {
5
- return union(
6
- difference(
7
- cube({ size: 3, center: true }),
8
- sphere({ r: 2, center: true })
9
- ),
10
- intersection(
11
- sphere({ r: 1.3, center: true }),
12
- cube({ size: 2.1, center: true })
13
- )
4
+ const main = () => union(
5
+ difference(
6
+ cube({ size: 3, center: true }),
7
+ sphere({ r: 2, center: true })
8
+ ),
9
+ intersection(
10
+ sphere({ r: 1.3, center: true }),
11
+ cube({ size: 2.1, center: true })
14
12
  )
15
- }
13
+ )
16
14
 
17
15
  module.exports = main
@@ -1,16 +1,14 @@
1
1
  const { cube, sphere, difference, intersection, union } = require('../../core/index')
2
2
 
3
- function main () {
4
- return union(
5
- difference(
6
- cube({ size: 3, center: true }),
7
- sphere({ r: 2, center: true })
8
- ),
9
- intersection(
10
- sphere({ r: 1.3, center: true }),
11
- cube({ size: 2.1, center: true })
12
- )
3
+ const main = () => union(
4
+ difference(
5
+ cube({ size: 3, center: true }),
6
+ sphere({ r: 2, center: true })
7
+ ),
8
+ intersection(
9
+ sphere({ r: 1.3, center: true }),
10
+ cube({ size: 2.1, center: true })
13
11
  )
14
- }
12
+ )
15
13
 
16
14
  module.exports = main
@@ -1,7 +1,5 @@
1
1
  const { cube, sphere } = require('@jscad/csg/api').primitives3d
2
2
 
3
- function main () {
4
- return [cube(), sphere()]
5
- }
3
+ const main = () => [cube(), sphere()]
6
4
 
7
5
  module.exports = main
@@ -1,19 +1,21 @@
1
- const { cube, sphere, difference, intersection, union } = require('../../core/index')
1
+ const { cube, sphere, union } = require('../../core/index')
2
2
 
3
- function aCoolPart () {
4
- return [cube({ name: 'c1' }), cube({ name: 's1' }), sphere({ name: 's2' })]
5
- }
3
+ const aCoolPart = () => [
4
+ cube({ name: 'c1' }),
5
+ cube({ name: 's1' }),
6
+ sphere({ name: 's2' })
7
+ ]
6
8
 
7
- function anotherCoolPart () {
8
- return union(cube({ name: 'c2' }), sphere({ name: 's3' }))
9
- }
9
+ const anotherCoolPart = () => union(cube({ name: 'c2' }), sphere({ name: 's3' }))
10
10
 
11
- function wowPart () {
12
- return { type: 'part', children: [cube(), sphere()] }
13
- }
11
+ const wowPart = () => ({ type: 'part', children: [cube(), sphere()] })
14
12
 
15
- function main () {
16
- return [cube({ name: 'c3' }), sphere({ name: 's4' }), aCoolPart(), anotherCoolPart(), wowPart()]
17
- }
13
+ const main = () => [
14
+ cube({ name: 'c3' }),
15
+ sphere({ name: 's4' }),
16
+ aCoolPart(),
17
+ anotherCoolPart(),
18
+ wowPart()
19
+ ]
18
20
 
19
21
  module.exports = main
@@ -1,7 +1,5 @@
1
- const { cube, sphere, difference, intersection, union } = require('../../core/index')
1
+ const { cube, sphere } = require('../../core/index')
2
2
 
3
- function main () {
4
- return [cube(), sphere()]
5
- }
3
+ const main = () => [cube(), sphere()]
6
4
 
7
5
  module.exports = main
@@ -1,7 +1,5 @@
1
1
  const { cube } = require('../../core/index')
2
2
 
3
- function main () {
4
- return cube({ size: 3, center: true })
5
- }
3
+ const main = () => cube({ size: 3, center: true })
6
4
 
7
5
  module.exports = main
@@ -1,15 +1,12 @@
1
1
  const {
2
- cube, sphere,
3
- difference, intersection, union,
2
+ cube,
4
3
  scale, rotate, translate
5
4
  } = require('../../core/index')
6
5
 
7
- function main () {
8
- return [
9
- translate([0, 5, 0], cube({ size: 10 })),
10
- scale([1, 2, 1], rotate([0, 10, 0], cube({ size: 10 }))),
11
- cube({ size: 10 })
12
- ]
13
- }
6
+ const main = () => [
7
+ translate([0, 5, 0], cube({ size: 10 })),
8
+ scale([1, 2, 1], rotate([0, 10, 0], cube({ size: 10 }))),
9
+ cube({ size: 10 })
10
+ ]
14
11
 
15
12
  module.exports = main
@@ -1,8 +1,6 @@
1
1
  const { cube } = require('@jscad/csg/api').primitives3d
2
2
  const { union } = require('@jscad/csg/api').booleanOps
3
3
 
4
- function main () {
5
- return union([cube(), cube()])
6
- }
4
+ const main = () => union([cube(), cube()])
7
5
 
8
6
  module.exports = main
@@ -1,7 +1,5 @@
1
1
  const { cube, union } = require('../../core/index')
2
2
 
3
- function main () {
4
- return union([cube(), cube()])
5
- }
3
+ const main = () => union([cube(), cube()])
6
4
 
7
5
  module.exports = main
@@ -2,7 +2,7 @@ const serialize = require('serialize-to-js')
2
2
 
3
3
  const deserializeGeometryCache = (cache) => {
4
4
  const data = {}
5
- Object.keys(cache).map(function (key) {
5
+ Object.keys(cache).map((key) => {
6
6
  data[key] = cache[key]// .toCompactBinary()
7
7
  })
8
8
  /* results.forEach(function (result) {
@@ -8,7 +8,7 @@ const serializeGeometryCache = (cache) => {
8
8
  fs.mkdirSync(cachePath)
9
9
  }
10
10
  const data = {}
11
- Object.keys(cache).map(function (key) {
11
+ Object.keys(cache).map((key) => {
12
12
  data[key] = cache[key]// .toCompactBinary()
13
13
  })
14
14
  /* results.forEach(function (result) {
@@ -1,7 +1,7 @@
1
1
  // const decache = require('decache')
2
2
  const child_process = require('child_process')
3
3
 
4
- function runBenchMark (runFn, name, runs = 10) {
4
+ const runBenchMark = (runFn, name, runs = 10) => {
5
5
  console.log('running benchmarks for ' + name + ' ' + runs + ' times')
6
6
 
7
7
  // first verify they all have the same output
@@ -17,7 +17,7 @@ function runBenchMark (runFn, name, runs = 10) {
17
17
  runPass(runFn, runs, name)
18
18
  }
19
19
 
20
- function spawnBenchMark (path, runs = 100) {
20
+ const spawnBenchMark = (path, runs = 100) => {
21
21
  const usage = require('usage')
22
22
  const cpuNumbers = []
23
23
  const memNumbers = []
@@ -25,8 +25,8 @@ function spawnBenchMark (path, runs = 100) {
25
25
  const process = child_process.spawn('node', [path, runs])
26
26
 
27
27
  const pid = process.pid // you can use any valid PID instead
28
- const measureInterval = setInterval(function () {
29
- usage.lookup(pid, function (err, result) {
28
+ const measureInterval = setInterval(() => {
29
+ usage.lookup(pid, (err, result) => {
30
30
  if (err) {
31
31
  console.log('error?', err)
32
32
  }
@@ -37,15 +37,15 @@ function spawnBenchMark (path, runs = 100) {
37
37
  })
38
38
  }, 1000)
39
39
 
40
- process.stdout.on('data', function (data) {
40
+ process.stdout.on('data', (data) => {
41
41
  console.log('' + data)
42
42
  })
43
43
 
44
- process.stderr.on('data', function (data) {
44
+ process.stderr.on('data', (data) => {
45
45
  console.log('' + data)
46
46
  })
47
47
 
48
- process.on('close', function (code) {
48
+ process.on('close', (code) => {
49
49
  // console.log('Child process is exiting with exit code: ' + code)
50
50
  clearInterval(measureInterval)
51
51
 
@@ -62,7 +62,7 @@ const runPass = (runFn, runs, name) => {
62
62
  let start
63
63
 
64
64
  const numbers = []
65
- for (var i = 0; i < runs; i++) {
65
+ for (let i = 0; i < runs; i++) {
66
66
  // decache(moduleName)
67
67
 
68
68
  start = process.hrtime()
@@ -76,7 +76,7 @@ const runPass = (runFn, runs, name) => {
76
76
  // console.log(name + process.hrtime(start)[0] + ' s, ' + elapsed.toFixed(precision) + ' ms - ')
77
77
  }
78
78
 
79
- const median = sequence => {
79
+ const median = (sequence) => {
80
80
  sequence.sort() // note that direction doesn't matter
81
81
  return sequence[Math.ceil(sequence.length / 2)]
82
82
  }