From 7251d81a658b5e22aee6e5073a1ad41d4e64de35 Mon Sep 17 00:00:00 2001 From: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:39:12 +0000 Subject: [PATCH] Fix path being closed when resampling (#1542) --- libraries/bezier-rs/src/subpath/lookup.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/bezier-rs/src/subpath/lookup.rs b/libraries/bezier-rs/src/subpath/lookup.rs index acc0e306..5bf69c95 100644 --- a/libraries/bezier-rs/src/subpath/lookup.rs +++ b/libraries/bezier-rs/src/subpath/lookup.rs @@ -38,12 +38,12 @@ impl Subpath { let mut accumulator = 0.; for (index, length) in lengths.iter().enumerate() { let length_ratio = length / total_length; - if accumulator <= global_t && global_t <= accumulator + length_ratio { - return (index, (global_t - accumulator) / length_ratio); + if (index == 0 || accumulator <= global_t) && global_t <= accumulator + length_ratio { + return (index, ((global_t - accumulator) / length_ratio).clamp(0., 1.)); } accumulator += length_ratio; } - (0, 0.) + (self.len() - 2, 1.) } /// Convert a [SubpathTValue] to a parametric `(segment_index, t)` tuple.