Skip to content

Commit a2ddcb9

Browse files
committed
merged cube and cuboid
1 parent c581efa commit a2ddcb9

File tree

1 file changed

+4
-40
lines changed

1 file changed

+4
-40
lines changed

csg.js

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -160,57 +160,21 @@ CSG.prototype = {
160160
}
161161
};
162162

163-
// Construct an axis-aligned solid cube. Optional parameters are `center` and
164-
// `radius`, which default to `[0, 0, 0]` and `1`.
165-
//
166-
// Example code:
167-
//
168-
// var cube = CSG.cube({
169-
// center: [0, 0, 0],
170-
// radius: 1
171-
// });
172-
CSG.cube = function(options) {
173-
options = options || {};
174-
var c = new CSG.Vector(options.center || [0, 0, 0]);
175-
var r = options.radius || 1;
176-
return CSG.fromPolygons([
177-
[[0, 4, 6, 2], [-1, 0, 0]],
178-
[[1, 3, 7, 5], [+1, 0, 0]],
179-
[[0, 1, 5, 4], [0, -1, 0]],
180-
[[2, 6, 7, 3], [0, +1, 0]],
181-
[[0, 2, 3, 1], [0, 0, -1]],
182-
[[4, 5, 7, 6], [0, 0, +1]]
183-
].map(function(info) {
184-
return new CSG.Polygon(info[0].map(function(i) {
185-
var pos = new CSG.Vector(
186-
c.x + r * (2 * !!(i & 1) - 1),
187-
c.y + r * (2 * !!(i & 2) - 1),
188-
c.z + r * (2 * !!(i & 4) - 1)
189-
);
190-
return new CSG.Vertex(pos, new CSG.Vector(info[1]));
191-
}));
192-
}));
193-
};
194-
195163
// Construct an axis-aligned solid cuboid. Optional parameters are `center` and
196164
// `radius`, which default to `[0, 0, 0]` and `[1, 1, 1]`. The radius can be
197165
// specified using a single number or a list of three numbers, one for each axis.
198-
//
166+
//
199167
// Example code:
200-
//
168+
//
201169
// var cube = CSG.cube({
202170
// center: [0, 0, 0],
203171
// radius: 1
204172
// });
205173
CSG.cube = function(options) {
206174
options = options || {};
207175
var c = new CSG.Vector(options.center || [0, 0, 0]);
208-
var r = ( !options.radius ) ?
209-
( [ 1, 1, 1 ] ) :
210-
( options.radius.length ?
211-
options.radius :
212-
[ options.radius, options.radius, options.radius ]
213-
);
176+
var r = !options.radius ? [1, 1, 1] : options.radius.length ?
177+
options.radius : [options.radius, options.radius, options.radius];
214178
return CSG.fromPolygons([
215179
[[0, 4, 6, 2], [-1, 0, 0]],
216180
[[1, 3, 7, 5], [+1, 0, 0]],

0 commit comments

Comments
 (0)