Skip to content

Commit

Permalink
chore(deps): update dependency polybool to v2.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 1, 2024
1 parent 75ee5a1 commit 74c9998
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@kitware/vtk.js": "^29.0.0",
"@netlify/edge-functions": "^2.0.0",
"@sentry/vue": "^7.54.0",
"@velipso/polybool": "^1.1.0",
"@velipso/polybool": "^2.0.11",
"@vueuse/core": "^10.7.0",
"core-js": "3.22.5",
"deep-equal": "^2.0.5",
Expand Down
12 changes: 0 additions & 12 deletions patches/@velipso+polybool+1.1.0.patch

This file was deleted.

22 changes: 17 additions & 5 deletions src/store/tools/polygons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import polybool, { Polygon as LibPolygon } from '@velipso/polybool';
import polybool, { Polygon as LibPolygon, Vec2, Vec6 } from '@velipso/polybool';
import type { Vector3, Vector2 } from '@kitware/vtk.js/types';
import { computed } from 'vue';
import {
Expand All @@ -19,6 +19,17 @@ const toolDefaults = () => ({
name: 'Polygon',
});

const ensureVec2 = (regions: (Vec2 | Vec6)[][]) => {
const remapToVec2Needed =
regions.length > 0 && regions[0].length > 0 && regions[0][0].length === 6;
return !remapToVec2Needed
? (regions as Vec2[][])
: regions.map((region) => {
// ensure Vec2 points, and not Vec6 for bezier control points
return region.map((point) => [point[4], point[5]] as Vec2);
});
};

export const usePolygonStore = defineAnnotationToolStore('polygon', () => {
const toolAPI = useAnnotationTool({
toolDefaults,
Expand Down Expand Up @@ -53,7 +64,7 @@ export const usePolygonStore = defineAnnotationToolStore('polygon', () => {

// After union, regions will have shared points because we require overlap to union.
// Create one region/ring by splicing in the next region at the common point.
const mergeRegions = (regions: Array<Array<Vector2>>) => {
const mergeRegions = (regions: Vector2[][]) => {
const [mergedRegion, ...candidates] = regions;

while (candidates.length > 0) {
Expand Down Expand Up @@ -96,12 +107,13 @@ export const usePolygonStore = defineAnnotationToolStore('polygon', () => {
const comb = polybool.combine(segments, seg2);
segments = polybool.selectUnion(comb);
}
const unionPoly = polybool.polygon(segments);

const unionPolyRegions = polybool.polygon(segments).regions;
const singleRegion = mergeRegions(ensureVec2(unionPolyRegions));

const firstTool = polygons[0];
const { to3D } = getPlaneTransforms(firstTool.frameOfReference);

const points = mergeRegions(unionPoly.regions).map(to3D);
const points = singleRegion.map(to3D);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id: _, ...toolProps } = polygons[0];
Expand Down

0 comments on commit 74c9998

Please sign in to comment.