Skip to content

Commit

Permalink
Avoid rendering zero-length vectors in VectorField
Browse files Browse the repository at this point in the history
Closes #164
  • Loading branch information
stevenpetryk committed May 31, 2024
1 parent bd42eda commit 493194a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/display/Plot/VectorField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 493194a

Please sign in to comment.