diff --git a/packages/modeling/src/operations/extrusions/extrudeRectangular.d.ts b/packages/modeling/src/operations/extrusions/extrudeRectangular.d.ts deleted file mode 100644 index 7f503eb05..000000000 --- a/packages/modeling/src/operations/extrusions/extrudeRectangular.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Path2, Geom2, Geom3 } from '../../geometries/types' -import { Corners } from '../../utils/corners' -import RecursiveArray from '../../utils/recursiveArray' - -export interface ExtrudeRectangularOptions { - size?: number - height?: number - corners?: Corners - segments?: number -} - -type Geometry = Path2 | Geom2 - -export function extrudeRectangular(options: ExtrudeRectangularOptions, geometry: Geometry): Geom3 -export function extrudeRectangular(options: ExtrudeRectangularOptions, ...geometries: RecursiveArray): Geom3 diff --git a/packages/modeling/src/operations/extrusions/extrudeRectangular.js b/packages/modeling/src/operations/extrusions/extrudeRectangular.js deleted file mode 100644 index ccacaba39..000000000 --- a/packages/modeling/src/operations/extrusions/extrudeRectangular.js +++ /dev/null @@ -1,43 +0,0 @@ -import { flatten } from '../../utils/flatten.js' - -import * as geom2 from '../../geometries/geom2/index.js' -import * as path2 from '../../geometries/path2/index.js' - -import { extrudeRectangularPath2 } from './extrudeRectangularPath2.js' -import { extrudeRectangularGeom2 } from './extrudeRectangularGeom2.js' - -/** - * Extrude the given geometry by following the outline(s) with a rectangle. - * @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 {...Object} objects - the geometries to extrude - * @return {Object|Array} the extruded object, or a list of extruded objects - * @alias module:modeling/extrusions.extrudeRectangular - * - * @example - * let myWalls = extrudeRectangular({size: 1, height: 3}, square({size: 20})) - * let myWalls = extrudeRectangular({size: 1, height: 300, twistAngle: TAU / 2}, square({size: 20})) - */ -export const extrudeRectangular = (options, ...objects) => { - const defaults = { - size: 1, - height: 1 - } - const { size, height } = Object.assign({}, defaults, options) - - objects = flatten(objects) - if (objects.length === 0) throw new Error('wrong number of arguments') - - if (size <= 0) throw new Error('size must be positive') - if (height <= 0) throw new Error('height must be positive') - - const results = objects.map((object) => { - if (path2.isA(object)) return extrudeRectangularPath2(options, object) - if (geom2.isA(object)) return extrudeRectangularGeom2(options, object) - // if (geom3.isA(object)) return geom3.transform(matrix, object) - return object - }) - return results.length === 1 ? results[0] : results -} diff --git a/packages/modeling/src/operations/extrusions/extrudeRectangular.test.js b/packages/modeling/src/operations/extrusions/extrudeRectangular.test.js deleted file mode 100644 index 0da90bafd..000000000 --- a/packages/modeling/src/operations/extrusions/extrudeRectangular.test.js +++ /dev/null @@ -1,75 +0,0 @@ -import test from 'ava' - -import { TAU } from '../../maths/constants.js' - -import { geom2, geom3 } from '../../geometries/index.js' - -import { measureVolume } from '../../measurements/index.js' - -import { arc, rectangle } from '../../primitives/index.js' - -import { extrudeRectangular } from './index.js' - -test('extrudeRectangular (defaults)', (t) => { - const geometry1 = arc({ radius: 5, endAngle: TAU / 4, segments: 16 }) - const geometry2 = rectangle({ size: [5, 5] }) - - let obs = extrudeRectangular({ }, geometry1) - let pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 15.643446504023084) - t.is(pts.length, 44) - - obs = extrudeRectangular({ }, geometry2) - pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 40) - t.is(pts.length, 32) -}) - -test('extrudeRectangular (chamfer)', (t) => { - const geometry1 = arc({ radius: 5, endAngle: TAU / 4, segments: 16 }) - const geometry2 = rectangle({ size: [5, 5] }) - - let obs = extrudeRectangular({ corners: 'chamfer' }, geometry1) - let pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 15.627942731474823) - t.is(pts.length, 60) - - obs = extrudeRectangular({ corners: 'chamfer' }, geometry2) - pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 38) - t.is(pts.length, 48) -}) - -test('extrudeRectangular (segments = 8, round)', (t) => { - const geometry1 = arc({ radius: 5, endAngle: TAU / 4, segments: 16 }) - const geometry2 = rectangle({ size: [5, 5] }) - - let obs = extrudeRectangular({ segments: 8, corners: 'round' }, geometry1) - let pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 18.456369856221006) - t.is(pts.length, 84) - - obs = extrudeRectangular({ segments: 8, corners: 'round' }, geometry2) - pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 38.828427124746185) - t.is(pts.length, 64) -}) - -test('extrudeRectangular (holes)', (t) => { - const geometry2 = geom2.create([ - [[-15, 15], [-15, -15], [15, -15], [15, 15]], - [[5, 5], [5, -5], [-5, -5], [-5, 5]] - ]) - - const obs = extrudeRectangular({ size: 2, height: 15, segments: 16, corners: 'round' }, geometry2) - const pts = geom3.toPoints(obs) - t.notThrows(() => geom3.validate(obs)) - t.is(measureVolume(obs), 9487.376095070491) - t.is(pts.length, 192) -}) diff --git a/packages/modeling/src/operations/extrusions/extrudeRectangularGeom2.js b/packages/modeling/src/operations/extrusions/extrudeRectangularGeom2.js deleted file mode 100644 index 302bcea72..000000000 --- a/packages/modeling/src/operations/extrusions/extrudeRectangularGeom2.js +++ /dev/null @@ -1,46 +0,0 @@ -import { area } from '../../maths/utils/area.js' - -import * as geom2 from '../../geometries/geom2/index.js' -import * as path2 from '../../geometries/path2/index.js' - -import { offset } from '../offsets/offset.js' - -import { extrudeLinearGeom2 } from './extrudeLinearGeom2.js' - -/* - * Expand and extrude the given geometry (geom2). - * @see offset for additional 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 {geom2} geometry - the geometry to extrude - * @return {geom3} the extruded geometry - */ -export const extrudeRectangularGeom2 = (options, geometry) => { - const defaults = { - size: 1, - height: 1 - } - const { size, height } = Object.assign({ }, defaults, options) - - options.delta = size - options.offset = [0, 0, height] - - // convert the geometry to outlines - const outlines = geom2.toOutlines(geometry) - if (outlines.length === 0) throw new Error('the given geometry cannot be empty') - - // create a composite geometry - let expanded = [] - outlines.forEach((outline) => { - if (area(outline) < 0) { - outline = outline.slice().reverse() // all outlines must wind counterclockwise - } - // expand the outline - const part = offset(options, path2.fromPoints({ closed: true }, outline)) - expanded = expanded.concat(geom2.toOutlines(part)) - }) - const newGeometry = geom2.create(expanded) - - return extrudeLinearGeom2(options, newGeometry) -} diff --git a/packages/modeling/src/operations/extrusions/extrudeRectangularPath2.js b/packages/modeling/src/operations/extrusions/extrudeRectangularPath2.js deleted file mode 100644 index 479ac10d7..000000000 --- a/packages/modeling/src/operations/extrusions/extrudeRectangularPath2.js +++ /dev/null @@ -1,31 +0,0 @@ -import * as path2 from '../../geometries/path2/index.js' - -import { offset } from '../offsets/offset.js' - -import { extrudeLinearGeom2 } from './extrudeLinearGeom2.js' - -/* - * 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 - */ -export 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 = offset(options, geometry) - return extrudeLinearGeom2(options, newGeometry) -} diff --git a/packages/modeling/src/operations/extrusions/index.d.ts b/packages/modeling/src/operations/extrusions/index.d.ts index 4868db248..06ebca808 100644 --- a/packages/modeling/src/operations/extrusions/index.d.ts +++ b/packages/modeling/src/operations/extrusions/index.d.ts @@ -1,6 +1,5 @@ export { extrudeFromSlices, ExtrudeFromSlicesOptions } from './extrudeFromSlices' export { extrudeLinear, ExtrudeLinearOptions } from './extrudeLinear' -export { extrudeRectangular, ExtrudeRectangularOptions } from './extrudeRectangular' export { extrudeRotate, ExtrudeRotateOptions } from './extrudeRotate' export { extrudeHelical, ExtrudeHelicalOptions } from './extrudeHelical' export { project, ProjectOptions } from './project' diff --git a/packages/modeling/src/operations/extrusions/index.js b/packages/modeling/src/operations/extrusions/index.js index d1a222ff5..7dd165b90 100644 --- a/packages/modeling/src/operations/extrusions/index.js +++ b/packages/modeling/src/operations/extrusions/index.js @@ -4,11 +4,10 @@ * @module modeling/extrusions * @example * import { extrusions } from '@jscad/modeling' - * const { extrudeFromSlices, extrudeLinear, extrudeRectangular, extrudeRotate, project } = extrusions + * const { extrudeFromSlices, extrudeHelical, extrudeLinear, extrudeRotate, project } = extrusions */ export { extrudeFromSlices } from './extrudeFromSlices.js' export { extrudeLinear } from './extrudeLinear.js' -export { extrudeRectangular } from './extrudeRectangular.js' export { extrudeRotate } from './extrudeRotate.js' export { extrudeHelical } from './extrudeHelical.js' export { project } from './project.js'