Fix divide by zero on triangle shapes
This commit is contained in:
parent
9a4d047cd5
commit
96a100c02a
@ -150,7 +150,7 @@ export function getUpdatedShapeData(type, data, brushPosition, gridSize) {
|
|||||||
const length = Vector2.length(scaled);
|
const length = Vector2.length(scaled);
|
||||||
const direction = Vector2.normalize(scaled);
|
const direction = Vector2.normalize(scaled);
|
||||||
// Get the angle for a triangle who's width is the same as it's length
|
// 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 sideLength = length / Math.cos(angle);
|
||||||
|
|
||||||
const leftDir = Vector2.rotateDirection(direction, toDegrees(angle));
|
const leftDir = Vector2.rotateDirection(direction, toDegrees(angle));
|
||||||
|
@ -10,6 +10,9 @@ export function length(p) {
|
|||||||
|
|
||||||
export function normalize(p) {
|
export function normalize(p) {
|
||||||
const l = length(p);
|
const l = length(p);
|
||||||
|
if (l === 0) {
|
||||||
|
return { x: 0, y: 0 };
|
||||||
|
}
|
||||||
return divide(p, l);
|
return divide(p, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user