@jscad/vtree 2.0.14 → 2.0.15
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 +8 -0
- package/README.md +2 -2
- package/core/api-measurements.js +8 -12
- package/core/buildCachedGeometryFromTree.js +2 -4
- package/core/cacheWithInvalidation.js +2 -2
- package/core/findDisconnectedSubGraphs.js +3 -3
- package/core/generators/geometry-generator-cached-csg.js +11 -13
- package/core/geometry-generator-cached.js +17 -19
- package/core/index.js +5 -5
- package/core/modeling/index-old.js +2 -2
- package/core/modeling/operations/measurements/measureArea.js +2 -2
- package/core/modeling/operations/measurements/measureBounds.js +2 -2
- package/core/modeling/operations/measurements/measureVolume.js +2 -2
- package/core/modeling/primitives/arc.js +1 -1
- package/core/modeling/primitives/cuboid.js +2 -2
- package/core/modeling/primitives/cylinderElliptic.js +2 -2
- package/core/modeling/primitives/line.js +1 -1
- package/core/modeling/primitives/rectangle.js +1 -1
- package/core/objectUtils.js +3 -5
- package/package.json +6 -6
- package/prototyping/examples/basic-base.js +1 -3
- package/prototyping/examples/basic-vtree.js +2 -4
- package/prototyping/examples/caching-shape-measurements.js +3 -3
- package/prototyping/examples/caching-test-vanilla-changed.js +18 -21
- package/prototyping/examples/caching-test-vanilla-changed2.js +16 -19
- package/prototyping/examples/caching-test-vanilla.js +15 -19
- package/prototyping/examples/caching-test-vtree-changed.js +18 -21
- package/prototyping/examples/caching-test-vtree-changed2.js +16 -19
- package/prototyping/examples/caching-test-vtree.js +15 -19
- package/prototyping/examples/caching-test.js +8 -10
- package/prototyping/examples/complex-base.js +19 -26
- package/prototyping/examples/complex-vtree-changed.js +19 -26
- package/prototyping/examples/complex-vtree.js +18 -25
- package/prototyping/examples/logo-base.js +9 -11
- package/prototyping/examples/logo-vtree.js +9 -11
- package/prototyping/examples/shapes-array-base.js +1 -3
- package/prototyping/examples/shapes-array-nested-vtree.js +15 -13
- package/prototyping/examples/shapes-array-vtree.js +2 -4
- package/prototyping/examples/single-shape-vtree.js +1 -3
- package/prototyping/examples/transforms-vtree.js +6 -9
- package/prototyping/examples/union-base.js +1 -3
- package/prototyping/examples/union-vtree.js +1 -3
- package/prototyping/io/deserializeGeometryCache.js +1 -1
- package/prototyping/io/serializeGeometryCache.js +1 -1
- package/prototyping/runBenchmark.js +9 -9
- package/prototyping/runCompare.js +6 -6
- package/vtree-api.js +1 -1
- package/prototyping/io/convertToBlob.js +0 -13
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.0.15](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/vtree@2.0.14...@jscad/vtree@2.0.15) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/vtree
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [2.0.14](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/vtree@2.0.13...@jscad/vtree@2.0.14) (2022-02-19)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @jscad/vtree
|
package/README.md
CHANGED
|
@@ -39,13 +39,13 @@ Some people (need to find their names again, sorry folks !) mentioned AST based
|
|
|
39
39
|
* do diffs of the previous tree structure to determine the changed parts
|
|
40
40
|
* make use of caching when possible:
|
|
41
41
|
* caching of all possible variants of objects is not really feasable (there are infinite possible sizes of even a single cube() for example)
|
|
42
|
-
* but it should be possible to at least cache some
|
|
42
|
+
* but it should be possible to at least cache some 'previous versions' of a design before things change again (since not everything changes at once)
|
|
43
43
|
* perhaps cache each geometry in the csg tree
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
This repository will contain code that tries to explore these possibilities.
|
|
47
47
|
|
|
48
|
-
>It is also important to mention that some
|
|
48
|
+
>It is also important to mention that some experiments here are also inspired by Maker.js by Dan Marshall, particularly the use of 'pojo' (plain old javascript objects) as a way to define shapes
|
|
49
49
|
|
|
50
50
|
## running the benchmarks
|
|
51
51
|
|
package/core/api-measurements.js
CHANGED
|
@@ -3,19 +3,17 @@ const { toArray } = require('./arrays')
|
|
|
3
3
|
const cacheWithInvalidation = require('./cacheWithInvalidation')
|
|
4
4
|
const cachedGenerator = require('./geometry-generator-cached')
|
|
5
5
|
|
|
6
|
-
const makeMeasureArea = specials => {
|
|
6
|
+
const makeMeasureArea = (specials) => {
|
|
7
7
|
const measureArea = (...solids) => {
|
|
8
8
|
// console.log('measure area in overlay api', solids)
|
|
9
9
|
// console.log(arguments[1])
|
|
10
10
|
solids = toArray(solids)
|
|
11
|
-
// we create a
|
|
11
|
+
// we create a preemptive cache
|
|
12
12
|
const cache = cacheWithInvalidation()
|
|
13
13
|
const operands = cachedGenerator(solids, cache)
|
|
14
14
|
|
|
15
15
|
const area = operands.reduce((acc, csg) => {
|
|
16
|
-
const tmpArea = csg.toTriangles().reduce(
|
|
17
|
-
return accSub + triPoly.getTetraFeatures(['area'])[0]
|
|
18
|
-
}, 0)
|
|
16
|
+
const tmpArea = csg.toTriangles().reduce((accSub, triPoly) => accSub + triPoly.getTetraFeatures(['area'])[0], 0)
|
|
19
17
|
return acc + tmpArea
|
|
20
18
|
}, 0)
|
|
21
19
|
|
|
@@ -27,17 +25,15 @@ const makeMeasureArea = specials => {
|
|
|
27
25
|
return measureArea
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
const makeMeasureVolume = specials => {
|
|
28
|
+
const makeMeasureVolume = (specials) => {
|
|
31
29
|
const measureVolume = (...solids) => {
|
|
32
30
|
solids = toArray(solids)
|
|
33
|
-
// we create a
|
|
31
|
+
// we create a preemptive cache
|
|
34
32
|
const cache = cacheWithInvalidation()
|
|
35
33
|
const operands = cachedGenerator(solids, cache)
|
|
36
34
|
|
|
37
35
|
const volume = operands.reduce((acc, csg) => {
|
|
38
|
-
const tmpArea = csg.toTriangles().reduce(
|
|
39
|
-
return accSub + triPoly.getTetraFeatures(['volume'])[0]
|
|
40
|
-
}, 0)
|
|
36
|
+
const tmpArea = csg.toTriangles().reduce((accSub, triPoly) => accSub + triPoly.getTetraFeatures(['volume'])[0], 0)
|
|
41
37
|
return acc + tmpArea
|
|
42
38
|
}, 0)
|
|
43
39
|
|
|
@@ -49,9 +45,9 @@ const makeMeasureVolume = specials => {
|
|
|
49
45
|
return measureVolume
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
const makeMeasureBounds = specials => {
|
|
48
|
+
const makeMeasureBounds = (specials) => {
|
|
53
49
|
const measureBounds = (solid) => {
|
|
54
|
-
// we create a
|
|
50
|
+
// we create a preemptive cache
|
|
55
51
|
const cache = cacheWithInvalidation()
|
|
56
52
|
const operands = cachedGenerator([solid], cache)
|
|
57
53
|
const bounds = operands[0].getBounds()
|
|
@@ -18,9 +18,7 @@ const makeBuildCachedGeometryFromTree = (params) => {
|
|
|
18
18
|
const { passesBeforeElimination, lookup, lookupCounts } = Object.assign({}, defaults, params)
|
|
19
19
|
const cache = makeCacheWithInvalidation(passesBeforeElimination, lookup, lookupCounts)
|
|
20
20
|
|
|
21
|
-
const buildFinalResult = (tree, deep) =>
|
|
22
|
-
return toArray(dfs(tree, cache))
|
|
23
|
-
}
|
|
21
|
+
const buildFinalResult = (tree, deep) => toArray(dfs(tree, cache))
|
|
24
22
|
|
|
25
23
|
// main function, this can be called every time one needs to generate
|
|
26
24
|
// geometry from the vtree
|
|
@@ -50,7 +48,7 @@ const makeBuildCachedGeometryFromTree = (params) => {
|
|
|
50
48
|
const dfs = (node, cache) => {
|
|
51
49
|
// console.log('dfs', node)
|
|
52
50
|
if (node.children) {
|
|
53
|
-
flatten(node.children).forEach(
|
|
51
|
+
flatten(node.children).forEach((childNode) => {
|
|
54
52
|
dfs(childNode, cache)
|
|
55
53
|
})
|
|
56
54
|
}
|
|
@@ -27,9 +27,9 @@ const makeCacheWithInvalidation = (passesBeforeElimination = 1, lookup = {}, loo
|
|
|
27
27
|
const totalHashes = Object.keys(lookup)
|
|
28
28
|
const a = new Set(totalHashes)
|
|
29
29
|
const b = new Set(currentPassHits)
|
|
30
|
-
const hashesWithNoHits = Array.from(new Set([...a].filter(x => !b.has(x))))
|
|
30
|
+
const hashesWithNoHits = Array.from(new Set([...a].filter((x) => !b.has(x))))
|
|
31
31
|
|
|
32
|
-
hashesWithNoHits.forEach(
|
|
32
|
+
hashesWithNoHits.forEach((nodeHash, index) => {
|
|
33
33
|
lookupCounts[nodeHash] -= 1
|
|
34
34
|
// console.log('hashesWithNoHits', nodeHash, index, lookupCounts[nodeHash])
|
|
35
35
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* the script on which the tree is based returns arrays of data will return those
|
|
3
3
|
* @param {} root 'findDisconnectedSubGraphs'
|
|
4
4
|
*/
|
|
5
|
-
const findDisconnectedSubGraphs = root => {
|
|
5
|
+
const findDisconnectedSubGraphs = (root) => {
|
|
6
6
|
// console.log('findDisconnectedSubGraphs')
|
|
7
7
|
if (Array.isArray(root)) {
|
|
8
8
|
root = { children: root, type: 'root' }
|
|
@@ -13,7 +13,7 @@ const findDisconnectedSubGraphs = root => {
|
|
|
13
13
|
const subTrees = []
|
|
14
14
|
dfs(root, stack, leafs, subTrees)
|
|
15
15
|
|
|
16
|
-
// const
|
|
16
|
+
// const independentSubtree = root.children
|
|
17
17
|
// console.log('results subTrees', JSON.stringify(subTrees[0]))
|
|
18
18
|
return subTrees[0]
|
|
19
19
|
}
|
|
@@ -27,7 +27,7 @@ const dfs = (node, stack = [], leafs = [], subTrees, depth = 0) => {
|
|
|
27
27
|
leafs.push(node)
|
|
28
28
|
}
|
|
29
29
|
if (node.children) {
|
|
30
|
-
node.children.forEach(
|
|
30
|
+
node.children.forEach((childNode) => {
|
|
31
31
|
// childNode.parent = node
|
|
32
32
|
dfs(childNode, stack, leafs)
|
|
33
33
|
})
|
|
@@ -12,14 +12,14 @@ const { extrudeLinear, extrudeRotate, extrudeFromSlices, extrudeRectangular } =
|
|
|
12
12
|
const { measureArea, measureVolume, measureBounds } = modeling.measurements
|
|
13
13
|
const { colorize } = modeling.colors
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/** generate actual geometry based on vtree node(s)
|
|
16
16
|
* @param {} node
|
|
17
17
|
* @param {} cache
|
|
18
18
|
*/
|
|
19
19
|
const generate = (node, cache) => {
|
|
20
20
|
let operands
|
|
21
21
|
if (Array.isArray(node)) {
|
|
22
|
-
return flatten(node).map(n => generate(n, cache))
|
|
22
|
+
return flatten(node).map((n) => generate(n, cache))
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const { foundData, nodeHash } = cache.find(node)
|
|
@@ -28,11 +28,11 @@ const generate = (node, cache) => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const nodeWithoutParams = (node, operands, fn) => {
|
|
31
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
31
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
32
32
|
return fn(operands)
|
|
33
33
|
}
|
|
34
34
|
const nodeWithParams = (node, operands, fn) => {
|
|
35
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
35
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
36
36
|
return fn(node.params, operands)
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -70,18 +70,16 @@ const generate = (node, cache) => {
|
|
|
70
70
|
extrudeRectangular: () => nodeWithParams(node, operands, extrudeRectangular),
|
|
71
71
|
extrudeFromSlices: () => nodeWithParams(node, operands, extrudeFromSlices),
|
|
72
72
|
// measurements
|
|
73
|
-
measureArea: () =>
|
|
73
|
+
measureArea: () =>
|
|
74
74
|
// first generate the actual geometry for the items, then compute
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
measureVolume: () => {
|
|
75
|
+
measureArea(flatten(node.children).map((n) => generate(n, cache))),
|
|
76
|
+
measureVolume: () =>
|
|
78
77
|
// first generate the actual geometry for the items, then compute
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
measureBounds: () => {
|
|
78
|
+
measureVolume(flatten(node.children).map((n) => generate(n, cache))),
|
|
79
|
+
measureBounds: () =>
|
|
82
80
|
// first generate the actual geometry for the items, then compute
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
measureBounds(flatten(node.children).map((n) => generate(n, cache)))
|
|
82
|
+
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
const result = lookup[node.type] ? lookup[node.type]() : node
|
|
@@ -10,7 +10,7 @@ const generate = (node, cache) => {
|
|
|
10
10
|
let result
|
|
11
11
|
let operands
|
|
12
12
|
if (Array.isArray(node)) {
|
|
13
|
-
return flatten(node).map(n => generate(n, cache))
|
|
13
|
+
return flatten(node).map((n) => generate(n, cache))
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const { foundData, nodeHash } = cache.find(node)
|
|
@@ -41,67 +41,67 @@ const generate = (node, cache) => {
|
|
|
41
41
|
result = square(node)
|
|
42
42
|
break
|
|
43
43
|
case 'union' :
|
|
44
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
44
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
45
45
|
result = union(operands)
|
|
46
46
|
break
|
|
47
47
|
case 'difference' :
|
|
48
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
48
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
49
49
|
result = difference(operands)
|
|
50
50
|
break
|
|
51
51
|
case 'intersection' :
|
|
52
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
52
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
53
53
|
result = intersection(operands)
|
|
54
54
|
break
|
|
55
55
|
case 'translate':
|
|
56
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
56
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
57
57
|
// console.log('translate::::', node.params, operands)
|
|
58
58
|
result = translate(node.params, operands)
|
|
59
59
|
break
|
|
60
60
|
case 'rotate':
|
|
61
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
61
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
62
62
|
result = rotate(node.params, operands)
|
|
63
63
|
break
|
|
64
64
|
case 'scale':
|
|
65
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
65
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
66
66
|
result = scale(node.params, operands)
|
|
67
67
|
break
|
|
68
68
|
case 'contract':
|
|
69
69
|
console.log('contract', node)
|
|
70
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
70
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
71
71
|
// FIXME: REALLY NEEDED ???
|
|
72
72
|
operands = union(operands)
|
|
73
73
|
result = contract(node.radius, node.n, operands)
|
|
74
74
|
break
|
|
75
75
|
case 'mirror':
|
|
76
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
76
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
77
77
|
result = mirror(node.params, operands)
|
|
78
78
|
break
|
|
79
79
|
case 'hull':
|
|
80
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
80
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
81
81
|
result = hull(operands)
|
|
82
82
|
break
|
|
83
83
|
case 'chain_hull':
|
|
84
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
84
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
85
85
|
result = chain_hull(operands)
|
|
86
86
|
break
|
|
87
87
|
case 'colorize':
|
|
88
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
88
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
89
89
|
result = colorize(node.params, operands)
|
|
90
90
|
break
|
|
91
91
|
case 'linear_extrude':
|
|
92
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
92
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
93
93
|
// FIXME: REALLY NEEDED ???
|
|
94
94
|
operands = union(operands)
|
|
95
95
|
result = linear_extrude(node.params, operands)
|
|
96
96
|
break
|
|
97
97
|
case 'rotate_extrude':
|
|
98
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
98
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
99
99
|
// FIXME: REALLY NEEDED ???
|
|
100
100
|
operands = union(operands)
|
|
101
101
|
result = rotate_extrude(node.params, operands)
|
|
102
102
|
break
|
|
103
103
|
case 'rectangular_extrude':
|
|
104
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
104
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
105
105
|
// operands = flatten(node.children).map(n => generate(n, cache))
|
|
106
106
|
// FIXME: REALLY NEEDED ???
|
|
107
107
|
// operands = union(operands)
|
|
@@ -109,11 +109,9 @@ const generate = (node, cache) => {
|
|
|
109
109
|
break
|
|
110
110
|
case 'measureArea':
|
|
111
111
|
// console.log('actual measure Area')
|
|
112
|
-
operands = flatten(node.children).map(n => generate(n, cache))
|
|
112
|
+
operands = flatten(node.children).map((n) => generate(n, cache))
|
|
113
113
|
result = operands.reduce((acc, csg) => {
|
|
114
|
-
const tmpArea = csg.toTriangles().reduce(
|
|
115
|
-
return accSub + triPoly.getTetraFeatures(['area'])
|
|
116
|
-
}, 0)
|
|
114
|
+
const tmpArea = csg.toTriangles().reduce((accSub, triPoly) => accSub + triPoly.getTetraFeatures(['area']), 0)
|
|
117
115
|
return acc + tmpArea
|
|
118
116
|
}, 0)
|
|
119
117
|
break
|
package/core/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const { toArray, flatten } = require('./arrays')
|
|
3
3
|
|
|
4
|
-
const cube = params => {
|
|
4
|
+
const cube = (params) => {
|
|
5
5
|
/* const defaults = {
|
|
6
6
|
size: [1, 1, 1],
|
|
7
7
|
center: [true, true, true]
|
|
@@ -11,7 +11,7 @@ const cube = params => {
|
|
|
11
11
|
return Object.assign({}, _params, { type: 'cube' })
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const sphere = params => {
|
|
14
|
+
const sphere = (params) => {
|
|
15
15
|
/* const defaults = {
|
|
16
16
|
size: 1,
|
|
17
17
|
center: [true, true, true]
|
|
@@ -21,7 +21,7 @@ const sphere = params => {
|
|
|
21
21
|
return Object.assign({}, _params, { type: 'sphere' })
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const cylinder = params => {
|
|
24
|
+
const cylinder = (params) => {
|
|
25
25
|
const _params = Object.assign({}, params)
|
|
26
26
|
|
|
27
27
|
return Object.assign({}, _params, { type: 'cylinder' })
|
|
@@ -126,7 +126,7 @@ const measureBounds = require('./api-measurements').makeMeasureBounds(specials)
|
|
|
126
126
|
// return {type: 'vector_text', params}
|
|
127
127
|
} */
|
|
128
128
|
|
|
129
|
-
// this is a convenience object, that
|
|
129
|
+
// this is a convenience object, that mimics the structure of the jscad functional api
|
|
130
130
|
const apiClone = {
|
|
131
131
|
primitives3d: {
|
|
132
132
|
cube,
|
|
@@ -207,6 +207,6 @@ module.exports = {
|
|
|
207
207
|
measureVolume,
|
|
208
208
|
measureBounds,
|
|
209
209
|
|
|
210
|
-
//
|
|
210
|
+
// separate
|
|
211
211
|
specials
|
|
212
212
|
}
|
|
@@ -19,7 +19,7 @@ const measureBounds = require('./api-measurements').makeMeasureBounds(specials)
|
|
|
19
19
|
// return {type: 'vector_text', params}
|
|
20
20
|
} */
|
|
21
21
|
|
|
22
|
-
// this is a convenience object, that
|
|
22
|
+
// this is a convenience object, that mimics the structure of the jscad functional api
|
|
23
23
|
const apiClone = {
|
|
24
24
|
primitives3d: {
|
|
25
25
|
cube,
|
|
@@ -100,6 +100,6 @@ module.exports = {
|
|
|
100
100
|
measureVolume,
|
|
101
101
|
measureBounds,
|
|
102
102
|
|
|
103
|
-
//
|
|
103
|
+
// separate
|
|
104
104
|
specials
|
|
105
105
|
}
|
|
@@ -12,7 +12,7 @@ const cachedGenerator = require('../../../generators/geometry-generator-cached-c
|
|
|
12
12
|
* @param {Object} specials - hash of 'specials'
|
|
13
13
|
* @returns {Function} the actual function made for measuring areas
|
|
14
14
|
**/
|
|
15
|
-
const makeMeasureArea = specials => {
|
|
15
|
+
const makeMeasureArea = (specials) => {
|
|
16
16
|
/**
|
|
17
17
|
* Measure the area of the given geometry.
|
|
18
18
|
*
|
|
@@ -22,7 +22,7 @@ const makeMeasureArea = specials => {
|
|
|
22
22
|
**/
|
|
23
23
|
const _measureArea = (...objects) => {
|
|
24
24
|
objects = flatten(objects)
|
|
25
|
-
// we create a
|
|
25
|
+
// we create a preemptive cache
|
|
26
26
|
const cache = cacheWithInvalidation()
|
|
27
27
|
const operands = cachedGenerator(objects, cache)
|
|
28
28
|
|
|
@@ -11,9 +11,9 @@ const cachedGenerator = require('../../../generators/geometry-generator-cached-c
|
|
|
11
11
|
* @param {Object} specials - hash of 'specials'
|
|
12
12
|
* @returns {Function} the actual function made for measuring bounds
|
|
13
13
|
**/
|
|
14
|
-
const makeMeasureBounds = specials => {
|
|
14
|
+
const makeMeasureBounds = (specials) => {
|
|
15
15
|
const _measureBounds = (solids) => {
|
|
16
|
-
// we create a
|
|
16
|
+
// we create a preemptive cache
|
|
17
17
|
const cache = cacheWithInvalidation()
|
|
18
18
|
const operands = cachedGenerator([solids], cache)
|
|
19
19
|
const bounds = measureBounds(operands)
|
|
@@ -12,10 +12,10 @@ const cachedGenerator = require('../../../generators/geometry-generator-cached-c
|
|
|
12
12
|
* @param {Object} specials - hash of 'specials'
|
|
13
13
|
* @returns {Function} the actual function made for measuring volumes
|
|
14
14
|
**/
|
|
15
|
-
const makeMeasureVolume = specials => {
|
|
15
|
+
const makeMeasureVolume = (specials) => {
|
|
16
16
|
const _measureVolume = (...objects) => {
|
|
17
17
|
objects = flatten(objects)
|
|
18
|
-
// we create a
|
|
18
|
+
// we create a preemptive cache
|
|
19
19
|
const cache = cacheWithInvalidation()
|
|
20
20
|
const operands = cachedGenerator(objects, cache)
|
|
21
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const cuboid = params => Object.assign({}, params, { type: 'cuboid' })
|
|
1
|
+
const cuboid = (params) => Object.assign({}, params, { type: 'cuboid' })
|
|
2
2
|
|
|
3
|
-
const cube = params => Object.assign({}, params, { type: 'cube' })
|
|
3
|
+
const cube = (params) => Object.assign({}, params, { type: 'cube' })
|
|
4
4
|
|
|
5
5
|
module.exports = { cuboid, cube }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const cylinder = params => Object.assign({}, params, { type: 'cylinder' })
|
|
1
|
+
const cylinder = (params) => Object.assign({}, params, { type: 'cylinder' })
|
|
2
2
|
|
|
3
|
-
const cylinderElliptic = params => Object.assign({}, params, { type: 'cylinderElliptic' })
|
|
3
|
+
const cylinderElliptic = (params) => Object.assign({}, params, { type: 'cylinderElliptic' })
|
|
4
4
|
|
|
5
5
|
module.exports = { cylinder, cylinderElliptic }
|
package/core/objectUtils.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
const omit = (obj, blacklist) =>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {})
|
|
5
|
-
}
|
|
1
|
+
const omit = (obj, blacklist) => Object.keys(obj)
|
|
2
|
+
.filter((key) => blacklist.indexOf(key) < 0)
|
|
3
|
+
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {})
|
|
6
4
|
|
|
7
5
|
module.exports = { omit }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/vtree",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "Experimental Object Caching for JSCAD",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@jscad/array-utils": "2.1.
|
|
22
|
-
"@jscad/modeling": "2.
|
|
21
|
+
"@jscad/array-utils": "2.1.2",
|
|
22
|
+
"@jscad/modeling": "2.8.0",
|
|
23
23
|
"object-hash": "2.0.3"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@jscad/io-utils": "2.0.
|
|
27
|
-
"@jscad/stl-serializer": "2.1.
|
|
26
|
+
"@jscad/io-utils": "2.0.14",
|
|
27
|
+
"@jscad/stl-serializer": "2.1.4",
|
|
28
28
|
"decache": "4.4.0",
|
|
29
29
|
"just-diff": "2.1.1",
|
|
30
30
|
"serialize-to-js": "3.0.2",
|
|
31
31
|
"simple-diff": "1.6.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "92fb9c75eb070fca5f5ee8c2bab6614b1f54514e"
|
|
34
34
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const {
|
|
2
2
|
cube, sphere,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
union,
|
|
4
|
+
measureArea, measureVolume, measureBounds
|
|
5
5
|
} = require('../../core/index')
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const main = () => {
|
|
8
8
|
const someCube = cube()
|
|
9
9
|
const someSphere = sphere({ r: 20, fn: 100 })
|
|
10
10
|
const shapesSize = measureArea(union(someCube, someSphere)) * 0.1
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
const { cube, sphere } = require('@jscad/csg/api').primitives3d
|
|
2
|
-
const { union
|
|
3
|
-
const { translate, rotate
|
|
2
|
+
const { union } = require('@jscad/csg/api').booleanOps
|
|
3
|
+
const { translate, rotate } = require('@jscad/csg/api').transformations
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
sphere({ fn: 128 })
|
|
22
|
-
]
|
|
23
|
-
}
|
|
5
|
+
const foo = () => [
|
|
6
|
+
cube(),
|
|
7
|
+
translate([13, 0, 0], cube()),
|
|
8
|
+
sphere({ fn: 128 })
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
const main = () => [
|
|
12
|
+
foo(),
|
|
13
|
+
cube(),
|
|
14
|
+
translate([13, 0, 0], cube()),
|
|
15
|
+
translate([0, 0, 2], sphere()),
|
|
16
|
+
union(cube(), sphere()),
|
|
17
|
+
translate([23, 0, 0], cube()),
|
|
18
|
+
rotate([13, 0, 0], cube()),
|
|
19
|
+
sphere({ fn: 128 })
|
|
20
|
+
]
|
|
24
21
|
|
|
25
22
|
module.exports = main
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
const { cube, sphere } = require('@jscad/csg/api').primitives3d
|
|
2
|
-
const { union
|
|
3
|
-
const { translate, rotate
|
|
2
|
+
const { union } = require('@jscad/csg/api').booleanOps
|
|
3
|
+
const { translate, rotate } = require('@jscad/csg/api').transformations
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
rotate([13, 0, 0], cube())
|
|
20
|
-
]
|
|
21
|
-
}
|
|
5
|
+
const foo = () => [
|
|
6
|
+
cube(),
|
|
7
|
+
translate([13, 0, 0], cube())
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
const main = () => [
|
|
11
|
+
foo(),
|
|
12
|
+
cube(),
|
|
13
|
+
translate([13, 0, 0], cube()),
|
|
14
|
+
translate([0, 0, 2], sphere()),
|
|
15
|
+
union(cube(), sphere()),
|
|
16
|
+
translate([23, 0, 0], cube()),
|
|
17
|
+
rotate([13, 0, 0], cube())
|
|
18
|
+
]
|
|
22
19
|
|
|
23
20
|
module.exports = main
|