Refactored getBrushPosition helper
This commit is contained in:
parent
251a89eaf4
commit
9c1960ba71
@ -55,8 +55,8 @@ function MapDrawing({
|
||||
return getBrushPositionForTool(
|
||||
map,
|
||||
getRelativePointerPositionNormalized(mapImage),
|
||||
toolId,
|
||||
toolSettings,
|
||||
map.snapToGrid && isShape,
|
||||
false,
|
||||
gridSize,
|
||||
shapes
|
||||
);
|
||||
|
@ -61,8 +61,8 @@ function MapFog({
|
||||
return getBrushPositionForTool(
|
||||
map,
|
||||
getRelativePointerPositionNormalized(mapImage),
|
||||
toolId,
|
||||
toolSettings,
|
||||
map.snapToGrid && toolSettings.type === "polygon",
|
||||
toolSettings.useEdgeSnapping,
|
||||
gridSize,
|
||||
shapes
|
||||
);
|
||||
|
@ -38,8 +38,8 @@ function MapMeasure({ map, selectedToolSettings, active, gridSize }) {
|
||||
return getBrushPositionForTool(
|
||||
map,
|
||||
getRelativePointerPositionNormalized(mapImage),
|
||||
"drawing",
|
||||
{ type: "line" },
|
||||
map.snapToGrid,
|
||||
false,
|
||||
gridSize,
|
||||
[]
|
||||
);
|
||||
|
@ -8,22 +8,13 @@ const snappingThreshold = 1 / 5;
|
||||
export function getBrushPositionForTool(
|
||||
map,
|
||||
brushPosition,
|
||||
tool,
|
||||
toolSettings,
|
||||
useGridSnappning,
|
||||
useEdgeSnapping,
|
||||
gridSize,
|
||||
shapes
|
||||
) {
|
||||
let position = brushPosition;
|
||||
|
||||
const useGridSnappning =
|
||||
map.snapToGrid &&
|
||||
((tool === "drawing" &&
|
||||
(toolSettings.type === "line" ||
|
||||
toolSettings.type === "rectangle" ||
|
||||
toolSettings.type === "circle" ||
|
||||
toolSettings.type === "triangle")) ||
|
||||
(tool === "fog" && toolSettings.type === "polygon"));
|
||||
|
||||
if (useGridSnappning) {
|
||||
// Snap to corners of grid
|
||||
// Subtract offset to transform into offset space then add it back transform back
|
||||
@ -58,8 +49,6 @@ export function getBrushPositionForTool(
|
||||
}
|
||||
}
|
||||
|
||||
const useEdgeSnapping = tool === "fog" && toolSettings.useEdgeSnapping;
|
||||
|
||||
if (useEdgeSnapping) {
|
||||
const minGrid = Vector2.min(gridSize);
|
||||
let closestDistance = Number.MAX_VALUE;
|
||||
|
Loading…
Reference in New Issue
Block a user