From e1e20d16c7ceceeea5463815949d9fd7b63a82d0 Mon Sep 17 00:00:00 2001 From: Kenny Date: Wed, 14 Jun 2023 02:32:22 -0700 Subject: [PATCH] style(modeling): fix lint warnings --- .../src/curves/bezier/arcLengthToT.js | 12 ++-- .../src/curves/bezier/arcLengthToT.test.js | 50 ++++++------- packages/modeling/src/curves/bezier/length.js | 8 +-- .../modeling/src/curves/bezier/length.test.js | 4 +- .../modeling/src/curves/bezier/lengths.js | 20 +++--- .../src/curves/bezier/lengths.test.js | 6 +- .../src/geometries/poly2/arePointsInside.js | 7 -- .../geometries/poly3/measureBoundingSphere.js | 3 +- .../booleans/trees/PolygonTreeNode.js | 2 +- .../src/operations/expansions/expand.test.js | 2 +- .../operations/extrusions/extrudeHelical.js | 13 ++-- .../extrusions/extrudeHelical.test.js | 72 +++++++++---------- .../src/operations/hulls/hullPoints2.js | 5 +- .../src/operations/modifiers/index.js | 2 +- .../src/operations/modifiers/retessellate.js | 32 ++++----- .../modeling/src/primitives/geodesicSphere.js | 2 +- 16 files changed, 113 insertions(+), 127 deletions(-) diff --git a/packages/modeling/src/curves/bezier/arcLengthToT.js b/packages/modeling/src/curves/bezier/arcLengthToT.js index f867276f9..8468e83af 100644 --- a/packages/modeling/src/curves/bezier/arcLengthToT.js +++ b/packages/modeling/src/curves/bezier/arcLengthToT.js @@ -3,7 +3,7 @@ const lengths = require('./lengths') /** * Convert a given arc length along a bezier curve to a t value. * Useful for generating equally spaced points along a bezier curve. - * + * * @example * const points = []; * const segments = 9; // this will generate 10 equally spaced points @@ -14,7 +14,7 @@ const lengths = require('./lengths') * points.push(point); * } * return points; - * + * * @param {Object} [options] options for construction * @param {Number} [options.distance=0] the distance along the bezier curve for which we want to find the corresponding t value. * @param {Number} [options.segments=100] the number of segments to use when approximating the curve length. @@ -27,8 +27,8 @@ const arcLengthToT = (options, bezier) => { distance: 0, segments: 100 } - const {distance, segments} = Object.assign({}, defaults, options) - + const { distance, segments } = Object.assign({}, defaults, options) + const arcLengths = lengths(segments, bezier) // binary search for the index with largest value smaller than target arcLength let startIndex = 0 @@ -58,6 +58,6 @@ const arcLengthToT = (options, bezier) => { const segmentFraction = (distance - lengthBefore) / segmentLength // add that fractional amount and return return (targetIndex + segmentFraction) / segments -}; +} -module.exports = arcLengthToT \ No newline at end of file +module.exports = arcLengthToT diff --git a/packages/modeling/src/curves/bezier/arcLengthToT.test.js b/packages/modeling/src/curves/bezier/arcLengthToT.test.js index ddc5f6ebd..5772f8cb2 100644 --- a/packages/modeling/src/curves/bezier/arcLengthToT.test.js +++ b/packages/modeling/src/curves/bezier/arcLengthToT.test.js @@ -9,71 +9,71 @@ const { nearlyEqual } = require('../../../test/helpers/index') test('calculate arcLengthToT for an 1D linear bezier with numeric control points', (t) => { const bezierCurve = bezier.create([0, 10]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.5, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for an 1D linear bezier with array control points', (t) => { const bezierCurve = bezier.create([[0], [10]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.5, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for a 2D linear bezier', (t) => { const bezierCurve = bezier.create([[0, 0], [10, 10]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.5, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for a 2D quadratic (3 control points) bezier', (t) => { const bezierCurve = bezier.create([[0, 0], [0, 10], [10, 10]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.50001, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.50001, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for a 2D cubic (4 control points) bezier', (t) => { const bezierCurve = bezier.create([[0, 0], [0, 10], [10, 10], [10, 0]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.49999, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.49999, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for a 3D linear bezier', (t) => { const bezierCurve = bezier.create([[0, 0, 0], [10, 10, 10]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.49999, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.49999, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for a 3D quadratic (3 control points) bezier', (t) => { const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.49999, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.49999, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) }) test('calculate arcLengthToT for a 3D cubic (4 control points) bezier', (t) => { const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10], [-5, -5, 5]]) const len = length(100, bezierCurve) - nearlyEqual(t, arcLengthToT({distance: 0}, bezierCurve), 0, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len / 2}, bezierCurve), 0.5621, 0.0001) - nearlyEqual(t, arcLengthToT({distance: len}, bezierCurve), 1, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: 0 }, bezierCurve), 0, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len / 2 }, bezierCurve), 0.5621, 0.0001) + nearlyEqual(t, arcLengthToT({ distance: len }, bezierCurve), 1, 0.0001) t.true(true) -}) \ No newline at end of file +}) diff --git a/packages/modeling/src/curves/bezier/length.js b/packages/modeling/src/curves/bezier/length.js index a2e493908..98e2e8636 100644 --- a/packages/modeling/src/curves/bezier/length.js +++ b/packages/modeling/src/curves/bezier/length.js @@ -7,14 +7,12 @@ const lengths = require('./lengths') * @example * const b = bezier.create([[0, 0], [0, 10]]); * console.log(length(100, b)) // output 10 - * + * * @param {Number} segments the number of segments to use when approximating the curve length. * @param {Object} bezier a bezier curve. * @returns an approximation of the curve's length. * @alias module:modeling/curves/bezier.length */ -const length = (segments, bezier) => { - return lengths(segments, bezier)[segments] -}; +const length = (segments, bezier) => lengths(segments, bezier)[segments] -module.exports = length \ No newline at end of file +module.exports = length diff --git a/packages/modeling/src/curves/bezier/length.test.js b/packages/modeling/src/curves/bezier/length.test.js index d8c69edb9..1a4d05798 100644 --- a/packages/modeling/src/curves/bezier/length.test.js +++ b/packages/modeling/src/curves/bezier/length.test.js @@ -7,7 +7,7 @@ const { nearlyEqual } = require('../../../test/helpers/index') test('calculate the length of an 1D linear bezier with numeric control points', (t) => { const bezierCurve = bezier.create([0, 10]) - nearlyEqual(t, length(100, bezierCurve), 10, 0.0001) + nearlyEqual(t, length(100, bezierCurve), 10, 0.0001) t.true(true) }) @@ -51,4 +51,4 @@ test('calculate the length of a 3D cubic (4 control points) bezier', (t) => { const bezierCurve = bezier.create([[0, 0, 0], [5, 5, 5], [0, 0, 10], [-5, -5, 5]]) nearlyEqual(t, length(100, bezierCurve), 17.2116, 0.0001) t.true(true) -}) \ No newline at end of file +}) diff --git a/packages/modeling/src/curves/bezier/lengths.js b/packages/modeling/src/curves/bezier/lengths.js index c11d9eb65..5eeadd954 100644 --- a/packages/modeling/src/curves/bezier/lengths.js +++ b/packages/modeling/src/curves/bezier/lengths.js @@ -1,20 +1,20 @@ -const valueAt = require("./valueAt") +const valueAt = require('./valueAt') /** * Divides the bezier curve into line segments and returns the cumulative length of those segments as an array. * Utility function used to calculate the curve's approximate length and determine the equivalence between arc length and time. - * + * * @example * const b = bezier.create([[0, 0], [0, 10]]); * const totalLength = lengths(100, b).pop(); // the last element of the array is the curve's approximate length - * + * * @param {Number} segments the number of segments to use when approximating the curve length. * @param {Object} bezier a bezier curve. * @returns an array containing the cumulative length of the segments. */ const lengths = (segments, bezier) => { let sum = 0 - let lengths = [0] + const lengths = [0] let previous = valueAt(0, bezier) for (let index = 1; index <= segments; index++) { const current = valueAt(index / segments, bezier) @@ -23,7 +23,7 @@ const lengths = (segments, bezier) => { previous = current } return lengths -}; +} /** * Calculates the Euclidean distance between two n-dimensional points. @@ -31,7 +31,7 @@ const lengths = (segments, bezier) => { * @example * const distance = distanceBetween([0, 0], [0, 10]); // calculate distance between 2D points * console.log(distance); // output 10 - * + * * @param {Array} a - first operand. * @param {Array} b - second operand. * @returns {Number} - distance. @@ -41,7 +41,7 @@ const distanceBetween = (a, b) => { return Math.abs(a - b) } else if (Array.isArray(a) && Array.isArray(b)) { if (a.length !== b.length) { - throw new Error("The operands must have the same number of dimensions.") + throw new Error('The operands must have the same number of dimensions.') } let sum = 0 for (let i = 0; i < a.length; i++) { @@ -49,8 +49,8 @@ const distanceBetween = (a, b) => { } return Math.sqrt(sum) } else { - throw new Error("The operands must be of the same type, either number or array.") + throw new Error('The operands must be of the same type, either number or array.') } -}; +} -module.exports = lengths \ No newline at end of file +module.exports = lengths diff --git a/packages/modeling/src/curves/bezier/lengths.test.js b/packages/modeling/src/curves/bezier/lengths.test.js index c6ef2e2ce..4cd6f09b1 100644 --- a/packages/modeling/src/curves/bezier/lengths.test.js +++ b/packages/modeling/src/curves/bezier/lengths.test.js @@ -17,7 +17,7 @@ test('calculate lengths for a 1D linear bezier with numeric control points', (t) test('calculate lengths for a 1D linear bezier with array control points', (t) => { const bezierCurve = bezier.create([[0], [10]]) const result = lengths(100, bezierCurve) - t.is(result.length, 101) + t.is(result.length, 101) nearlyEqual(t, result[0], 0, 0.0001) nearlyEqual(t, result[50], 5, 0.0001) nearlyEqual(t, result[100], 10, 0.0001) @@ -26,7 +26,7 @@ test('calculate lengths for a 1D linear bezier with array control points', (t) = test('calculate lengths for a 2D linear bezier', (t) => { const bezierCurve = bezier.create([[0, 0], [10, 10]]) const result = lengths(100, bezierCurve) - t.is(result.length, 101) + t.is(result.length, 101) nearlyEqual(t, result[0], 0, 0.0001) nearlyEqual(t, result[50], 7.0710, 0.0001) nearlyEqual(t, result[100], 14.1421, 0.0001) @@ -53,7 +53,7 @@ test('calculate lengths for a 2D cubic (4 control points) bezier', (t) => { test('calculate lengths for a 3D linear bezier', (t) => { const bezierCurve = bezier.create([[0, 0, 0], [10, 10, 10]]) const result = lengths(100, bezierCurve) - t.is(result.length, 101) + t.is(result.length, 101) nearlyEqual(t, result[0], 0, 0.0001) nearlyEqual(t, result[50], 8.6602, 0.0001) nearlyEqual(t, result[100], 17.3205, 0.0001) diff --git a/packages/modeling/src/geometries/poly2/arePointsInside.js b/packages/modeling/src/geometries/poly2/arePointsInside.js index aaa064a3d..6093932ba 100644 --- a/packages/modeling/src/geometries/poly2/arePointsInside.js +++ b/packages/modeling/src/geometries/poly2/arePointsInside.js @@ -80,11 +80,4 @@ const isPointInside = (point, polygon) => { return insideFlag } -/* - * > 0 : p2 is left of the line p0 -> p1 - * = 0 : p2 is on the line p0 -> p1 - * < 0 : p2 is right of the line p0 -> p1 - */ -const isLeft = (p0, p1, p2) => (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p2[0] - p0[0]) * (p1[1] - p0[1]) - module.exports = arePointsInside diff --git a/packages/modeling/src/geometries/poly3/measureBoundingSphere.js b/packages/modeling/src/geometries/poly3/measureBoundingSphere.js index bac62d62b..bc96bddb5 100644 --- a/packages/modeling/src/geometries/poly3/measureBoundingSphere.js +++ b/packages/modeling/src/geometries/poly3/measureBoundingSphere.js @@ -1,4 +1,3 @@ -const vec3 = require('../../maths/vec3') const vec4 = require('../../maths/vec4') const cache = new WeakMap() @@ -10,7 +9,7 @@ const cache = new WeakMap() * @alias module:modeling/geometries/poly3.measureBoundingSphere */ const measureBoundingSphere = (polygon) => { - let boundingSphere = cache.get(polygon) + const boundingSphere = cache.get(polygon) if (boundingSphere) return boundingSphere const vertices = polygon.vertices diff --git a/packages/modeling/src/operations/booleans/trees/PolygonTreeNode.js b/packages/modeling/src/operations/booleans/trees/PolygonTreeNode.js index 5eb99b4af..09df932e7 100644 --- a/packages/modeling/src/operations/booleans/trees/PolygonTreeNode.js +++ b/packages/modeling/src/operations/booleans/trees/PolygonTreeNode.js @@ -25,7 +25,7 @@ class PolygonTreeNode { this.parent = parent this.children = [] this.polygon = polygon - this.removed = false // state of branch or leaf + this.removed = false // state of branch or leaf } // fill the tree with polygons. Should be called on the root node only; child nodes must diff --git a/packages/modeling/src/operations/expansions/expand.test.js b/packages/modeling/src/operations/expansions/expand.test.js index 55f598471..8ba42792c 100644 --- a/packages/modeling/src/operations/expansions/expand.test.js +++ b/packages/modeling/src/operations/expansions/expand.test.js @@ -53,7 +53,7 @@ test('expand: round-expanding a bent line produces expected geometry', (t) => { const expandedPoints = geom2.toPoints(expandedPathGeom2) t.notThrows(() => geom2.validate(expandedPathGeom2)) - const expectedArea = 56 + TAU * delta * 1.25 // shape will have 1 and 1/4 circles + const expectedArea = 56 + TAU * delta * 1.25 // shape will have 1 and 1/4 circles nearlyEqual(t, area(expandedPoints), expectedArea, 0.01, 'Measured area should be pretty close') const boundingBox = measureBoundingBox(expandedPathGeom2) t.true(comparePoints(boundingBox, [[-7, -2, 0], [2, 12, 0]]), 'Unexpected bounding box: ' + JSON.stringify(boundingBox)) diff --git a/packages/modeling/src/operations/extrusions/extrudeHelical.js b/packages/modeling/src/operations/extrusions/extrudeHelical.js index cc6f95e15..c38bb1bf2 100644 --- a/packages/modeling/src/operations/extrusions/extrudeHelical.js +++ b/packages/modeling/src/operations/extrusions/extrudeHelical.js @@ -40,7 +40,7 @@ const extrudeHelical = (options, geometry) => { let pitch // ignore height if pitch is set - if(!options.pitch && options.height) { + if (!options.pitch && options.height) { pitch = options.height / (angle / TAU) } else { pitch = options.pitch ? options.pitch : defaults.pitch @@ -49,18 +49,17 @@ const extrudeHelical = (options, geometry) => { // needs at least 3 segments for each revolution const minNumberOfSegments = 3 - if (segmentsPerRotation < minNumberOfSegments) - throw new Error(`The number of segments per rotation needs to be at least 3.`) + if (segmentsPerRotation < minNumberOfSegments) { throw new Error('The number of segments per rotation needs to be at least 3.') } - let shapeSides = geom2.toSides(geometry) + const shapeSides = geom2.toSides(geometry) if (shapeSides.length === 0) throw new Error('the given geometry cannot be empty') // const pointsWithNegativeX = shapeSides.filter((s) => (s[0][0] < 0)) const pointsWithPositiveX = shapeSides.filter((s) => (s[0][0] >= 0)) - + let baseSlice = slice.fromSides(shapeSides) - - if(pointsWithPositiveX.length === 0) { + + if (pointsWithPositiveX.length === 0) { // only points in negative x plane, reverse baseSlice = slice.reverse(baseSlice) } diff --git a/packages/modeling/src/operations/extrusions/extrudeHelical.test.js b/packages/modeling/src/operations/extrusions/extrudeHelical.test.js index f4f601713..514cb4493 100644 --- a/packages/modeling/src/operations/extrusions/extrudeHelical.test.js +++ b/packages/modeling/src/operations/extrusions/extrudeHelical.test.js @@ -1,5 +1,4 @@ const test = require('ava') -const { comparePoints, comparePolygonsAsPoints } = require('../../../test/helpers') const { TAU } = require('../../maths/constants') const { geom2, geom3 } = require('../../geometries') const { circle } = require('../../primitives') @@ -7,56 +6,55 @@ const { circle } = require('../../primitives') const { extrudeHelical } = require('./index') test('extrudeHelical: (defaults) extruding of a geom2 produces an expected geom3', (t) => { - const geometry2 = geom2.fromPoints([[10, 8], [10, -8], [26, -8], [26, 8]]) + const geometry2 = geom2.fromPoints([[10, 8], [10, -8], [26, -8], [26, 8]]) - const geometry3 = extrudeHelical({}, geometry2) - const pts = geom3.toPoints(geometry3) - t.notThrows(() => geom3.validate(geometry3)) + const geometry3 = extrudeHelical({}, geometry2) + t.notThrows(() => geom3.validate(geometry3)) }) test('extrudeHelical: (defaults) extruding of a circle produces an expected geom3', (t) => { - const geometry2 = circle({ size: 3, center: [10, 0] }) + const geometry2 = circle({ size: 3, center: [10, 0] }) - const geometry3 = extrudeHelical({}, geometry2) - t.notThrows(() => geom3.validate(geometry3)) + const geometry3 = extrudeHelical({}, geometry2) + t.notThrows(() => geom3.validate(geometry3)) }) test('extrudeHelical: (angle) extruding of a circle produces an expected geom3', (t) => { - const maxRevolutions = 10 - const geometry2 = circle({ size: 3, center: [10, 0] }) - for (const index of [...Array(maxRevolutions).keys()]) { - // also test negative angles - const geometry3 = extrudeHelical({angle: TAU * (index - maxRevolutions / 2)}, geometry2) - t.notThrows(() => geom3.validate(geometry3)) - } + const maxRevolutions = 10 + const geometry2 = circle({ size: 3, center: [10, 0] }) + for (const index of [...Array(maxRevolutions).keys()]) { + // also test negative angles + const geometry3 = extrudeHelical({ angle: TAU * (index - maxRevolutions / 2) }, geometry2) + t.notThrows(() => geom3.validate(geometry3)) + } }) test('extrudeHelical: (pitch) extruding of a circle produces an expected geom3', (t) => { - const startPitch = -10 - const geometry2 = circle({ size: 3, center: [10, 0] }) - for (const index of [...Array(20).keys()]) { - // also test negative pitches - const geometry3 = extrudeHelical({pitch: startPitch + index}, geometry2) - t.notThrows(() => geom3.validate(geometry3)) - } + const startPitch = -10 + const geometry2 = circle({ size: 3, center: [10, 0] }) + for (const index of [...Array(20).keys()]) { + // also test negative pitches + const geometry3 = extrudeHelical({ pitch: startPitch + index }, geometry2) + t.notThrows(() => geom3.validate(geometry3)) + } }) test('extrudeHelical: (endRadiusOffset) extruding of a circle produces an expected geom3', (t) => { - const startOffset = -5 - const geometry2 = circle({ size: 3, center: [10, 0] }) - for (const index of [...Array(10).keys()]) { - // also test negative pitches - const geometry3 = extrudeHelical({endRadiusOffset: startOffset + index}, geometry2) - t.notThrows(() => geom3.validate(geometry3)) - } + const startOffset = -5 + const geometry2 = circle({ size: 3, center: [10, 0] }) + for (const index of [...Array(10).keys()]) { + // also test negative pitches + const geometry3 = extrudeHelical({ endRadiusOffset: startOffset + index }, geometry2) + t.notThrows(() => geom3.validate(geometry3)) + } }) test('extrudeHelical: (segments) extruding of a circle produces an expected geom3', (t) => { - const startSegments = 3 - const geometry2 = circle({ size: 3, center: [10, 0] }) - for (const index of [...Array(30).keys()]) { - // also test negative pitches - const geometry3 = extrudeHelical({segments: startSegments + index}, geometry2) - t.notThrows(() => geom3.validate(geometry3)) - } -}) \ No newline at end of file + const startSegments = 3 + const geometry2 = circle({ size: 3, center: [10, 0] }) + for (const index of [...Array(30).keys()]) { + // also test negative pitches + const geometry3 = extrudeHelical({ segments: startSegments + index }, geometry2) + t.notThrows(() => geom3.validate(geometry3)) + } +}) diff --git a/packages/modeling/src/operations/hulls/hullPoints2.js b/packages/modeling/src/operations/hulls/hullPoints2.js index d69f5a12e..10f1166fb 100644 --- a/packages/modeling/src/operations/hulls/hullPoints2.js +++ b/packages/modeling/src/operations/hulls/hullPoints2.js @@ -25,8 +25,9 @@ const hullPoints2 = (uniquePoints) => { }) // sort by polar coordinates - points.sort((pt1, pt2) => pt1.angle < pt2.angle ? -1 : pt1.angle > pt2.angle ? 1 : - pt1.distSq < pt2.distSq ? -1 : pt1.distSq > pt2.distSq ? 1 : 0) + points.sort((pt1, pt2) => pt1.angle !== pt2.angle + ? pt1.angle - pt2.angle + : pt1.distSq - pt2.distSq) const stack = [] // start with empty stack points.forEach((point) => { diff --git a/packages/modeling/src/operations/modifiers/index.js b/packages/modeling/src/operations/modifiers/index.js index a92406597..d4e21cbb3 100644 --- a/packages/modeling/src/operations/modifiers/index.js +++ b/packages/modeling/src/operations/modifiers/index.js @@ -8,5 +8,5 @@ module.exports = { generalize: require('./generalize'), snap: require('./snap'), - retessellate: require('./retessellate'), + retessellate: require('./retessellate') } diff --git a/packages/modeling/src/operations/modifiers/retessellate.js b/packages/modeling/src/operations/modifiers/retessellate.js index aa0a3e0c9..06cce7670 100644 --- a/packages/modeling/src/operations/modifiers/retessellate.js +++ b/packages/modeling/src/operations/modifiers/retessellate.js @@ -16,7 +16,7 @@ const retessellate = (geometry) => { return geometry } - const polygons = geom3.toPolygons(geometry).map((polygon, index) => ({vertices: polygon.vertices, plane: poly3.plane(polygon), index: index})) + const polygons = geom3.toPolygons(geometry).map((polygon, index) => ({ vertices: polygon.vertices, plane: poly3.plane(polygon), index: index })) const classified = classifyPolygons(polygons) const destPolygons = [] @@ -41,18 +41,18 @@ const classifyPolygons = (polygons) => { // go through each component of the plane starting with the last one (the distance from origin) for (let component = 3; component >= 0; component--) { const maybeCoplanar = [] - const tolerance = component == 3 ? 0.000000015 : NEPS - clusters.forEach(cluster => { + const tolerance = component === 3 ? 0.000000015 : NEPS + clusters.forEach((cluster) => { // sort the cluster by the current component cluster.sort(byPlaneComponent(component, tolerance)) - // iterate through the cluster and check if there are polygons which are not coplanar with the others + // iterate through the cluster and check if there are polygons which are not coplanar with the others // or if there are sub-clusters of coplanar polygons let startIndex = 0 for (let i = 1; i < cluster.length; i++) { // if there's a difference larger than the tolerance, split the cluster if (cluster[i].plane[component] - cluster[startIndex].plane[component] > tolerance) { // if there's a single polygon it's definitely not coplanar with any others - if (i - startIndex == 1) { + if (i - startIndex === 1) { nonCoplanar.push(cluster[startIndex]) } else { // we have a new sub cluster of potentially coplanar polygons maybeCoplanar.push(cluster.slice(startIndex, i)) @@ -61,7 +61,7 @@ const classifyPolygons = (polygons) => { } } // handle the last elements of the cluster - if (cluster.length - startIndex == 1) { + if (cluster.length - startIndex === 1) { nonCoplanar.push(cluster[startIndex]) } else { maybeCoplanar.push(cluster.slice(startIndex)) @@ -73,21 +73,19 @@ const classifyPolygons = (polygons) => { // restore the original order of the polygons const result = [] // polygons inside the cluster should already be sorted by index - clusters.forEach(cluster => result[cluster[0]?.index] = cluster) - nonCoplanar.forEach(polygon => result[polygon.index] = polygon) + clusters.forEach((cluster) => { result[cluster[0]?.index] = cluster }) + nonCoplanar.forEach((polygon) => { result[polygon.index] = polygon }) return result } -const byPlaneComponent = (component, tolerance) => { - return (a, b) => { - if (a.plane[component] - b.plane[component] > tolerance) { - return 1 - } else if (b.plane[component] - a.plane[component] > tolerance) { - return -1 - } - return 0 +const byPlaneComponent = (component, tolerance) => (a, b) => { + if (a.plane[component] - b.plane[component] > tolerance) { + return 1 + } else if (b.plane[component] - a.plane[component] > tolerance) { + return -1 } + return 0 } -module.exports = retessellate \ No newline at end of file +module.exports = retessellate diff --git a/packages/modeling/src/primitives/geodesicSphere.js b/packages/modeling/src/primitives/geodesicSphere.js index d7014cc29..65c556413 100644 --- a/packages/modeling/src/primitives/geodesicSphere.js +++ b/packages/modeling/src/primitives/geodesicSphere.js @@ -5,7 +5,7 @@ const geom3 = require('../geometries/geom3') const polyhedron = require('./polyhedron') -const { isGT, isGTE } = require('./commonChecks') +const { isGTE } = require('./commonChecks') /** * Construct a geodesic sphere based on icosahedron symmetry.