Skip to content

Commit

Permalink
cap max segments
Browse files Browse the repository at this point in the history
  • Loading branch information
bobnik committed Jun 10, 2024
1 parent 6e345bd commit 8fab150
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/common/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export const subsample = (vertices, maxLength) => {
let subsampledVertices = []
let previous = undefined
let next
const maxSegments = 1000

for (next = 0; next < vertices.length; next++) {
if (previous !== undefined) {
Expand All @@ -309,7 +310,13 @@ export const subsample = (vertices, maxLength) => {
.multiply(Victor(maxLength, maxLength))

// This loads up (start, end].
for (let step = 0; step < delta.magnitude() / maxLength; step++) {
const magnitude = delta.magnitude()

// If the magnitude is unreasonably large, cap the number of segments
// to prevent the creation of too many points
const segmentMaxLength = Math.max(magnitude / maxSegments, maxLength)

for (let step = 0; step < magnitude / segmentMaxLength; step++) {
subsampledVertices.push(
new Victor(
start.x + step * deltaSegment.x,
Expand Down

0 comments on commit 8fab150

Please sign in to comment.