From 493194a1fa9a921df55c63e807933d9b1e7e4c54 Mon Sep 17 00:00:00 2001 From: Steven Petryk Date: Fri, 31 May 2024 16:49:28 -0700 Subject: [PATCH] Avoid rendering zero-length vectors in VectorField Closes #164 --- src/display/Plot/VectorField.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/display/Plot/VectorField.tsx b/src/display/Plot/VectorField.tsx index c62ad3b4..c539b0be 100644 --- a/src/display/Plot/VectorField.tsx +++ b/src/display/Plot/VectorField.tsx @@ -37,6 +37,10 @@ export function VectorField({ const tail: vec.Vector2 = [x, y] const trueOffset = xy([x, y]) const trueMag = vec.mag(trueOffset) + + // Avoid rendering zero-length vectors + if (trueMag === 0) continue + const scaledOffset = vec.scale(vec.normalize(trueOffset), Math.min(trueMag, step * 0.75)) const tip = vec.add(tail, scaledOffset)