From 6c0cb4aae6f03a38f6f77f82db2d8e5b1166d8d8 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 6 Sep 2023 18:01:59 -0700 Subject: [PATCH] feat(modeling): removed extrudeRectangular --- .../extrusions/extrudeRectangular.d.ts | 15 ---- .../extrusions/extrudeRectangular.js | 43 ----------- .../extrusions/extrudeRectangular.test.js | 75 ------------------- .../extrusions/extrudeRectangularGeom2.js | 46 ------------ .../extrusions/extrudeRectangularPath2.js | 31 -------- .../src/operations/extrusions/index.d.ts | 1 - .../src/operations/extrusions/index.js | 3 +- 7 files changed, 1 insertion(+), 213 deletions(-) delete mode 100644 packages/modeling/src/operations/extrusions/extrudeRectangular.d.ts delete mode 100644 packages/modeling/src/operations/extrusions/extrudeRectangular.js delete mode 100644 packages/modeling/src/operations/extrusions/extrudeRectangular.test.js delete mode 100644 packages/modeling/src/operations/extrusions/extrudeRectangularGeom2.js delete mode 100644 packages/modeling/src/operations/extrusions/extrudeRectangularPath2.js 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 cdb698baf..000000000 --- a/packages/modeling/src/operations/extrusions/extrudeRectangular.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { Path2, Geom2, Geom3 } from '../../geometries/types.d.ts' -import type { Corners } from '../../utils/corners.d.ts' -import type { RecursiveArray } from '../../utils/recursiveArray.d.ts' - -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 325e76bdc..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 9f6fd7710..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 cc0baac49..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 67079129f..0e9d42e15 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.js' export { extrudeLinear, ExtrudeLinearOptions } from './extrudeLinear.js' -export { extrudeRectangular, ExtrudeRectangularOptions } from './extrudeRectangular.js' export { extrudeRotate, ExtrudeRotateOptions } from './extrudeRotate.js' export { extrudeHelical, ExtrudeHelicalOptions } from './extrudeHelical.js' export { project, ProjectOptions } from './project.js' 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'