@jwc/jscad-utils 4.9.0 → 5.0.1
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/dist/compat.js +430 -481
- package/dist/examples/bisect.jscad +201 -512
- package/dist/examples/boxes.jscad +201 -512
- package/dist/examples/chamfer.jscad +201 -512
- package/dist/examples/fillet.jscad +201 -512
- package/dist/examples/fit.jscad +201 -512
- package/dist/examples/groups.jscad +201 -512
- package/dist/examples/midlineTo.jscad +201 -512
- package/dist/examples/parts-hexagon.jscad +201 -512
- package/dist/examples/rabett-tb.jscad +201 -512
- package/dist/examples/rabett.jscad +201 -512
- package/dist/examples/rabett2.jscad +201 -512
- package/dist/examples/retraction-test.jscad +201 -512
- package/dist/examples/size.jscad +201 -512
- package/dist/examples/snap.jscad +201 -512
- package/dist/examples/text.jscad +201 -512
- package/dist/examples/wedge.jscad +201 -512
- package/dist/index.js +430 -481
- package/package.json +15 -43
- package/src/add-prototype.js +87 -7
- package/src/color.js +36 -46
- package/src/util.js +24 -22
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jwc/jscad-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Utilities for use in a jscad script.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "src/index.js",
|
|
6
7
|
"module": "src/index.js",
|
|
7
8
|
"files": [
|
|
@@ -10,8 +11,7 @@
|
|
|
10
11
|
"jscad.json"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
|
-
"test": "
|
|
14
|
-
"test:cov": "nyc --reporter=html --reporter=lcov --reporter=text ava",
|
|
14
|
+
"test": "vitest",
|
|
15
15
|
"build": "gulp all",
|
|
16
16
|
"start": "gulp"
|
|
17
17
|
},
|
|
@@ -32,50 +32,22 @@
|
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@jscad/csg": "0.7.0",
|
|
35
|
-
"@jscad/scad-api": "0.5.1"
|
|
35
|
+
"@jscad/scad-api": "0.5.1",
|
|
36
|
+
"@jwc/jscad-test-utils": "3.0.1",
|
|
37
|
+
"@jwc/jscad2-regl-renderer": "3.0.0",
|
|
38
|
+
"gl": "8.1.6",
|
|
39
|
+
"vitepress": "1.6.4",
|
|
40
|
+
"vitest": "3.2.4"
|
|
36
41
|
},
|
|
37
42
|
"devDependencies": {
|
|
38
|
-
"@babel
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"del": "6.1.1",
|
|
43
|
-
"eslint": "7.32.0",
|
|
44
|
-
"eslint-plugin-ava": "11.0.0",
|
|
45
|
-
"gulp": "4.0.2",
|
|
46
|
-
"gulp-debug": "4.0.0",
|
|
43
|
+
"@rollup/plugin-babel": "6.0.4",
|
|
44
|
+
"@rollup/plugin-node-resolve": "16.0.1",
|
|
45
|
+
"gulp": "5.0.1",
|
|
46
|
+
"gulp-debug": "5.0.1",
|
|
47
47
|
"gulp-eslint": "6.0.0",
|
|
48
48
|
"gulp-inject": "5.0.5",
|
|
49
|
-
"gulp-jscad-files": "4.1.0",
|
|
50
|
-
"gulp-jsdoc-to-markdown": "1.2.2",
|
|
51
|
-
"gulp-load-plugins": "2.0.8",
|
|
52
49
|
"gulp-plumber": "1.2.1",
|
|
53
|
-
"gulp-terser": "1.
|
|
54
|
-
"
|
|
55
|
-
"gulp-watch": "5.0.1",
|
|
56
|
-
"nyc": "15.1.0",
|
|
57
|
-
"rollup": "2.79.1",
|
|
58
|
-
"rollup-plugin-babel": "4.4.0",
|
|
59
|
-
"rollup-plugin-commonjs": "4.1.0",
|
|
60
|
-
"rollup-plugin-node-resolve": "5.2.0",
|
|
61
|
-
"vitepress": "1.6.4",
|
|
62
|
-
"vitepress-jsdoc": "1.0.4"
|
|
63
|
-
},
|
|
64
|
-
"ava": {
|
|
65
|
-
"files": [
|
|
66
|
-
"test/**/*.js",
|
|
67
|
-
"!test/helpers/**/*.js"
|
|
68
|
-
],
|
|
69
|
-
"require": [
|
|
70
|
-
"esm",
|
|
71
|
-
"@babel/register",
|
|
72
|
-
"babel-polyfill",
|
|
73
|
-
"./test/helpers/compat-env.js"
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
"babel": {
|
|
77
|
-
"presets": [
|
|
78
|
-
"@babel/preset-env"
|
|
79
|
-
]
|
|
50
|
+
"gulp-terser": "2.1.0",
|
|
51
|
+
"rollup": "4.52.3"
|
|
80
52
|
}
|
|
81
53
|
}
|
package/src/add-prototype.js
CHANGED
|
@@ -1,18 +1,100 @@
|
|
|
1
|
+
/** @typedef {object} ExtendedCSG
|
|
2
|
+
* @property {object} prototype
|
|
3
|
+
* @property {function} prototype.color
|
|
4
|
+
* @property {function} prototype.flush
|
|
5
|
+
* @property {function} prototype.snap
|
|
6
|
+
* @property {function} prototype.calcSnap
|
|
7
|
+
* @property {function} prototype.midlineTo
|
|
8
|
+
* @property {function} prototype.calcmidlineTo
|
|
9
|
+
* @property {function} prototype.centerWith
|
|
10
|
+
* @property {function} prototype.calcCenter
|
|
11
|
+
* @property {function} prototype.align
|
|
12
|
+
* @property {function} prototype.calcAlign
|
|
13
|
+
* @property {function} prototype.enlarge
|
|
14
|
+
* @property {function} prototype.fit
|
|
15
|
+
* @property {function} prototype.size
|
|
16
|
+
* @property {function} prototype.centroid
|
|
17
|
+
* @property {function} prototype.Zero
|
|
18
|
+
* @property {function} prototype.Center
|
|
19
|
+
* @property {function} prototype.fillet
|
|
20
|
+
* @property {function} prototype.chamfer
|
|
21
|
+
* @property {function} prototype.bisect
|
|
22
|
+
* @property {function} prototype.slice
|
|
23
|
+
* @property {function} prototype.wedge
|
|
24
|
+
* @property {function} prototype.stretch
|
|
25
|
+
* @property {function} prototype.unionIf
|
|
26
|
+
* @property {function} prototype.subtractIf
|
|
27
|
+
* @property {function} prototype.translate
|
|
28
|
+
* @property {function} prototype.addConnector
|
|
29
|
+
* @property {function} prototype.connect
|
|
30
|
+
* @property {function} prototype.connectTo
|
|
31
|
+
* @property {object} Vector2D
|
|
32
|
+
* @property {function} Vector2D.prototype.map
|
|
33
|
+
* @property {boolean} prototype._jscadutilsinit
|
|
34
|
+
* @property {function} result
|
|
35
|
+
* @property {function} array.addArray
|
|
36
|
+
* @property {function} unitCube
|
|
37
|
+
* @property {function} depreciated
|
|
38
|
+
* @property {function} error
|
|
39
|
+
* @property {function} size
|
|
40
|
+
* @property {function} centroid
|
|
41
|
+
* @property {function} zero
|
|
42
|
+
* @property {function} calcCenterWith
|
|
43
|
+
* @property {function} fillet
|
|
44
|
+
* @property {function} chamfer
|
|
45
|
+
* @property {function} bisect
|
|
46
|
+
* @property {function} slice
|
|
47
|
+
* @property {function} wedge
|
|
48
|
+
* @property {function} stretch
|
|
49
|
+
* @property {function} addConnector
|
|
50
|
+
* @property {function} echo
|
|
51
|
+
* @property {function} log
|
|
52
|
+
* @property {function} warn
|
|
53
|
+
* @property {function} info
|
|
54
|
+
* @property {function} debug
|
|
55
|
+
* @property {function} table
|
|
56
|
+
* @property {function} dir
|
|
57
|
+
* @property {function} dirxml
|
|
58
|
+
* @property {function} trace
|
|
59
|
+
* @property {function} group
|
|
60
|
+
* @property {function} clear
|
|
61
|
+
* @property {function} count
|
|
62
|
+
* @property {function} countReset
|
|
63
|
+
* @property {function} time
|
|
64
|
+
* @property {function} timeLog
|
|
65
|
+
* @property {function} timeEnd
|
|
66
|
+
* @property {function} assert
|
|
67
|
+
* @property {function} profile
|
|
68
|
+
* @property {function} profileEnd
|
|
69
|
+
* @property {function} timeStamp
|
|
70
|
+
* @property {function} stackTrace
|
|
71
|
+
* @property {function} getConnector
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/** @typedef {import('./color').ColorName} ColorName */
|
|
75
|
+
|
|
76
|
+
/** @typedef {import('@jscad/csg').CSG & ExtendedCSG} CSG */
|
|
1
77
|
import { color } from './color';
|
|
2
78
|
import * as util from './util';
|
|
3
79
|
|
|
4
80
|
/**
|
|
5
81
|
* Initialize `jscad-utils` and add utilities to the `proto` object.
|
|
6
|
-
* @param {
|
|
7
|
-
* @augments proto
|
|
82
|
+
* @param {CSG} proto The global `proto` object
|
|
8
83
|
*/
|
|
9
84
|
export default function init(proto) {
|
|
10
85
|
/**
|
|
11
|
-
* Short
|
|
86
|
+
* Short circuit out if the prototypes have already been added.
|
|
12
87
|
*/
|
|
13
88
|
if (proto.prototype._jscadutilsinit) return;
|
|
14
89
|
|
|
15
|
-
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* @param {ColorName | number} r The red channel value (0.0 - 1.0) or a css color name
|
|
93
|
+
* @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
94
|
+
* @param {number} [b] The blue channel value (0.0 - 1.0)
|
|
95
|
+
* @param {number} [a] The alpha channel value (0.0 - 1.0)
|
|
96
|
+
* @returns {CSG} The colored object
|
|
97
|
+
*/
|
|
16
98
|
proto.prototype.color = function (r, g, b, a) {
|
|
17
99
|
if (!r) return this; // shortcut empty color values to do nothing.
|
|
18
100
|
return color(this, r, g, b, a);
|
|
@@ -45,7 +127,6 @@ export default function init(proto) {
|
|
|
45
127
|
|
|
46
128
|
if (proto.center) echo('proto already has .center');
|
|
47
129
|
proto.prototype.center = function center(axis) {
|
|
48
|
-
// console.log('center', axis, this.getBounds());
|
|
49
130
|
return util.centerWith(this, axis || 'xyz', util.unitCube(), 0);
|
|
50
131
|
};
|
|
51
132
|
|
|
@@ -54,7 +135,6 @@ export default function init(proto) {
|
|
|
54
135
|
};
|
|
55
136
|
|
|
56
137
|
proto.prototype.align = function align(to, axis) {
|
|
57
|
-
// console.log('align', to.getBounds(), axis);
|
|
58
138
|
return util.centerWith(this, axis, to);
|
|
59
139
|
};
|
|
60
140
|
|
|
@@ -130,7 +210,7 @@ export default function init(proto) {
|
|
|
130
210
|
* This modifies the normal `proto.translate` method to accept
|
|
131
211
|
* multiple translations, adding the translations together.
|
|
132
212
|
* The original translate is available on `proto._translate` and
|
|
133
|
-
* a short
|
|
213
|
+
* a short circuit is applied when only one parameter is given.
|
|
134
214
|
* @return {proto} The resulting object.
|
|
135
215
|
*/
|
|
136
216
|
proto.prototype.translate = function translate() {
|
package/src/color.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** @typedef { import('@jscad/csg').CSG } CSG */
|
|
2
|
+
|
|
3
|
+
/** @typedef {"aliceblue"|"antiquewhite"|"aqua"|"aquamarine"|"azure"|"beige"|"bisque"|"black"|"blanchedalmond"|"blue"|"blueviolet"|"brown"|"burlywood"|"cadetblue"|"chartreuse"|"chocolate"|"coral"|"cornflowerblue"|"cornsilk"|"crimson"|"cyan"|"darkblue"|"darkcyan"|"darkgoldenrod"|"darkgray"|"darkgrey"|"darkgreen"|"darkkhaki"|"darkmagenta"|"darkolivegreen"|"darkorange"|"darkorchid"|"darkred"|"darksalmon"|"darkseagreen"|"darkslateblue"|"darkslategray"|"darkslategrey"|"darkturquoise"|"darkviolet"|"deeppink"|"deepskyblue"|"dimgray"|"dimgrey"|"dodgerblue"|"firebrick"|"floralwhite"|"forestgreen"|"fuchsia"|"gainsboro"|"ghostwhite"|"gold"|"goldenrod"|"gray"|"grey"|"green"|"greenyellow"|"honeydew"|"hotpink"|"indianred"|"indigo"|"ivory"|"khaki"|"lavender"|"lavenderblush"|"lawngreen"|"lemonchiffon"|"lightblue"|"lightcoral"|"lightcyan"|"lightgoldenrodyellow"|"lightgray"|"lightgrey"|"lightgreen"|"lightpink"|"lightsalmon"|"lightseagreen"|"lightskyblue"|"lightslategray"|"lightslategrey"|"lightsteelblue"|"lightyellow"|"lime"|"limegreen"|"linen"|"magenta"|"maroon"|"mediumaquamarine"|"mediumblue"|"mediumorchid"|"mediumpurple"|"mediumseagreen"|"mediumslateblue"|"mediumspringgreen"|"mediumturquoise"|"mediumvioletred"|"midnightblue"|"mintcream"|"mistyrose"|"moccasin"|"navajowhite"|"navy"|"oldlace"|"olive"|"olivedrab"|"orange"|"orangered"|"orchid"|"palegoldenrod"|"palegreen"|"paleturquoise"|"palevioletred"|"papayawhip"|"peachpuff"|"peru"|"pink"|"plum"|"powderblue"|"purple"|"red"|"rosybrown"|"royalblue"|"saddlebrown"|"salmon"|"sandybrown"|"seagreen"|"seashell"|"sienna"|"silver"|"skyblue"|"slateblue"|"slategray"|"slategrey"|"snow"|"springgreen"|"steelblue"|"tan"|"teal"|"thistle"|"tomato"|"turquoise"|"violet"|"wheat"|"white"|"whitesmoke"|"yellow"|"yellowgreen"} ColorName */
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Color utilities for jscad. Makes setting colors easier using css color names. Using `.init()` adds a `.color()` function to the CSG object.
|
|
3
7
|
* > You must use `Colors.init(CSG)` in the `main()` function. The `CSG` class is not available before
|
|
@@ -10,7 +14,7 @@
|
|
|
10
14
|
* // draws a purple cube
|
|
11
15
|
* return CSG.cube({radius: [10, 10, 10]}).color('purple');
|
|
12
16
|
*}
|
|
13
|
-
* @type {
|
|
17
|
+
* @type {Record<ColorName, string>}
|
|
14
18
|
*/
|
|
15
19
|
const nameArray = {
|
|
16
20
|
aliceblue: '#f0f8ff',
|
|
@@ -162,12 +166,22 @@ const nameArray = {
|
|
|
162
166
|
yellowgreen: '#9acd32'
|
|
163
167
|
};
|
|
164
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Converts a css color name to a hex string.
|
|
171
|
+
* @param {ColorName} n A css color name
|
|
172
|
+
* @returns {string}
|
|
173
|
+
*/
|
|
165
174
|
export function name2hex(n) {
|
|
166
|
-
n = n.toLowerCase();
|
|
175
|
+
n = /** @type {ColorName} */ (n.toLowerCase());
|
|
167
176
|
if (!nameArray[n]) return 'Invalid Color Name';
|
|
168
177
|
return nameArray[n];
|
|
169
178
|
}
|
|
170
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Converts a hex color string to an rgb array.
|
|
182
|
+
* @param {string} h
|
|
183
|
+
* @returns {number[]}
|
|
184
|
+
*/
|
|
171
185
|
export function hex2rgb(h) {
|
|
172
186
|
h = h.replace(/^\#/, '');
|
|
173
187
|
|
|
@@ -177,65 +191,41 @@ export function hex2rgb(h) {
|
|
|
177
191
|
parseInt(h.substr(2, 2), 16),
|
|
178
192
|
parseInt(h.substr(4, 2), 16)
|
|
179
193
|
];
|
|
194
|
+
} else {
|
|
195
|
+
return [0, 0, 0];
|
|
180
196
|
}
|
|
181
197
|
}
|
|
182
198
|
|
|
199
|
+
/**
|
|
200
|
+
* @type {Record<ColorName, number[]>}
|
|
201
|
+
*/
|
|
183
202
|
const _name2rgb = {};
|
|
184
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Converts a css color name to an rgb array.
|
|
206
|
+
* @param {ColorName} n A css color name
|
|
207
|
+
* @returns {number[]}
|
|
208
|
+
*/
|
|
185
209
|
export function name2rgb(n) {
|
|
186
210
|
if (!_name2rgb[n]) _name2rgb[n] = hex2rgb(name2hex(n));
|
|
187
211
|
return _name2rgb[n];
|
|
188
212
|
}
|
|
189
213
|
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* @param {CSG} o
|
|
217
|
+
* @param {number|string} r The red channel value (0.0 - 1.0) or a css color name
|
|
218
|
+
* @param {number} [g] The green channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
219
|
+
* @param {number} [b] The blue channel value (0.0 - 1.0)
|
|
220
|
+
* @param {number} [a] The alpha channel value (0.0 - 1.0)
|
|
221
|
+
* @returns {CSG} Returns a `CSG` object set to the desired color.
|
|
222
|
+
*/
|
|
190
223
|
export function color(o, r, g, b, a) {
|
|
191
224
|
if (typeof r !== 'string') return o.setColor(r, g, b, a);
|
|
192
225
|
if (r === '') return o; // shortcut for no color
|
|
193
|
-
var c = name2rgb(r).map(function(x) {
|
|
226
|
+
var c = name2rgb(/** @type {ColorName} */(r)).map(function (x) {
|
|
194
227
|
return x / 255;
|
|
195
228
|
});
|
|
196
229
|
c[3] = g || 1.0;
|
|
197
230
|
return o.setColor(c);
|
|
198
231
|
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Initialize the Color utility. This adds a `.color()` prototype to the `CSG` object.
|
|
202
|
-
* @param {CSG} CSG The global `CSG` object
|
|
203
|
-
* @memberof module:jscad-utils-color
|
|
204
|
-
* @augments CSG
|
|
205
|
-
*/
|
|
206
|
-
// init: function init(proto) {
|
|
207
|
-
// // if (proto.setColor) {
|
|
208
|
-
// var _setColor = proto.setColor; // eslint-disable-line no-unused-vars
|
|
209
|
-
|
|
210
|
-
// /**
|
|
211
|
-
// * Set the color of a CSG object using a css color name. Also accepts the normal `setColor()` values.
|
|
212
|
-
// * @example
|
|
213
|
-
// * // creates a red cube
|
|
214
|
-
// * var redcube = CSG.cube({radius: [1, 1, 1]}).color('red');
|
|
215
|
-
// *
|
|
216
|
-
// * // creates a blue cube with the alpha channel at 50%
|
|
217
|
-
// * var bluecube = CSG.cube({radius: [1, 1, 1]}).color('blue', 0.5);
|
|
218
|
-
// *
|
|
219
|
-
// * // creates a green cube with the alpha channel at 25%
|
|
220
|
-
// * // this is the same as the standard setColor
|
|
221
|
-
// * var greencube = proto.cube({radius: [1, 1, 1]}).color(0, 1, 0, 0.25);
|
|
222
|
-
// * @param {(String | Number)} [red or css name] - Css color name or the red color channel value (0.0 - 1.0)
|
|
223
|
-
// * @param {Number} [green or alpha] - green color channel value (0.0 - 1.0) or the alpha channel when used with a css color string
|
|
224
|
-
// * @param {Number} [blue] - blue color channel value (0.0 - 1.0)
|
|
225
|
-
// * @param {Number} [alpha] - alpha channel value (0.0 - 1.0)
|
|
226
|
-
// * @return {CSG} Returns a `CSG` object set to the desired color.
|
|
227
|
-
// * @memberof module:CSG
|
|
228
|
-
// * @alias color
|
|
229
|
-
// * @chainable
|
|
230
|
-
// * @augments CSG
|
|
231
|
-
// */
|
|
232
|
-
// proto.prototype.color = function(r, g, b, a) {
|
|
233
|
-
// if (!r) return this; // shortcut empty color values to do nothing.
|
|
234
|
-
// return Colors.color(this, r, g, b, a);
|
|
235
|
-
// };
|
|
236
|
-
// // } else {
|
|
237
|
-
// // console.error(
|
|
238
|
-
// // `"${proto}" does not have a setColor function to add the Colors prototype to. Make sure the object your trying to decorate with '.color' is correct.`
|
|
239
|
-
// // );
|
|
240
|
-
// // }
|
|
241
|
-
// }
|
package/src/util.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @typedef { import('@jscad/csg').CSG } CSG */
|
|
2
|
+
|
|
1
3
|
import * as array from './array';
|
|
2
4
|
import { Debug } from './debug';
|
|
3
5
|
// import jsCadCSG from '@jscad/csg';
|
|
@@ -26,7 +28,7 @@ export const nearest = {
|
|
|
26
28
|
* Return the largest number that is a multiple of the
|
|
27
29
|
* nozzel size.
|
|
28
30
|
* @param {Number} desired Desired value
|
|
29
|
-
* @param {Number} [nozzel=NOZZEL_SIZE]
|
|
31
|
+
* @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
|
|
30
32
|
* @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
|
|
31
33
|
* @return {Number} Multiple of nozzel size
|
|
32
34
|
*/
|
|
@@ -34,10 +36,10 @@ export const nearest = {
|
|
|
34
36
|
return (Math.floor(desired / nozzel) + nozzie) * nozzel;
|
|
35
37
|
},
|
|
36
38
|
/**
|
|
37
|
-
* Returns the largest number that is a
|
|
39
|
+
* Returns the largest number that is a multiple of the
|
|
38
40
|
* nozzel size, just over the desired value.
|
|
39
41
|
* @param {Number} desired Desired value
|
|
40
|
-
* @param {Number} [nozzel=NOZZEL_SIZE]
|
|
42
|
+
* @param {Number} [nozzel=NOZZEL_SIZE] Nozzel size, defaults to `NOZZEL_SIZE`
|
|
41
43
|
* @param {Number} [nozzie=0] Number of nozzel sizes to add to the value
|
|
42
44
|
* @return {Number} Multiple of nozzel size
|
|
43
45
|
*/
|
|
@@ -47,9 +49,9 @@ export const nearest = {
|
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
|
-
* A function that
|
|
52
|
+
* A function that returns the first argument. Useful when
|
|
51
53
|
* passing in a callback to modify something, and you want a
|
|
52
|
-
* default
|
|
54
|
+
* default function hat does nothing.
|
|
53
55
|
* @param {object} solid an object that will be returned
|
|
54
56
|
* @return {object} the first parameter passed into the function.
|
|
55
57
|
* @function identity
|
|
@@ -59,13 +61,13 @@ export function identity(solid) {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
|
-
* If `f` is a
|
|
64
|
+
* If `f` is a function, it is executed with `object` as the
|
|
63
65
|
* parameter. This is used in `CSG.unionIf` and `CSG.subtractIf`,
|
|
64
66
|
* allowing you to pass a function instead of an object. Since the
|
|
65
|
-
* function isn't
|
|
67
|
+
* function isn't executed until called, the object to `union` or
|
|
66
68
|
* `subtract` can be assembled only if the conditional is true.
|
|
67
69
|
* @param {object} object the context to run the function with.
|
|
68
|
-
* @param {function|object} f if a
|
|
70
|
+
* @param {function|object} f if a function it is executed, otherwise the object is returned.
|
|
69
71
|
* @return {object} the result of the function or the object.
|
|
70
72
|
* @function result
|
|
71
73
|
*/
|
|
@@ -80,10 +82,10 @@ export function result(object, f) {
|
|
|
80
82
|
/**
|
|
81
83
|
* Returns target object with default values assigned. If values already exist, they are not set.
|
|
82
84
|
* @param {object} target The target object to return.
|
|
83
|
-
* @param {object} defaults
|
|
85
|
+
* @param {object} defaults Default values to add to the object if they don't already exist.
|
|
84
86
|
* @return {object} Target object with default values assigned.
|
|
85
87
|
* @function defaults
|
|
86
|
-
* @
|
|
88
|
+
* @deprecated
|
|
87
89
|
*/
|
|
88
90
|
export function defaults(target, defaults) {
|
|
89
91
|
depreciated('defaults', true, 'use Object.assign instead');
|
|
@@ -99,11 +101,11 @@ export function isNegative(n) {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
* Print a message and CSG object bounds and size to the
|
|
104
|
+
* Print a message and CSG object bounds and size to the console.
|
|
103
105
|
* @param {String} msg Message to print
|
|
104
106
|
* @param {CSG} o A CSG object to print the bounds and size of.
|
|
105
107
|
* @function
|
|
106
|
-
* @
|
|
108
|
+
* @deprecated use Debug instead
|
|
107
109
|
*/
|
|
108
110
|
export function print(msg, o) {
|
|
109
111
|
debug(
|
|
@@ -138,11 +140,11 @@ export function error(msg, name, error) {
|
|
|
138
140
|
|
|
139
141
|
/**
|
|
140
142
|
* Shows a warning or error message. Used to indicate a method
|
|
141
|
-
* has been
|
|
143
|
+
* has been deprecated and what to use instead.
|
|
142
144
|
* @function depreciated
|
|
143
|
-
* @param {string} method The name of the method being
|
|
145
|
+
* @param {string} method The name of the method being deprecated.
|
|
144
146
|
* @param {boolean} [error] Throws an error if called when true.
|
|
145
|
-
* @param {string} [message] Instructions on what to use instead of the
|
|
147
|
+
* @param {string} [message] Instructions on what to use instead of the deprecated method.
|
|
146
148
|
*/
|
|
147
149
|
export function depreciated(method, error, message) {
|
|
148
150
|
var msg = method + ' is depreciated.' + (' ' + message || '');
|
|
@@ -243,7 +245,7 @@ export function ifArray(a, cb) {
|
|
|
243
245
|
* Returns an array of positions along an object on a given axis.
|
|
244
246
|
* @param {CSG} object The object to calculate the segments on.
|
|
245
247
|
* @param {number} segments The number of segments to create.
|
|
246
|
-
* @param {string} axis Axis to create the
|
|
248
|
+
* @param {string} axis Axis to create the segments on.
|
|
247
249
|
* @return {Array} An array of segment positions.
|
|
248
250
|
* @function segment
|
|
249
251
|
*/
|
|
@@ -638,7 +640,7 @@ export function centroid(o, objectSize) {
|
|
|
638
640
|
* @param {CSG} o A CSG object.
|
|
639
641
|
* @param {String} axis A string with the axis to operate on.
|
|
640
642
|
* @param {Number} to Value to move the midline of the object to.
|
|
641
|
-
* @return {Number[]} The
|
|
643
|
+
* @return {Number[]} The transform array needed to move the object.
|
|
642
644
|
*/
|
|
643
645
|
export function calcmidlineTo(o, axis, to) {
|
|
644
646
|
var bounds = o.getBounds();
|
|
@@ -684,7 +686,7 @@ export function centerWith(o, axis, withObj) {
|
|
|
684
686
|
* along the axis will be returned. If no `offset`
|
|
685
687
|
* is given, then the midway point on the axis is returned.
|
|
686
688
|
* When the `offset` is positive, a point `offset` from the
|
|
687
|
-
*
|
|
689
|
+
* minimum axis is returned. When the `offset` is negative,
|
|
688
690
|
* the `offset` is subtracted from the axis maximum.
|
|
689
691
|
* @param {Size} size Size array of the object
|
|
690
692
|
* @param {Bounds} bounds Bounds of the object
|
|
@@ -731,7 +733,7 @@ export function getDelta(size, bounds, axis, offset, nonzero) {
|
|
|
731
733
|
*/
|
|
732
734
|
export function bisect(...args) {
|
|
733
735
|
if (args.length < 2) {
|
|
734
|
-
error('bisect
|
|
736
|
+
error('bisect requires an object and an axis', 'JSCAD_UTILS_INVALID_ARGS');
|
|
735
737
|
}
|
|
736
738
|
var object = args[0];
|
|
737
739
|
var axis = args[1];
|
|
@@ -944,7 +946,7 @@ export function wedge(object, start, end, axis) {
|
|
|
944
946
|
* Wraps the `stretchAtPlane` call using the same
|
|
945
947
|
* logic as `bisect`.
|
|
946
948
|
* @param {CSG} object Object to stretch
|
|
947
|
-
* @param {String} axis Axis to
|
|
949
|
+
* @param {String} axis Axis to stretch along
|
|
948
950
|
* @param {Number} distance Distance to stretch
|
|
949
951
|
* @param {Number} offset Offset along the axis to cut the object
|
|
950
952
|
* @return {CSG} The stretched object.
|
|
@@ -1059,7 +1061,7 @@ export function slices2poly(slices, options, axis) {
|
|
|
1059
1061
|
})
|
|
1060
1062
|
);
|
|
1061
1063
|
|
|
1062
|
-
// rotate with quick short
|
|
1064
|
+
// rotate with quick short circuit
|
|
1063
1065
|
var rotate =
|
|
1064
1066
|
twistangle === 0
|
|
1065
1067
|
? function rotateZero(v) {
|
|
@@ -1178,7 +1180,7 @@ export function reShape(object, radius, orientation, options, slicer) {
|
|
|
1178
1180
|
|
|
1179
1181
|
if (si.axis !== 'z')
|
|
1180
1182
|
throw new Error(
|
|
1181
|
-
'reShape error: CAG.
|
|
1183
|
+
'reShape error: CAG._toPlanePolygons only uses the "z" axis. You must use the "z" axis for now.'
|
|
1182
1184
|
);
|
|
1183
1185
|
|
|
1184
1186
|
var cutplane = CSG.OrthoNormalBasis.GetCartesian(
|