Skip to content

Commit 8400135

Browse files
committed
small fix and improve variable names & comment
1 parent 1ed5e24 commit 8400135

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

node-graph/gcore/src/vector/algorithms/bezpath_algorithms.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -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,28 +48,28 @@ 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

72-
let t = next_length / next_segment_length;
72+
let t = (next_length / next_segment_length).clamp(0., 1.);
7373

7474
let point = bezpath.get_seg(next_segment_index + 1).unwrap().eval(t);
7575

0 commit comments

Comments
 (0)