Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Move up empty geometry checks

Use Geom3[] instead of ...Geom3
  • Loading branch information
platypii committed Dec 16, 2023
1 parent 4121054 commit cf64094
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 15 deletions.
5 changes: 2 additions & 3 deletions packages/modeling/src/operations/booleans/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { intersectGeom3 } from './intersectGeom3.js'
* The given geometries should be of the same type, either geom2 or geom3.
*
* @param {...Object} geometries - list of geometries
* @returns {Geom2|geom3} a new geometry
* @returns {Geom2|Geom3} a new geometry
* @alias module:modeling/booleans.intersect
*
* @example
Expand All @@ -32,12 +32,11 @@ import { intersectGeom3 } from './intersectGeom3.js'
export const intersect = (...geometries) => {
geometries = coalesce(geometries)

if (geometries.length === 0) return undefined
if (!areAllShapesTheSameType(geometries)) {
throw new Error('intersect arguments must be the same geometry type')
}

if (geometries.length === 0) return undefined

const geometry = geometries[0]
// if (path.isA(geometry)) return intersectPath(matrix, geometries)
if (geom2.isA(geometry)) return intersectGeom2(geometries)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { boolean } from './martinez/index.js'
/*
* Return a new 2D geometry representing space in both the first geometry and
* in the subsequent geometries. None of the given geometries are modified.
* @param {...Geom2} geometries - a flat list of 2D geometries
* @param {Geom2[]} geometries - a flat list of 2D geometries
* @returns {Geom2} new 2D geometry
*/
export const intersectGeom2 = (geometries) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { intersectGeom3Sub } from './intersectGeom3Sub.js'
/*
* Return a new 3D geometry representing space in both the first geometry and
* in the subsequent geometries. None of the given geometries are modified.
* @param {...Geom3} geometries - a flat list of 3D geometries
* @param {Geom3[]} geometries - a flat list of 3D geometries
* @returns {Geom3} new 3D geometry
*/
export const intersectGeom3 = (geometries) => {
Expand Down
5 changes: 2 additions & 3 deletions packages/modeling/src/operations/booleans/subtract.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { subtractGeom3 } from './subtractGeom3.js'
* The given geometries should be of the same type, either geom2 or geom3.
*
* @param {...Object} geometries - list of geometries
* @returns {Geom2|geom3} a new geometry
* @returns {Geom2|Geom3} a new geometry
* @alias module:modeling/booleans.subtract
*
* @example
Expand All @@ -32,12 +32,11 @@ import { subtractGeom3 } from './subtractGeom3.js'
export const subtract = (...geometries) => {
geometries = coalesce(geometries)

if (geometries.length === 0) return undefined
if (!areAllShapesTheSameType(geometries)) {
throw new Error('subtract arguments must be the same geometry type')
}

if (geometries.length === 0) return undefined

const geometry = geometries[0]
// if (path.isA(geometry)) return subtractPath(matrix, geometries)
if (geom2.isA(geometry)) return subtractGeom2(geometries)
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/operations/booleans/subtractGeom2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { boolean } from './martinez/index.js'
/*
* Return a new 2D geometry representing space in the first geometry but
* not in the subsequent geometries. None of the given geometries are modified.
* @param {...Geom2} geometries - a flat list of 2D geometries
* @param {Geom2[]} geometries - a flat list of 2D geometries
* @returns {Geom2} new 2D geometry
*/
export const subtractGeom2 = (geometries) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/operations/booleans/subtractGeom3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { subtractGeom3Sub } from './subtractGeom3Sub.js'
/*
* Return a new 3D geometry representing space in this geometry but not in the given geometries.
* Neither this geometry nor the given geometries are modified.
* @param {...Geom3} geometries - a flat list of 3D geometries
* @param {Geom3[]} geometries - a flat list of 3D geometries
* @returns {Geom3} new 3D geometry
*/
export const subtractGeom3 = (geometries) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/modeling/src/operations/booleans/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ import { unionGeom3 } from './unionGeom3.js'
export const union = (...geometries) => {
geometries = coalesce(geometries)

if (geometries.length === 0) return undefined
if (!areAllShapesTheSameType(geometries)) {
throw new Error('union arguments must be the same geometry type')
}

if (geometries.length === 0) return undefined

const geometry = geometries[0]
// if (path.isA(geometry)) return unionPath(matrix, geometries)
if (geom2.isA(geometry)) return unionGeom2(geometries)
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/operations/booleans/unionGeom2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { boolean } from './martinez/index.js'

/*
* Return a new 2D geometry representing the total space in the given 2D geometries.
* @param {...geom2} geometries - a flat list of 2D geometries to union
* @param {Geom2[]} geometries - a flat list of 2D geometries to union
* @returns {Geom2} new 2D geometry
*/
export const unionGeom2 = (geometries) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/operations/booleans/unionGeom3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { unionGeom3Sub } from './unionGeom3Sub.js'

/*
* Return a new 3D geometry representing the space in the given 3D geometries.
* @param {...Geom3} geometries - a flat list of 3D geometries to union
* @param {Geom3[]} geometries - a flat list of 3D geometries to union
* @returns {Geom3} new 3D geometry
*/
export const unionGeom3 = (geometries) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/operations/hulls/hullChain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { hull } from './hull.js'
* The given geometries should be of the same type, either geom2 or geom3 or path2.
*
* @param {...Objects} geometries - list of geometries from which to create a hull
* @returns {Geom2|Geom3} new geometry
* @returns {Geom2|Geom3|Path2} new geometry
* @alias module:modeling/hulls.hullChain
*
* @example
Expand Down

0 comments on commit cf64094

Please sign in to comment.