@jscad/modeling
Version:
Constructive Solid Geometry (CSG) Library for JSCAD
34 lines (26 loc) • 1.03 kB
JavaScript
const path2 = require('../../geometries/path2')
const expand = require('../expansions/expand')
const extrudeLinearGeom2 = require('./extrudeLinearGeom2')
/*
* Expand and extrude the given geometry (path2).
* @See expand for addition options
* @param {Object} options - options for extrusion, if any
* @param {Number} [options.size=1] - size of the rectangle
* @param {Number} [options.height=1] - height of the extrusion
* @param {path2} geometry - the geometry to extrude
* @return {geom3} the extruded geometry
*/
const extrudeRectangularPath2 = (options, geometry) => {
const defaults = {
size: 1,
height: 1
}
const { size, height } = Object.assign({ }, defaults, options)
options.delta = size
options.offset = [0, 0, height]
const points = path2.toPoints(geometry)
if (points.length === 0) throw new Error('the given geometry cannot be empty')
const newgeometry = expand(options, geometry)
return extrudeLinearGeom2(options, newgeometry)
}
module.exports = extrudeRectangularPath2