diff --git a/src/helpers/drawing.js b/src/helpers/drawing.js index 0229422..a03ec02 100644 --- a/src/helpers/drawing.js +++ b/src/helpers/drawing.js @@ -150,7 +150,7 @@ export function getUpdatedShapeData(type, data, brushPosition, gridSize) { const length = Vector2.length(scaled); const direction = Vector2.normalize(scaled); // Get the angle for a triangle who's width is the same as it's length - const angle = Math.atan(length / 2 / length); + const angle = Math.atan(length / 2 / (length === 0 ? 1 : length)); const sideLength = length / Math.cos(angle); const leftDir = Vector2.rotateDirection(direction, toDegrees(angle)); diff --git a/src/helpers/vector2.js b/src/helpers/vector2.js index 41be521..63f3030 100644 --- a/src/helpers/vector2.js +++ b/src/helpers/vector2.js @@ -10,6 +10,9 @@ export function length(p) { export function normalize(p) { const l = length(p); + if (l === 0) { + return { x: 0, y: 0 }; + } return divide(p, l); }