@@ -34,7 +34,7 @@ pub fn sample_points_on_bezpath(bezpath: BezPath, spacing: f64, start_offset: f6
3434 }
3535
3636 // Determine the number of points to generate along the path.
37- let count = if adaptive_spacing {
37+ let sample_count = if adaptive_spacing {
3838 // Calculate point count to evenly distribute points while covering the entire path.
3939 // With adaptive spacing, we widen or narrow the points as necessary to ensure the last point is always at the end of the path.
4040 ( used_length / spacing) . round ( )
@@ -48,24 +48,24 @@ pub fn sample_points_on_bezpath(bezpath: BezPath, spacing: f64, start_offset: f6
4848 } ;
4949
5050 // Skip if there are no points to generate.
51- if count < 1. {
51+ if sample_count < 1. {
5252 return None ;
5353 }
5454 // Generate points along the path based on calculated intervals.
55- let max_c = count as usize ;
5655 let mut length_upto_previous_segment = 0. ;
5756 let mut next_segment_index = 0 ;
5857
59- for c in 0 ..=max_c {
60- let fraction = c as f64 / count ;
61- let c_next_length = fraction * used_length + start_offset;
62- let mut next_length = c_next_length - length_upto_previous_segment;
58+ for count in 0 ..=sample_count as usize {
59+ let fraction = count as f64 / sample_count ;
60+ let length_upto_next_sample_point = fraction * used_length + start_offset;
61+ let mut next_length = length_upto_next_sample_point - length_upto_previous_segment;
6362 let mut next_segment_length = segments_length[ next_segment_index] ;
6463
65- while next_length > next_segment_length && ( next_length - next_segment_length ) > 1e-7 {
66- next_segment_index += 1 ;
64+ // Keep moving to the next segment while the next sample point length is less or equals to the length upto that segment.
65+ while next_length > next_segment_length && ( next_length - next_segment_length ) > POSITION_ACCURACY {
6766 length_upto_previous_segment += next_segment_length;
68- next_length = c_next_length - length_upto_previous_segment;
67+ next_length = length_upto_next_sample_point - length_upto_previous_segment;
68+ next_segment_index += 1 ;
6969 next_segment_length = segments_length[ next_segment_index] ;
7070 }
7171
0 commit comments