diff --git a/packages/modeling/src/geometries/slice/calculatePlane.test.js b/packages/modeling/src/geometries/slice/calculatePlane.test.js index fc70ed778..ddc3f8bcb 100644 --- a/packages/modeling/src/geometries/slice/calculatePlane.test.js +++ b/packages/modeling/src/geometries/slice/calculatePlane.test.js @@ -3,7 +3,7 @@ import test from 'ava' import { TAU } from '../../maths/constants.js' import { mat4 } from '../../maths/index.js' -import { calculatePlane, create, fromPoints, transform } from './index.js' +import { calculatePlane, create, fromVertices, transform } from './index.js' import { compareVectors } from '../../../test/helpers/index.js' @@ -12,7 +12,7 @@ test('slice: calculatePlane() returns correct plans for various slices', (t) => // const slice1 = create() // const plane1 = calculatePlane(slice1) - const slice2 = fromPoints([[0, 0], [1, 0], [1, 1]]) + const slice2 = fromVertices([[0, 0], [1, 0], [1, 1]]) const plane2 = calculatePlane(slice2) t.true(compareVectors(plane2, [0, 0, 1, 0])) @@ -25,11 +25,11 @@ test('slice: calculatePlane() returns correct plans for various slices', (t) => t.true(compareVectors(plane4, [1, 0, 0, 0])) // Issue #749 - const slice5 = fromPoints([[-4, 0, 2], [4, 0, 2], [4, 5, 2], [6, 5, 2], [4, 7, 2], [-4, 7, 2], [-6, 5, 2], [-4, 5, 2]]) + const slice5 = fromVertices([[-4, 0, 2], [4, 0, 2], [4, 5, 2], [6, 5, 2], [4, 7, 2], [-4, 7, 2], [-6, 5, 2], [-4, 5, 2]]) const plane5 = calculatePlane(slice5) t.true(compareVectors(plane5, [0, 0, 1, 2])) - const slice6 = fromPoints([[4, 0, 0], [-4, 0, 0], [-4, 5, 0], [-6, 5, 0], [-4, 7, 0], [4, 7, 0], [6, 5, 0], [4, 5, 0]]) + const slice6 = fromVertices([[4, 0, 0], [-4, 0, 0], [-4, 5, 0], [-6, 5, 0], [-4, 7, 0], [4, 7, 0], [6, 5, 0], [4, 5, 0]]) const plane6 = calculatePlane(slice6) t.true(compareVectors(plane6, [0, 0, -1, 0])) diff --git a/packages/modeling/src/geometries/slice/clone.test.js b/packages/modeling/src/geometries/slice/clone.test.js index cf8db5f5b..a1a65531d 100644 --- a/packages/modeling/src/geometries/slice/clone.test.js +++ b/packages/modeling/src/geometries/slice/clone.test.js @@ -1,14 +1,14 @@ import test from 'ava' -import { create, clone, fromPoints, toPoints } from './index.js' +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 = fromPoints([[1, 1], [-1, 1], [-1, -1], [1, -1]]) + const org2 = fromVertices([[1, 1], [-1, 1], [-1, -1], [1, -1]]) const ret2 = clone(org2) t.not(ret2, org2) - t.deepEqual(toPoints(ret2), toPoints(org2)) + t.deepEqual(toVertices(ret2), toVertices(org2)) }) diff --git a/packages/modeling/src/geometries/slice/equals.test.js b/packages/modeling/src/geometries/slice/equals.test.js index 633c9059b..4f82ff617 100644 --- a/packages/modeling/src/geometries/slice/equals.test.js +++ b/packages/modeling/src/geometries/slice/equals.test.js @@ -1,11 +1,11 @@ import test from 'ava' -import { equals, fromPoints } from './index.js' +import { equals, fromVertices } from './index.js' test('slice: equals() should return proper value', (t) => { - const sliceA = fromPoints([[0, 0], [1, 0], [1, 1]]) - const sliceB = fromPoints([[0, 1], [1, 0], [1, 1]]) - const sliceC = fromPoints([[0, 0], [1, 0], [1, 1], [0, 0]]) + const sliceA = fromVertices([[0, 0], [1, 0], [1, 1]]) + const sliceB = fromVertices([[0, 1], [1, 0], [1, 1]]) + const sliceC = fromVertices([[0, 0], [1, 0], [1, 1], [0, 0]]) t.true(equals(sliceA, sliceA)) diff --git a/packages/modeling/src/geometries/slice/fromPoints.d.ts b/packages/modeling/src/geometries/slice/fromPoints.d.ts deleted file mode 100644 index 925fdc446..000000000 --- a/packages/modeling/src/geometries/slice/fromPoints.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Vec2, Vec3 } from '../../maths/types' - -import { Slice } from './type' - -type Point = Vec2 | Vec3 - -export function fromPoints(points: Array): Slice diff --git a/packages/modeling/src/geometries/slice/fromPoints.test.js b/packages/modeling/src/geometries/slice/fromPoints.test.js deleted file mode 100644 index 93590a869..000000000 --- a/packages/modeling/src/geometries/slice/fromPoints.test.js +++ /dev/null @@ -1,11 +0,0 @@ -import test from 'ava' - -import { fromPoints } from './index.js' - -test('slice: fromPoints() should return a new slice with correct values', (t) => { - const exp1 = { - contours: [[[0, 0, 0], [1, 0, 0], [1, 1, 0]]] - } - const obs1 = fromPoints([[0, 0], [1, 0], [1, 1]]) - t.deepEqual(obs1, exp1) -}) diff --git a/packages/modeling/src/geometries/slice/fromVertices.d.ts b/packages/modeling/src/geometries/slice/fromVertices.d.ts new file mode 100644 index 000000000..eef8dd8fb --- /dev/null +++ b/packages/modeling/src/geometries/slice/fromVertices.d.ts @@ -0,0 +1,7 @@ +import { Vec2, Vec3 } from '../../maths/types' + +import { Slice } from './type' + +type Vertex = Vec2 | Vec3 + +export function fromVertices(points: Array): Slice diff --git a/packages/modeling/src/geometries/slice/fromPoints.js b/packages/modeling/src/geometries/slice/fromVertices.js similarity index 85% rename from packages/modeling/src/geometries/slice/fromPoints.js rename to packages/modeling/src/geometries/slice/fromVertices.js index 7a76eb03c..b5593885a 100644 --- a/packages/modeling/src/geometries/slice/fromPoints.js +++ b/packages/modeling/src/geometries/slice/fromVertices.js @@ -7,7 +7,7 @@ import { create } from './create.js' * * @param {Array} vertices - list of vertices, where each vertex is either 2D or 3D * @returns {slice} a new slice - * @alias module:modeling/geometries/slice.fromPoints + * @alias module:modeling/geometries/slice.fromVertices * * @example * const vertices = [ @@ -15,9 +15,9 @@ import { create } from './create.js' * [0, 10, 3], * [0, 10, 6] * ] - * const slice = fromPoints(vertices) + * const slice = fromVertices(vertices) */ -export const fromPoints = (vertices) => { +export const fromVertices = (vertices) => { if (!Array.isArray(vertices)) throw new Error('the given vertices must be an array') if (vertices.length < 3) throw new Error('the given vertices must contain THREE or more vertices') diff --git a/packages/modeling/src/geometries/slice/fromVertices.test.js b/packages/modeling/src/geometries/slice/fromVertices.test.js new file mode 100644 index 000000000..5d91893e4 --- /dev/null +++ b/packages/modeling/src/geometries/slice/fromVertices.test.js @@ -0,0 +1,11 @@ +import test from 'ava' + +import { fromVertices } from './index.js' + +test('slice: fromVertices() should return a new slice with correct values', (t) => { + const exp1 = { + contours: [[[0, 0, 0], [1, 0, 0], [1, 1, 0]]] + } + const obs1 = fromVertices([[0, 0], [1, 0], [1, 1]]) + t.deepEqual(obs1, exp1) +}) diff --git a/packages/modeling/src/geometries/slice/index.d.ts b/packages/modeling/src/geometries/slice/index.d.ts index 5389b69d1..357c18115 100644 --- a/packages/modeling/src/geometries/slice/index.d.ts +++ b/packages/modeling/src/geometries/slice/index.d.ts @@ -3,11 +3,11 @@ export { clone } from './clone' export { create } from './create' export { equals } from './equals' export { fromGeom2 } from './fromGeom2' -export { fromPoints } from './fromPoints' +export { fromVertices } from './fromVertices' export { isA } from './isA' export { reverse } from './reverse' export { toEdges } from './toEdges' -export { toPoints } from './toPoints' +export { toVertices } from './toVertices' export { toPolygons } from './toPolygons' export { toString } from './toString' export { transform } from './transform' diff --git a/packages/modeling/src/geometries/slice/index.js b/packages/modeling/src/geometries/slice/index.js index 5d7d5870f..06289f3f3 100644 --- a/packages/modeling/src/geometries/slice/index.js +++ b/packages/modeling/src/geometries/slice/index.js @@ -12,11 +12,11 @@ export { clone } from './clone.js' export { create } from './create.js' export { equals } from './equals.js' export { fromGeom2 } from './fromGeom2.js' -export { fromPoints } from './fromPoints.js' +export { fromVertices } from './fromVertices.js' export { isA } from './isA.js' export { reverse } from './reverse.js' export { toEdges } from './toEdges.js' -export { toPoints } from './toPoints.js' +export { toVertices } from './toVertices.js' export { toPolygons } from './toPolygons.js' export { toString } from './toString.js' export { transform } from './transform.js' diff --git a/packages/modeling/src/geometries/slice/isA.test.js b/packages/modeling/src/geometries/slice/isA.test.js index d5863e7cd..2778f299e 100644 --- a/packages/modeling/src/geometries/slice/isA.test.js +++ b/packages/modeling/src/geometries/slice/isA.test.js @@ -1,10 +1,10 @@ import test from 'ava' -import { isA, create, fromPoints } from './index.js' +import { isA, create, fromVertices } from './index.js' test('isA: identifies created slice', (t) => { const p1 = create() - const p2 = fromPoints([[0, 0], [1, 0], [1, 1]]) + const p2 = fromVertices([[0, 0], [1, 0], [1, 1]]) t.true(isA(p1)) t.true(isA(p2)) }) diff --git a/packages/modeling/src/geometries/slice/toPoints.d.ts b/packages/modeling/src/geometries/slice/toVertices.d.ts similarity index 100% rename from packages/modeling/src/geometries/slice/toPoints.d.ts rename to packages/modeling/src/geometries/slice/toVertices.d.ts diff --git a/packages/modeling/src/geometries/slice/toPoints.js b/packages/modeling/src/geometries/slice/toVertices.js similarity index 74% rename from packages/modeling/src/geometries/slice/toPoints.js rename to packages/modeling/src/geometries/slice/toVertices.js index 77d9791ab..12a7ad0a7 100644 --- a/packages/modeling/src/geometries/slice/toPoints.js +++ b/packages/modeling/src/geometries/slice/toVertices.js @@ -3,12 +3,12 @@ * The returned array should not be modified as the data is shared with the slice. * @param {slice} slice - the slice * @returns {Array} an array of 3D vertices - * @alias module:modeling/geometries/slice.toPoints + * @alias module:modeling/geometries/slice.toVertices * * @example - * let sharedPoints = toPoints(slice) + * let sharedVertices = toVertices(slice) */ -export const toPoints = (slice) => { +export const toVertices = (slice) => { const vertices = [] slice.contours.forEach((contour) => { contour.forEach((vertex) => { diff --git a/packages/modeling/src/geometries/slice/transform.test.js b/packages/modeling/src/geometries/slice/transform.test.js index a32167b89..0aba812aa 100644 --- a/packages/modeling/src/geometries/slice/transform.test.js +++ b/packages/modeling/src/geometries/slice/transform.test.js @@ -1,6 +1,6 @@ import test from 'ava' -import { transform, fromPoints, toPoints } from './index.js' +import { transform, fromVertices, toVertices } from './index.js' test('slice: transform() should return a new slice with correct values', (t) => { const identityMatrix = [ @@ -10,11 +10,11 @@ test('slice: transform() should return a new slice with correct values', (t) => 0, 0, 0, 1 ] - const org1 = fromPoints([[0, 0], [1, 0], [1, 1]]) + const org1 = fromVertices([[0, 0], [1, 0], [1, 1]]) const ret1 = transform(identityMatrix, org1) t.not(org1, ret1) - const edges1 = toPoints(ret1) + const edges1 = toVertices(ret1) const exp1 = [[0, 0, 0], [1, 0, 0], [1, 1, 0]] t.deepEqual(edges1, exp1) @@ -28,11 +28,11 @@ test('slice: transform() should return a new slice with correct values', (t) => x, y, z, 1 ] - const org2 = fromPoints([[0, 0], [1, 0], [1, 1]]) + const org2 = fromVertices([[0, 0], [1, 0], [1, 1]]) const ret2 = transform(translationMatrix, org2) t.not(org2, ret2) - const edges2 = toPoints(ret2) + const edges2 = toVertices(ret2) const exp2 = [[1, 5, 7], [2, 5, 7], [2, 6, 7]] t.deepEqual(edges2, exp2) @@ -44,11 +44,11 @@ test('slice: transform() should return a new slice with correct values', (t) => 0, 0, 0, 1 ] - const org3 = fromPoints([[0, 0], [1, 0], [1, 1]]) + const org3 = fromVertices([[0, 0], [1, 0], [1, 1]]) const ret3 = transform(rotateZMatrix, org3) t.not(org3, ret3) - const edges3 = toPoints(ret3) + const edges3 = toVertices(ret3) const exp3 = [ [0, 0, 0], [6.123233995736766e-17, -1, 0], [1, -0.9999999999999999, 0] ] diff --git a/packages/modeling/src/operations/extrusions/extrudeFromSlices.js b/packages/modeling/src/operations/extrusions/extrudeFromSlices.js index 426b80a08..e1d7b7edc 100644 --- a/packages/modeling/src/operations/extrusions/extrudeFromSlices.js +++ b/packages/modeling/src/operations/extrusions/extrudeFromSlices.js @@ -10,7 +10,7 @@ import { extrudeWalls } from './extrudeWalls.js' const defaultCallback = (progress, index, base) => { let baseSlice = null if (geom2.isA(base)) baseSlice = slice.fromGeom2(base) - if (poly3.isA(base)) baseSlice = slice.fromPoints(poly3.toVertices(base)) + if (poly3.isA(base)) baseSlice = slice.fromVertices(poly3.toVertices(base)) return progress === 0 || progress === 1 ? slice.transform(mat4.fromTranslation(mat4.create(), [0, 0, progress]), baseSlice) : null } diff --git a/packages/modeling/src/operations/extrusions/extrudeFromSlices.test.js b/packages/modeling/src/operations/extrusions/extrudeFromSlices.test.js index c5d714f3a..f4bfabcce 100644 --- a/packages/modeling/src/operations/extrusions/extrudeFromSlices.test.js +++ b/packages/modeling/src/operations/extrusions/extrudeFromSlices.test.js @@ -58,7 +58,7 @@ test('extrudeFromSlices (torus)', (t) => { [radius / 2, -radius * sqrt3, 0] ]) hex = poly3.transform(mat4.fromTranslation(mat4.create(), [0, 20, 0]), hex) - hex = slice.fromPoints(poly3.toVertices(hex)) + hex = slice.fromVertices(poly3.toVertices(hex)) const angle = TAU / 8 const geometry3 = extrudeFromSlices( @@ -79,7 +79,7 @@ test('extrudeFromSlices (torus)', (t) => { }) test('extrudeFromSlices (same shape, changing dimensions)', (t) => { - const base = slice.fromPoints([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]) + const base = slice.fromVertices([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]) const geometry3 = extrudeFromSlices( { numberOfSlices: 4,