Moved draw action helpers into new file to fix import errors with workers
This commit is contained in:
parent
fa1f6fe18f
commit
924b3e2481
@ -1,3 +1,5 @@
|
|||||||
|
// Load Diff for auto complete
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
import { Diff } from "deep-diff";
|
import { Diff } from "deep-diff";
|
||||||
|
|
||||||
import { diff, revertChanges } from "../helpers/diff";
|
import { diff, revertChanges } from "../helpers/diff";
|
||||||
|
@ -4,7 +4,7 @@ import Action from "./Action";
|
|||||||
import {
|
import {
|
||||||
addPolygonDifferenceToShapes,
|
addPolygonDifferenceToShapes,
|
||||||
addPolygonIntersectionToShapes,
|
addPolygonIntersectionToShapes,
|
||||||
} from "../helpers/drawing";
|
} from "../helpers/actions";
|
||||||
|
|
||||||
class CutShapeAction extends Action {
|
class CutShapeAction extends Action {
|
||||||
constructor(shapes) {
|
constructor(shapes) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import polygonClipping from "polygon-clipping";
|
import polygonClipping from "polygon-clipping";
|
||||||
|
|
||||||
import Action from "./Action";
|
import Action from "./Action";
|
||||||
import { addPolygonDifferenceToShapes } from "../helpers/drawing";
|
import { addPolygonDifferenceToShapes } from "../helpers/actions";
|
||||||
|
|
||||||
class SubtractShapeAction extends Action {
|
class SubtractShapeAction extends Action {
|
||||||
constructor(shapes) {
|
constructor(shapes) {
|
||||||
|
37
src/helpers/actions.js
Normal file
37
src/helpers/actions.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
export function addPolygonDifferenceToShapes(shape, difference, shapes) {
|
||||||
|
for (let i = 0; i < difference.length; i++) {
|
||||||
|
let newId = `${shape.id}-dif-${i}`;
|
||||||
|
// Holes detected
|
||||||
|
let holes = [];
|
||||||
|
if (difference[i].length > 1) {
|
||||||
|
for (let j = 1; j < difference[i].length; j++) {
|
||||||
|
holes.push(difference[i][j].map(([x, y]) => ({ x, y })));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shapes[newId] = {
|
||||||
|
...shape,
|
||||||
|
id: newId,
|
||||||
|
data: {
|
||||||
|
points: difference[i][0].map(([x, y]) => ({ x, y })),
|
||||||
|
holes,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addPolygonIntersectionToShapes(shape, intersection, shapes) {
|
||||||
|
for (let i = 0; i < intersection.length; i++) {
|
||||||
|
let newId = `${shape.id}-int-${i}`;
|
||||||
|
shapes[newId] = {
|
||||||
|
...shape,
|
||||||
|
id: newId,
|
||||||
|
data: {
|
||||||
|
points: intersection[i][0].map(([x, y]) => ({ x, y })),
|
||||||
|
holes: [],
|
||||||
|
},
|
||||||
|
// Default intersection visibility to false
|
||||||
|
visible: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,6 @@ const snappingThreshold = 1 / 5;
|
|||||||
export function getBrushPosition(map, mapStage, useGridSnappning, gridSize) {
|
export function getBrushPosition(map, mapStage, useGridSnappning, gridSize) {
|
||||||
const mapImage = mapStage.findOne("#mapImage");
|
const mapImage = mapStage.findOne("#mapImage");
|
||||||
let position = getRelativePointerPositionNormalized(mapImage);
|
let position = getRelativePointerPositionNormalized(mapImage);
|
||||||
|
|
||||||
if (useGridSnappning) {
|
if (useGridSnappning) {
|
||||||
// Snap to corners of grid
|
// Snap to corners of grid
|
||||||
// Subtract offset to transform into offset space then add it back transform back
|
// Subtract offset to transform into offset space then add it back transform back
|
||||||
@ -20,7 +19,6 @@ export function getBrushPosition(map, mapStage, useGridSnappning, gridSize) {
|
|||||||
offset
|
offset
|
||||||
);
|
);
|
||||||
const gridDistance = Vector2.length(Vector2.subtract(gridSnap, position));
|
const gridDistance = Vector2.length(Vector2.subtract(gridSnap, position));
|
||||||
|
|
||||||
// Snap to center of grid
|
// Snap to center of grid
|
||||||
// Subtract offset and half size to transform it into offset half space then transform it back
|
// Subtract offset and half size to transform it into offset half space then transform it back
|
||||||
const halfSize = Vector2.multiply(gridSize, 0.5);
|
const halfSize = Vector2.multiply(gridSize, 0.5);
|
||||||
@ -219,44 +217,6 @@ export function simplifyPoints(points, gridSize, scale) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addPolygonDifferenceToShapes(shape, difference, shapes) {
|
|
||||||
for (let i = 0; i < difference.length; i++) {
|
|
||||||
let newId = `${shape.id}-dif-${i}`;
|
|
||||||
// Holes detected
|
|
||||||
let holes = [];
|
|
||||||
if (difference[i].length > 1) {
|
|
||||||
for (let j = 1; j < difference[i].length; j++) {
|
|
||||||
holes.push(difference[i][j].map(([x, y]) => ({ x, y })));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shapes[newId] = {
|
|
||||||
...shape,
|
|
||||||
id: newId,
|
|
||||||
data: {
|
|
||||||
points: difference[i][0].map(([x, y]) => ({ x, y })),
|
|
||||||
holes,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function addPolygonIntersectionToShapes(shape, intersection, shapes) {
|
|
||||||
for (let i = 0; i < intersection.length; i++) {
|
|
||||||
let newId = `${shape.id}-int-${i}`;
|
|
||||||
shapes[newId] = {
|
|
||||||
...shape,
|
|
||||||
id: newId,
|
|
||||||
data: {
|
|
||||||
points: intersection[i][0].map(([x, y]) => ({ x, y })),
|
|
||||||
holes: [],
|
|
||||||
},
|
|
||||||
// Default intersection visibility to false
|
|
||||||
visible: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mergeShapes(shapes) {
|
export function mergeShapes(shapes) {
|
||||||
if (shapes.length === 0) {
|
if (shapes.length === 0) {
|
||||||
return shapes;
|
return shapes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user