modeling/src/primitives/cube.js

  1. const cuboid = require('./cuboid')
  2. const { isGTE } = require('./commonChecks')
  3. /**
  4. * Construct an axis-aligned solid cube in three dimensional space with six square faces.
  5. * @see [cuboid]{@link module:modeling/primitives.cuboid} for more options
  6. * @param {Object} [options] - options for construction
  7. * @param {Array} [options.center=[0,0,0]] - center of cube
  8. * @param {Number} [options.size=2] - dimension of cube
  9. * @returns {geom3} new 3D geometry
  10. * @alias module:modeling/primitives.cube
  11. * @example
  12. * let myshape = cube({size: 10})
  13. */
  14. const cube = (options) => {
  15. const defaults = {
  16. center: [0, 0, 0],
  17. size: 2
  18. }
  19. let { center, size } = Object.assign({}, defaults, options)
  20. if (!isGTE(size, 0)) throw new Error('size must be positive')
  21. size = [size, size, size]
  22. return cuboid({ center, size })
  23. }
  24. module.exports = cube