Check for divide by zero in grid

This commit is contained in:
Mitchell McCaffrey 2021-07-18 08:40:44 +10:00
parent 8e8e800760
commit a6a233542e

View File

@ -48,22 +48,28 @@ function Grid({ stroke }: { stroke: "black" | "white" }) {
if (grid.type === "square") { if (grid.type === "square") {
// Square grid pattern is 150 DPI // Square grid pattern is 150 DPI
const scale = gridCellPixelSize.width / 300; const scale = gridCellPixelSize.width / 300;
patternProps.fillPatternScaleX = scale; if (scale > 0) {
patternProps.fillPatternScaleY = scale; patternProps.fillPatternScaleX = scale;
patternProps.fillPatternOffsetX = gridCellPixelSize.width / scale / 2; patternProps.fillPatternScaleY = scale;
patternProps.fillPatternOffsetY = gridCellPixelSize.height / scale / 2; patternProps.fillPatternOffsetX = gridCellPixelSize.width / scale / 2;
patternProps.fillPatternOffsetY = gridCellPixelSize.height / scale / 2;
}
} else if (grid.type === "hexVertical") { } else if (grid.type === "hexVertical") {
// Hex tile pattern is 153 DPI to better fit hex tiles // Hex tile pattern is 153 DPI to better fit hex tiles
const scale = gridCellPixelSize.width / 153; const scale = gridCellPixelSize.width / 153;
patternProps.fillPatternScaleX = scale; if (scale > 0) {
patternProps.fillPatternScaleY = scale; patternProps.fillPatternScaleX = scale;
patternProps.fillPatternOffsetY = gridCellPixelSize.radius / scale / 2; patternProps.fillPatternScaleY = scale;
patternProps.fillPatternOffsetY = gridCellPixelSize.radius / scale / 2;
}
} else if (grid.type === "hexHorizontal") { } else if (grid.type === "hexHorizontal") {
const scale = gridCellPixelSize.height / 153; const scale = gridCellPixelSize.height / 153;
patternProps.fillPatternScaleX = scale; if (scale > 0) {
patternProps.fillPatternScaleY = scale; patternProps.fillPatternScaleX = scale;
patternProps.fillPatternOffsetY = -gridCellPixelSize.radius / scale / 2; patternProps.fillPatternScaleY = scale;
patternProps.fillPatternRotation = 90; patternProps.fillPatternOffsetY = -gridCellPixelSize.radius / scale / 2;
patternProps.fillPatternRotation = 90;
}
} }
return ( return (