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(
map,
getRelativePointerPositionNormalized(mapImage),
toolId,
toolSettings,
map.snapToGrid && isShape,
false,
gridSize,
shapes
);

View File

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

View File

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

View File

@ -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;