Refactored getBrushPosition helper

This commit is contained in:
Mitchell McCaffrey 2020-11-03 16:20:51 +11:00
parent 251a89eaf4
commit 9c1960ba71
4 changed files with 8 additions and 19 deletions

View File

@ -55,8 +55,8 @@ function MapDrawing({
return getBrushPositionForTool( return getBrushPositionForTool(
map, map,
getRelativePointerPositionNormalized(mapImage), getRelativePointerPositionNormalized(mapImage),
toolId, map.snapToGrid && isShape,
toolSettings, false,
gridSize, gridSize,
shapes shapes
); );

View File

@ -61,8 +61,8 @@ function MapFog({
return getBrushPositionForTool( return getBrushPositionForTool(
map, map,
getRelativePointerPositionNormalized(mapImage), getRelativePointerPositionNormalized(mapImage),
toolId, map.snapToGrid && toolSettings.type === "polygon",
toolSettings, toolSettings.useEdgeSnapping,
gridSize, gridSize,
shapes shapes
); );

View File

@ -38,8 +38,8 @@ function MapMeasure({ map, selectedToolSettings, active, gridSize }) {
return getBrushPositionForTool( return getBrushPositionForTool(
map, map,
getRelativePointerPositionNormalized(mapImage), getRelativePointerPositionNormalized(mapImage),
"drawing", map.snapToGrid,
{ type: "line" }, false,
gridSize, gridSize,
[] []
); );

View File

@ -8,22 +8,13 @@ const snappingThreshold = 1 / 5;
export function getBrushPositionForTool( export function getBrushPositionForTool(
map, map,
brushPosition, brushPosition,
tool, useGridSnappning,
toolSettings, useEdgeSnapping,
gridSize, gridSize,
shapes shapes
) { ) {
let position = brushPosition; 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) { 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
@ -58,8 +49,6 @@ export function getBrushPositionForTool(
} }
} }
const useEdgeSnapping = tool === "fog" && toolSettings.useEdgeSnapping;
if (useEdgeSnapping) { if (useEdgeSnapping) {
const minGrid = Vector2.min(gridSize); const minGrid = Vector2.min(gridSize);
let closestDistance = Number.MAX_VALUE; let closestDistance = Number.MAX_VALUE;