From a0506d1389476b0fea3040fbd1c736e4aa3a7d16 Mon Sep 17 00:00:00 2001 From: Kenny Daniel Date: Wed, 25 Jan 2023 12:38:40 -0800 Subject: [PATCH] No geometry clone --- packages/modeling/src/colors/colorize.js | 16 +++------ packages/modeling/src/connectors/create.js | 2 +- .../modeling/src/geometries/geom2/clone.d.ts | 3 -- .../modeling/src/geometries/geom2/clone.js | 7 ---- .../src/geometries/geom2/clone.test.js | 26 -------------- .../src/geometries/geom2/fromCompactBinary.js | 2 +- .../modeling/src/geometries/geom2/index.d.ts | 1 - .../modeling/src/geometries/geom2/index.js | 1 - .../modeling/src/geometries/geom2/reverse.js | 3 +- .../modeling/src/geometries/geom3/clone.d.ts | 3 -- .../modeling/src/geometries/geom3/clone.js | 7 ---- .../src/geometries/geom3/clone.test.js | 31 ---------------- .../src/geometries/geom3/fromCompactBinary.js | 2 +- .../modeling/src/geometries/geom3/index.d.ts | 1 - .../modeling/src/geometries/geom3/index.js | 1 - .../src/geometries/path2/appendArc.js | 5 ++- .../modeling/src/geometries/path2/clone.d.ts | 3 -- .../modeling/src/geometries/path2/clone.js | 7 ---- .../modeling/src/geometries/path2/close.js | 4 +-- .../src/geometries/path2/fromCompactBinary.js | 2 +- .../src/geometries/path2/fromPoints.js | 3 +- .../modeling/src/geometries/path2/index.d.ts | 1 - .../modeling/src/geometries/path2/index.js | 1 - .../modeling/src/geometries/path2/reverse.js | 3 +- .../modeling/src/geometries/poly2/clone.d.ts | 3 -- .../modeling/src/geometries/poly2/clone.js | 8 ----- .../src/geometries/poly2/clone.test.js | 17 --------- .../modeling/src/geometries/poly2/index.d.ts | 1 - .../modeling/src/geometries/poly2/index.js | 1 - .../modeling/src/geometries/poly3/clone.d.ts | 4 --- .../modeling/src/geometries/poly3/clone.js | 26 -------------- .../src/geometries/poly3/clone.test.js | 36 ------------------- .../modeling/src/geometries/poly3/index.d.ts | 1 - .../modeling/src/geometries/poly3/index.js | 1 - .../modeling/src/geometries/slice/clone.d.ts | 3 -- .../modeling/src/geometries/slice/clone.js | 9 ----- .../src/geometries/slice/clone.test.js | 14 -------- .../modeling/src/geometries/slice/index.d.ts | 1 - .../modeling/src/geometries/slice/index.js | 1 - .../src/maths/line2/intersectPointOfLines.js | 7 ++-- .../operations/booleans/subtractGeom3Sub.js | 2 +- .../extrusions/extrudeLinearGeom2.js | 7 ++-- packages/modeling/src/primitives/arc.js | 5 ++- packages/modeling/src/primitives/ellipse.js | 5 ++- packages/modeling/src/primitives/star.js | 6 ++-- 45 files changed, 25 insertions(+), 268 deletions(-) delete mode 100644 packages/modeling/src/geometries/geom2/clone.d.ts delete mode 100644 packages/modeling/src/geometries/geom2/clone.js delete mode 100644 packages/modeling/src/geometries/geom2/clone.test.js delete mode 100644 packages/modeling/src/geometries/geom3/clone.d.ts delete mode 100644 packages/modeling/src/geometries/geom3/clone.js delete mode 100644 packages/modeling/src/geometries/geom3/clone.test.js delete mode 100644 packages/modeling/src/geometries/path2/clone.d.ts delete mode 100644 packages/modeling/src/geometries/path2/clone.js delete mode 100644 packages/modeling/src/geometries/poly2/clone.d.ts delete mode 100644 packages/modeling/src/geometries/poly2/clone.js delete mode 100644 packages/modeling/src/geometries/poly2/clone.test.js delete mode 100644 packages/modeling/src/geometries/poly3/clone.d.ts delete mode 100644 packages/modeling/src/geometries/poly3/clone.js delete mode 100644 packages/modeling/src/geometries/poly3/clone.test.js delete mode 100644 packages/modeling/src/geometries/slice/clone.d.ts delete mode 100644 packages/modeling/src/geometries/slice/clone.js delete mode 100644 packages/modeling/src/geometries/slice/clone.test.js diff --git a/packages/modeling/src/colors/colorize.js b/packages/modeling/src/colors/colorize.js index 3a38b943a..1555733dc 100644 --- a/packages/modeling/src/colors/colorize.js +++ b/packages/modeling/src/colors/colorize.js @@ -6,27 +6,19 @@ import * as path2 from '../geometries/path2/index.js' import * as poly3 from '../geometries/poly3/index.js' const colorGeom2 = (color, object) => { - const newGeom2 = geom2.clone(object) - newGeom2.color = color - return newGeom2 + return Object.assign({}, object, { color }) } const colorGeom3 = (color, object) => { - const newGeom3 = geom3.clone(object) - newGeom3.color = color - return newGeom3 + return Object.assign({}, object, { color }) } const colorPath2 = (color, object) => { - const newPath2 = path2.clone(object) - newPath2.color = color - return newPath2 + return Object.assign({}, object, { color }) } const colorPoly3 = (color, object) => { - const newPoly = poly3.clone(object) - newPoly.color = color - return newPoly + return Object.assign({}, object, { color }) } /** diff --git a/packages/modeling/src/connectors/create.js b/packages/modeling/src/connectors/create.js index 00e122e3b..d5a418b81 100644 --- a/packages/modeling/src/connectors/create.js +++ b/packages/modeling/src/connectors/create.js @@ -18,4 +18,4 @@ import * as vec3 from '../maths/vec3/index.js' * @example * let myConnector = create() */ -export const create = () => ({ point: vec3.create(), axis: vec3.clone([0, 0, 1]), normal: vec3.clone([1, 0, 0]) }) +export const create = () => ({ point: vec3.create(), axis: [0, 0, 1], normal: [1, 0, 0] }) diff --git a/packages/modeling/src/geometries/geom2/clone.d.ts b/packages/modeling/src/geometries/geom2/clone.d.ts deleted file mode 100644 index e4bc0279a..000000000 --- a/packages/modeling/src/geometries/geom2/clone.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Geom2 } from './type' - -export function clone(geometry: Geom2): Geom2 diff --git a/packages/modeling/src/geometries/geom2/clone.js b/packages/modeling/src/geometries/geom2/clone.js deleted file mode 100644 index a57c191e2..000000000 --- a/packages/modeling/src/geometries/geom2/clone.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Performs a shallow clone of the given geometry. - * @param {geom2} geometry - the geometry to clone - * @returns {geom2} new geometry - * @alias module:modeling/geometries/geom2.clone - */ -export const clone = (geometry) => Object.assign({}, geometry) diff --git a/packages/modeling/src/geometries/geom2/clone.test.js b/packages/modeling/src/geometries/geom2/clone.test.js deleted file mode 100644 index 3a1d82f67..000000000 --- a/packages/modeling/src/geometries/geom2/clone.test.js +++ /dev/null @@ -1,26 +0,0 @@ -import test from 'ava' - -import { clone, create } from './index.js' - -test('clone: Creates a clone on an empty geom2', (t) => { - const expected = { - outlines: [], - transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] - } - const geometry = create() - const another = clone(geometry) - t.not(another, geometry) - t.deepEqual(another, expected) -}) - -test('clone: Creates a clone of a complete geom2', (t) => { - const points = [[0, 0], [1, 0], [0, 1]] - const expected = { - outlines: [[[0, 0], [1, 0], [0, 1]]], - transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] - } - const geometry = create([points]) - const another = clone(geometry) - t.not(another, geometry) - t.deepEqual(another, expected) -}) diff --git a/packages/modeling/src/geometries/geom2/fromCompactBinary.js b/packages/modeling/src/geometries/geom2/fromCompactBinary.js index df4045ac4..dcb7b82ee 100644 --- a/packages/modeling/src/geometries/geom2/fromCompactBinary.js +++ b/packages/modeling/src/geometries/geom2/fromCompactBinary.js @@ -14,7 +14,7 @@ export const fromCompactBinary = (data) => { const created = create() - created.transforms = mat4.clone(data.slice(1, 17)) + created.transforms = data.slice(1, 17) for (let i = 21; i < data.length;) { const length = data[i++] // number of points for this polygon diff --git a/packages/modeling/src/geometries/geom2/index.d.ts b/packages/modeling/src/geometries/geom2/index.d.ts index 381ec4b9a..ab5143e47 100644 --- a/packages/modeling/src/geometries/geom2/index.d.ts +++ b/packages/modeling/src/geometries/geom2/index.d.ts @@ -1,4 +1,3 @@ -export { clone } from './clone' export { create } from './create' export { fromSides } from './fromSides' export { fromCompactBinary } from './fromCompactBinary' diff --git a/packages/modeling/src/geometries/geom2/index.js b/packages/modeling/src/geometries/geom2/index.js index 86dd2e1d3..54a374954 100644 --- a/packages/modeling/src/geometries/geom2/index.js +++ b/packages/modeling/src/geometries/geom2/index.js @@ -8,7 +8,6 @@ * import { geometries } from '@jscad/modeling' * let myShape = geometries.geom2.create([ [[-1,-1], [1,-1], [1,1], [-1,1]] ]) */ -export { clone } from './clone.js' export { create } from './create.js' export { fromSides } from './fromSides.js' export { fromCompactBinary } from './fromCompactBinary.js' diff --git a/packages/modeling/src/geometries/geom2/reverse.js b/packages/modeling/src/geometries/geom2/reverse.js index 51704f939..b5ded0e7a 100644 --- a/packages/modeling/src/geometries/geom2/reverse.js +++ b/packages/modeling/src/geometries/geom2/reverse.js @@ -1,4 +1,3 @@ -import { clone } from './clone.js' /** * Reverses the given geometry so that the outline points are flipped in the opposite order. @@ -11,7 +10,7 @@ import { clone } from './clone.js' * let newGeometry = reverse(geometry) */ export const reverse = (geometry) => { - const reversed = clone(geometry) + const reversed = Object.assign({}, geometry) reversed.outlines = reversed.outlines.map((outline) => outline.slice().reverse()) return reversed } diff --git a/packages/modeling/src/geometries/geom3/clone.d.ts b/packages/modeling/src/geometries/geom3/clone.d.ts deleted file mode 100644 index 46f141cff..000000000 --- a/packages/modeling/src/geometries/geom3/clone.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Geom3 } from './type' - -export function clone(geometry: Geom3): Geom3 diff --git a/packages/modeling/src/geometries/geom3/clone.js b/packages/modeling/src/geometries/geom3/clone.js deleted file mode 100644 index 84ece29f0..000000000 --- a/packages/modeling/src/geometries/geom3/clone.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Performs a shallow clone of the given geometry. - * @param {geom3} geometry - the geometry to clone - * @returns {geom3} a new geometry - * @alias module:modeling/geometries/geom3.clone - */ -export const clone = (geometry) => Object.assign({}, geometry) diff --git a/packages/modeling/src/geometries/geom3/clone.test.js b/packages/modeling/src/geometries/geom3/clone.test.js deleted file mode 100644 index b5cacb2a3..000000000 --- a/packages/modeling/src/geometries/geom3/clone.test.js +++ /dev/null @@ -1,31 +0,0 @@ -import test from 'ava' - -import { clone, create, fromPoints } from './index.js' - -import { comparePolygons, compareVectors } from '../../../test/helpers/index.js' - -test('clone: Creates a clone on an empty geom3', (t) => { - const expected = { - polygons: [], - transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] - } - const geometry = create() - const another = clone(geometry) - t.not(another, geometry) - t.deepEqual(another, expected) -}) - -test('clone: Creates a clone of a populated geom3', (t) => { - const vertices = [[[0, 0, 0], [1, 0, 0], [1, 0, 1]]] - const expected = { - polygons: [ - { vertices: [[0, 0, 0], [1, 0, 0], [1, 0, 1]] } - ], - transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] - } - const geometry = fromPoints(vertices) - const another = clone(geometry) - t.not(another, geometry) - t.true(comparePolygons(another.polygons[0], expected.polygons[0])) - t.true(compareVectors(another.transforms, expected.transforms)) -}) diff --git a/packages/modeling/src/geometries/geom3/fromCompactBinary.js b/packages/modeling/src/geometries/geom3/fromCompactBinary.js index 57f589607..eed750bda 100644 --- a/packages/modeling/src/geometries/geom3/fromCompactBinary.js +++ b/packages/modeling/src/geometries/geom3/fromCompactBinary.js @@ -16,7 +16,7 @@ export const fromCompactBinary = (data) => { const created = create() - created.transforms = mat4.clone(data.slice(1, 17)) + created.transforms = data.slice(1, 17) const numberOfVertices = data[21] let ci = 22 diff --git a/packages/modeling/src/geometries/geom3/index.d.ts b/packages/modeling/src/geometries/geom3/index.d.ts index e94363234..80f9d71f7 100644 --- a/packages/modeling/src/geometries/geom3/index.d.ts +++ b/packages/modeling/src/geometries/geom3/index.d.ts @@ -1,4 +1,3 @@ -export { clone } from './clone' export { create } from './create' export { fromPoints } from './fromPoints' export { fromCompactBinary } from './fromCompactBinary' diff --git a/packages/modeling/src/geometries/geom3/index.js b/packages/modeling/src/geometries/geom3/index.js index f0c5125da..f7cf67ceb 100644 --- a/packages/modeling/src/geometries/geom3/index.js +++ b/packages/modeling/src/geometries/geom3/index.js @@ -14,7 +14,6 @@ * [[-1,-1,1], [1,-1,1], [1,1,1], [-1,1,1]] * ]) */ -export { clone } from './clone.js' export { create } from './create.js' export { fromPoints } from './fromPoints.js' export { fromCompactBinary } from './fromCompactBinary.js' diff --git a/packages/modeling/src/geometries/path2/appendArc.js b/packages/modeling/src/geometries/path2/appendArc.js index f3b3f360b..3ea0004a6 100644 --- a/packages/modeling/src/geometries/path2/appendArc.js +++ b/packages/modeling/src/geometries/path2/appendArc.js @@ -36,11 +36,10 @@ export const appendArc = (options, geometry) => { // validate the given options if (!Array.isArray(endpoint)) throw new Error('endpoint must be an array of X and Y values') - if (endpoint.length < 2) throw new Error('endpoint must contain X and Y values') - endpoint = vec2.clone(endpoint) + if (endpoint.length !== 2) throw new Error('endpoint must contain X and Y values') if (!Array.isArray(radius)) throw new Error('radius must be an array of X and Y values') - if (radius.length < 2) throw new Error('radius must contain X and Y values') + if (radius.length !== 2) throw new Error('radius must contain X and Y values') if (segments < 4) throw new Error('segments must be four or more') diff --git a/packages/modeling/src/geometries/path2/clone.d.ts b/packages/modeling/src/geometries/path2/clone.d.ts deleted file mode 100644 index 9c8c43ca9..000000000 --- a/packages/modeling/src/geometries/path2/clone.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Path2 } from './type' - -export function clone(geometry: Path2): Path2 diff --git a/packages/modeling/src/geometries/path2/clone.js b/packages/modeling/src/geometries/path2/clone.js deleted file mode 100644 index 4602a20b8..000000000 --- a/packages/modeling/src/geometries/path2/clone.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Performs a shallow clone of the give geometry. - * @param {path2} geometry - the geometry to clone - * @returns {path2} a new path - * @alias module:modeling/geometries/path2.clone - */ -export const clone = (geometry) => Object.assign({}, geometry) diff --git a/packages/modeling/src/geometries/path2/close.js b/packages/modeling/src/geometries/path2/close.js index 3d5e4010e..dc2e78173 100644 --- a/packages/modeling/src/geometries/path2/close.js +++ b/packages/modeling/src/geometries/path2/close.js @@ -2,8 +2,6 @@ import { EPS } from '../../maths/constants.js' import * as vec2 from '../../maths/vec2/index.js' -import { clone } from './clone.js' - /** * Close the given geometry. * @param {path2} geometry - the path to close @@ -13,7 +11,7 @@ import { clone } from './clone.js' export const close = (geometry) => { if (geometry.isClosed) return geometry - const cloned = clone(geometry) + const cloned = Object.assign({}, geometry) cloned.isClosed = true if (cloned.points.length > 1) { diff --git a/packages/modeling/src/geometries/path2/fromCompactBinary.js b/packages/modeling/src/geometries/path2/fromCompactBinary.js index 93679a07c..36c92c618 100644 --- a/packages/modeling/src/geometries/path2/fromCompactBinary.js +++ b/packages/modeling/src/geometries/path2/fromCompactBinary.js @@ -14,7 +14,7 @@ export const fromCompactBinary = (data) => { const created = create() - created.transforms = mat4.clone(data.slice(1, 17)) + created.transforms = data.slice(1, 17) created.isClosed = !!data[17] diff --git a/packages/modeling/src/geometries/path2/fromPoints.js b/packages/modeling/src/geometries/path2/fromPoints.js index 3a0ab6c3e..4c852e7c9 100644 --- a/packages/modeling/src/geometries/path2/fromPoints.js +++ b/packages/modeling/src/geometries/path2/fromPoints.js @@ -22,8 +22,7 @@ export const fromPoints = (options, points) => { const defaults = { closed: false } let { closed } = Object.assign({}, defaults, options) - let created = create() - created.points = points.map((point) => vec2.clone(point)) + let created = create(points) // check if first and last points are equal if (created.points.length > 1) { diff --git a/packages/modeling/src/geometries/path2/index.d.ts b/packages/modeling/src/geometries/path2/index.d.ts index 56aa1901c..5e5f794cc 100644 --- a/packages/modeling/src/geometries/path2/index.d.ts +++ b/packages/modeling/src/geometries/path2/index.d.ts @@ -1,7 +1,6 @@ export { appendArc, AppendArcOptions } from './appendArc' export { appendBezier, AppendBezierOptions } from './appendBezier' export { appendPoints } from './appendPoints' -export { clone } from './clone' export { close } from './close' export { concat } from './concat' export { create } from './create' diff --git a/packages/modeling/src/geometries/path2/index.js b/packages/modeling/src/geometries/path2/index.js index 59292ba12..0a51dc5f8 100644 --- a/packages/modeling/src/geometries/path2/index.js +++ b/packages/modeling/src/geometries/path2/index.js @@ -10,7 +10,6 @@ export { appendArc } from './appendArc.js' export { appendBezier } from './appendBezier.js' export { appendPoints } from './appendPoints.js' -export { clone } from './clone.js' export { close } from './close.js' export { concat } from './concat.js' export { create } from './create.js' diff --git a/packages/modeling/src/geometries/path2/reverse.js b/packages/modeling/src/geometries/path2/reverse.js index 4ab5fd42f..752327242 100644 --- a/packages/modeling/src/geometries/path2/reverse.js +++ b/packages/modeling/src/geometries/path2/reverse.js @@ -1,4 +1,3 @@ -import { clone } from './clone.js' /** * Reverses the path so that the points are in the opposite order. @@ -12,7 +11,7 @@ import { clone } from './clone.js' */ export const reverse = (geometry) => { // NOTE: this only updates the order of the points - const cloned = clone(geometry) + const cloned = Object.assign({}, geometry) cloned.points = geometry.points.slice().reverse() return cloned } diff --git a/packages/modeling/src/geometries/poly2/clone.d.ts b/packages/modeling/src/geometries/poly2/clone.d.ts deleted file mode 100644 index 897fb4130..000000000 --- a/packages/modeling/src/geometries/poly2/clone.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import Poly2 from './type' - -export function clone(polygon: Poly2): Poly2 diff --git a/packages/modeling/src/geometries/poly2/clone.js b/packages/modeling/src/geometries/poly2/clone.js deleted file mode 100644 index 02369e260..000000000 --- a/packages/modeling/src/geometries/poly2/clone.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Create a shallow clone of the given polygon. - * - * @param {poly2} polygon - polygon to clone - * @returns {poly2} a new polygon - * @alias module:modeling/geometries/poly2.clone - */ -export const clone = (polygon) => Object.assign({}, polygon) diff --git a/packages/modeling/src/geometries/poly2/clone.test.js b/packages/modeling/src/geometries/poly2/clone.test.js deleted file mode 100644 index a55e88328..000000000 --- a/packages/modeling/src/geometries/poly2/clone.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import test from 'ava' - -import { create, clone } from './index.js' - -import { comparePoints } from '../../../test/helpers/index.js' - -test('poly2: clone() should return a new poly2 with same values', (t) => { - const org1 = create() - const ret1 = clone(org1) - t.true(comparePoints(ret1.points, org1.points)) - t.not(ret1, org1) - - const org2 = create([[1, 1], [-1, 1], [-1, -1], [1, -1]]) - const ret2 = clone(org2) - t.true(comparePoints(ret2.points, org2.points)) - t.not(ret2, org2) -}) diff --git a/packages/modeling/src/geometries/poly2/index.d.ts b/packages/modeling/src/geometries/poly2/index.d.ts index a2038bf4d..796705a51 100644 --- a/packages/modeling/src/geometries/poly2/index.d.ts +++ b/packages/modeling/src/geometries/poly2/index.d.ts @@ -1,5 +1,4 @@ export { arePointsInside } from './arePointsInside' -export { clone } from './clone' export { create } from './create' export { isA } from './isA' export { isConvex } from './isConvex' diff --git a/packages/modeling/src/geometries/poly2/index.js b/packages/modeling/src/geometries/poly2/index.js index db20c5c1c..63111c450 100644 --- a/packages/modeling/src/geometries/poly2/index.js +++ b/packages/modeling/src/geometries/poly2/index.js @@ -8,7 +8,6 @@ * const p1 = geometries.poly2.create([[0,0], [4,0], [4,3]]) */ export { arePointsInside } from './arePointsInside.js' -export { clone } from './clone.js' export { create } from './create.js' export { isA } from './isA.js' export { isConvex } from './isConvex.js' diff --git a/packages/modeling/src/geometries/poly3/clone.d.ts b/packages/modeling/src/geometries/poly3/clone.d.ts deleted file mode 100644 index f30bca7af..000000000 --- a/packages/modeling/src/geometries/poly3/clone.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Poly3 } from './type' - -export function clone(polygon: Poly3): Poly3 -export function clone(out: Poly3, polygon: Poly3): Poly3 diff --git a/packages/modeling/src/geometries/poly3/clone.js b/packages/modeling/src/geometries/poly3/clone.js deleted file mode 100644 index baddebe56..000000000 --- a/packages/modeling/src/geometries/poly3/clone.js +++ /dev/null @@ -1,26 +0,0 @@ -import * as vec3 from '../../maths/vec3/index.js' - -import { create } from './create.js' - -/** - * Create a deep clone of the given polygon - * - * @param {poly3} [out] - receiving polygon - * @param {poly3} polygon - polygon to clone - * @returns {poly3} a new polygon - * @alias module:modeling/geometries/poly3.clone - */ -export const clone = (...params) => { - let out - let poly3 - if (params.length === 1) { - out = create() - poly3 = params[0] - } else { - out = params[0] - poly3 = params[1] - } - // deep clone of vertices - out.vertices = poly3.vertices.map((vec) => vec3.clone(vec)) - return out -} diff --git a/packages/modeling/src/geometries/poly3/clone.test.js b/packages/modeling/src/geometries/poly3/clone.test.js deleted file mode 100644 index e043d0268..000000000 --- a/packages/modeling/src/geometries/poly3/clone.test.js +++ /dev/null @@ -1,36 +0,0 @@ -import test from 'ava' - -import { create, clone } from './index.js' - -import { comparePolygons } from '../../../test/helpers/index.js' - -test('poly3: clone() should return a new poly3 with same values', (t) => { - const org1 = create() - const ret1 = clone(org1) - t.true(comparePolygons(ret1, org1)) - t.not(ret1, org1) - - const org2 = create([[1, 1, 0], [-1, 1, 0], [-1, -1, 0], [1, -1, 0]]) - const ret2 = clone(org2) - t.true(comparePolygons(ret2, org2)) - t.not(ret2, org2) -}) - -test('poly3: clone() with two params should update a poly3 with same values', (t) => { - const org1 = create() - const out1 = create() - const ret1 = clone(out1, org1) - t.true(comparePolygons(org1, out1)) - t.true(comparePolygons(org1, ret1)) - t.not(out1, org1) - t.not(ret1, org1) - t.is(ret1, out1) - - const org2 = create([[1, 1, 0], [-1, 1, 0], [-1, -1, 0], [1, -1, 0]]) - const out2 = create() - const ret2 = clone(out2, org2) - t.true(comparePolygons(ret2, org2)) - t.not(out2, org2) - t.not(ret2, org2) - t.is(ret2, out2) -}) diff --git a/packages/modeling/src/geometries/poly3/index.d.ts b/packages/modeling/src/geometries/poly3/index.d.ts index da1600716..ca214d99f 100644 --- a/packages/modeling/src/geometries/poly3/index.d.ts +++ b/packages/modeling/src/geometries/poly3/index.d.ts @@ -1,4 +1,3 @@ -export { clone } from './clone' export { create } from './create' export { fromVerticesAndPlane } from './fromVerticesAndPlane' export { invert } from './invert' diff --git a/packages/modeling/src/geometries/poly3/index.js b/packages/modeling/src/geometries/poly3/index.js index f588d198b..e4e1a5dc5 100644 --- a/packages/modeling/src/geometries/poly3/index.js +++ b/packages/modeling/src/geometries/poly3/index.js @@ -7,7 +7,6 @@ * import { geometries } from '@jscad/modeling' * const polygon = geometries.poly3.create([[0,0,0], [4,0,0], [4,3,12]]) */ -export { clone } from './clone.js' export { create } from './create.js' export { fromVerticesAndPlane } from './fromVerticesAndPlane.js' export { invert } from './invert.js' diff --git a/packages/modeling/src/geometries/slice/clone.d.ts b/packages/modeling/src/geometries/slice/clone.d.ts deleted file mode 100644 index 84ed07456..000000000 --- a/packages/modeling/src/geometries/slice/clone.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Slice } from './type' - -export function clone(slice: Slice): Slice diff --git a/packages/modeling/src/geometries/slice/clone.js b/packages/modeling/src/geometries/slice/clone.js deleted file mode 100644 index cb94fc2a5..000000000 --- a/packages/modeling/src/geometries/slice/clone.js +++ /dev/null @@ -1,9 +0,0 @@ - -/** - * Create a deep clone of the given slice. - * - * @param {slice} slice - slice to clone - * @returns {slice} a new slice - * @alias module:modeling/geometries/slice.clone - */ -export const clone = (slice) => Object.assign({}, slice) diff --git a/packages/modeling/src/geometries/slice/clone.test.js b/packages/modeling/src/geometries/slice/clone.test.js deleted file mode 100644 index a1a65531d..000000000 --- a/packages/modeling/src/geometries/slice/clone.test.js +++ /dev/null @@ -1,14 +0,0 @@ -import test from 'ava' - -import { create, clone, fromVertices, toVertices } from './index.js' - -test('slice: clone() should return a new slice with same values', (t) => { - const org1 = create() - const ret1 = clone(org1) - t.not(ret1, org1) - - const org2 = fromVertices([[1, 1], [-1, 1], [-1, -1], [1, -1]]) - const ret2 = clone(org2) - t.not(ret2, org2) - t.deepEqual(toVertices(ret2), toVertices(org2)) -}) diff --git a/packages/modeling/src/geometries/slice/index.d.ts b/packages/modeling/src/geometries/slice/index.d.ts index 357c18115..0ff355ae3 100644 --- a/packages/modeling/src/geometries/slice/index.d.ts +++ b/packages/modeling/src/geometries/slice/index.d.ts @@ -1,5 +1,4 @@ export { calculatePlane } from './calculatePlane' -export { clone } from './clone' export { create } from './create' export { equals } from './equals' export { fromGeom2 } from './fromGeom2' diff --git a/packages/modeling/src/geometries/slice/index.js b/packages/modeling/src/geometries/slice/index.js index 06289f3f3..f96649e6c 100644 --- a/packages/modeling/src/geometries/slice/index.js +++ b/packages/modeling/src/geometries/slice/index.js @@ -8,7 +8,6 @@ * const slice = geometries.slice.create([[[0,0,0], [4,0,0], [4,3,12]]]) */ export { calculatePlane } from './calculatePlane.js' -export { clone } from './clone.js' export { create } from './create.js' export { equals } from './equals.js' export { fromGeom2 } from './fromGeom2.js' diff --git a/packages/modeling/src/maths/line2/intersectPointOfLines.js b/packages/modeling/src/maths/line2/intersectPointOfLines.js index 4037e5970..73e9dae00 100644 --- a/packages/modeling/src/maths/line2/intersectPointOfLines.js +++ b/packages/modeling/src/maths/line2/intersectPointOfLines.js @@ -1,6 +1,4 @@ -import * as vec2 from '../vec2/index.js' - -import { solve2Linear } from '../utils/index.js' +import { solve2Linear } from '../utils/solve2Linear.js' /** * Return the point of intersection between the given lines. @@ -15,6 +13,5 @@ import { solve2Linear } from '../utils/index.js' * @alias module:modeling/maths/line2.intersectPointOfLines */ export const intersectPointOfLines = (line1, line2) => { - const point = solve2Linear(line1[0], line1[1], line2[0], line2[1], line1[2], line2[2]) - return vec2.clone(point) + return solve2Linear(line1[0], line1[1], line2[0], line2[1], line1[2], line2[2]) } diff --git a/packages/modeling/src/operations/booleans/subtractGeom3Sub.js b/packages/modeling/src/operations/booleans/subtractGeom3Sub.js index 44fdccc03..ef78e8667 100644 --- a/packages/modeling/src/operations/booleans/subtractGeom3Sub.js +++ b/packages/modeling/src/operations/booleans/subtractGeom3Sub.js @@ -13,7 +13,7 @@ import { mayOverlap } from './mayOverlap.js' */ export const subtractGeom3Sub = (geometry1, geometry2) => { if (!mayOverlap(geometry1, geometry2)) { - return geom3.clone(geometry1) + return geometry1 } const a = new Tree(geom3.toPolygons(geometry1)) diff --git a/packages/modeling/src/operations/extrusions/extrudeLinearGeom2.js b/packages/modeling/src/operations/extrusions/extrudeLinearGeom2.js index 06083e3dd..029031291 100644 --- a/packages/modeling/src/operations/extrusions/extrudeLinearGeom2.js +++ b/packages/modeling/src/operations/extrusions/extrudeLinearGeom2.js @@ -31,16 +31,13 @@ export const extrudeLinearGeom2 = (options, geometry) => { twistSteps = 1 } - // convert to vector in order to perform transforms - const offsetV = vec3.clone(offset) - let baseSlice = slice.fromGeom2(geometry) - if (offsetV[2] < 0) baseSlice = slice.reverse(baseSlice) + if (offset[2] < 0) baseSlice = slice.reverse(baseSlice) const matrix = mat4.create() const createTwist = (progress, index, base) => { const Zrotation = index / twistSteps * twistAngle - const Zoffset = vec3.scale(vec3.create(), offsetV, index / twistSteps) + const Zoffset = vec3.scale(vec3.create(), offset, index / twistSteps) mat4.multiply(matrix, mat4.fromZRotation(matrix, Zrotation), mat4.fromTranslation(mat4.create(), Zoffset)) return slice.transform(matrix, base) diff --git a/packages/modeling/src/primitives/arc.js b/packages/modeling/src/primitives/arc.js index a303ddd5c..0bf5504ca 100644 --- a/packages/modeling/src/primitives/arc.js +++ b/packages/modeling/src/primitives/arc.js @@ -48,14 +48,13 @@ export const arc = (options) => { const minAngle = Math.acos(((radius * radius) + (radius * radius) - (EPS * EPS)) / (2 * radius * radius)) - const centerV = vec2.clone(center) let point const pointArray = [] if (rotation < minAngle) { // there is no rotation, just a single point point = vec2.fromAngleRadians(vec2.create(), startAngle) vec2.scale(point, point, radius) - vec2.add(point, point, centerV) + vec2.add(point, point, center) pointArray.push(point) } else { // note: add one additional step to achieve full rotation @@ -74,7 +73,7 @@ export const arc = (options) => { const angle = startAngle + (step * (rotation / numSteps)) point = vec2.fromAngleRadians(vec2.create(), angle) vec2.scale(point, point, radius) - vec2.add(point, point, centerV) + vec2.add(point, point, center) pointArray.push(point) } } diff --git a/packages/modeling/src/primitives/ellipse.js b/packages/modeling/src/primitives/ellipse.js index 7c17cd492..c9fe522e1 100644 --- a/packages/modeling/src/primitives/ellipse.js +++ b/packages/modeling/src/primitives/ellipse.js @@ -57,7 +57,6 @@ export const ellipse = (options) => { segments = Math.floor(segments * (rotation / TAU)) - const centerV = vec2.clone(center) const step = rotation / segments // radians per segment const points = [] @@ -65,9 +64,9 @@ export const ellipse = (options) => { for (let i = 0; i < segments; i++) { const angle = (step * i) + startAngle const point = vec2.fromValues(radius[0] * cos(angle), radius[1] * sin(angle)) - vec2.add(point, centerV, point) + vec2.add(point, center, point) points.push(point) } - if (rotation < TAU) points.push(centerV) + if (rotation < TAU) points.push(center) return geom2.create([points]) } diff --git a/packages/modeling/src/primitives/star.js b/packages/modeling/src/primitives/star.js index c2c00d9a9..7b956c971 100644 --- a/packages/modeling/src/primitives/star.js +++ b/packages/modeling/src/primitives/star.js @@ -71,10 +71,8 @@ export const star = (options) => { innerRadius = outerRadius * getRadiusRatio(vertices, density) } - const centerV = vec2.clone(center) - - const outerPoints = getPoints(vertices, outerRadius, startAngle, centerV) - const innerPoints = getPoints(vertices, innerRadius, startAngle + Math.PI / vertices, centerV) + const outerPoints = getPoints(vertices, outerRadius, startAngle, center) + const innerPoints = getPoints(vertices, innerRadius, startAngle + Math.PI / vertices, center) const allPoints = [] for (let i = 0; i < vertices; i++) {