Repository: GraphiteEditor/Graphite
File: node-graph/gcore/src/vector/algorithms/bezpath_algorithms.rs (Rust)

Code before:
	let mut used_length = total_length - start_offset - stop_offset;

	if used_length <= 0. {
		return None;
	}

	// Determine the number of points to generate along the path.
	let sample_count = if adaptive_spacing {
		// Calculate point count to evenly distribute points while covering the entire path.
		// With adaptive spacing, we widen or narrow the points as necessary to ensure the last point is always at the end of the path.
		(used_length / spacing).round()
	} else {
		// Calculate point count based on exact spacing, which may not cover the entire path.

		// Without adaptive spacing, we just evenly space the points at the exact specified spacing, usually falling short before the end of the path.
		let count = (used_length / spacing + f64::EPSILON).floor();
		used_length -= used_length % spacing;
		count
	};

	// Skip if there are no points to generate.
	if sample_count < 1. {
		return None;
	}

	// decide how many loop-iterations: if closed, skip the last duplicate point
	let sample_count_usize = sample_count as usize;
	let max_i = if was_closed { sample_count_usize } else { sample_count_usize + 1 };

	// Generate points along the path based on calculated intervals.
	let mut length_up_to_previous_segment = 0.;
	let mut next_segment_index = 0;

	for count in 0..max_i {
		let fraction = count as f64 / sample_count;
		let length_up_to_next_sample_point = fraction * used_length + start_offset;
		let mut next_length = length_up_to_next_sample_point - length_up_to_previous_segment;
		let mut next_segment_length = segments_length[next_segment_index];

		// Keep moving to the next segment while the length up to the next sample point is greater than the length up to the current segment.
		while next_length > next_segment_length {
			if next_segment_index == segments_length.len() - 1 {
				break;
			}
			length_up_to_previous_segment += next_segment_length;
			next_length = length_up_to_next_sample_point - length_up_to_previous_segment;
			next_segment_index += 1;
			next_segment_length = segments_length[next_segment_index];
		}

		let t = (next_length / next_segment_length).clamp(0., 1.);

Review comment (refactor):
```suggestion
	// Decide how many loop-iterations: if closed, skip the last duplicate point
```

Code after:
	let mut used_length = total_length - start_offset - stop_offset;

	if used_length <= 0. {
		return None;
	}

	// Determine the number of points to generate along the path.
	let sample_count = if adaptive_spacing {
		// Calculate point count to evenly distribute points while covering the entire path.
		// With adaptive spacing, we widen or narrow the points as necessary to ensure the last point is always at the end of the path.
		(used_length / spacing).round()
	} else {
		// Calculate point count based on exact spacing, which may not cover the entire path.

		// Without adaptive spacing, we just evenly space the points at the exact specified spacing, usually falling short before the end of the path.
		let count = (used_length / spacing + f64::EPSILON).floor();
		used_length -= used_length % spacing;
		count
	};

	// Skip if there are no points to generate.
	if sample_count < 1. {
		return None;
	}

	// Decide how many loop-iterations: if closed, skip the last duplicate point
	let sample_count_usize = sample_count as usize;
	let max_i = if was_closed { sample_count_usize } else { sample_count_usize + 1 };

	// Generate points along the path based on calculated intervals.
	let mut length_up_to_previous_segment = 0.;
	let mut next_segment_index = 0;

	for count in 0..max_i {
		let fraction = count as f64 / sample_count;
		let length_up_to_next_sample_point = fraction * used_length + start_offset;
		let mut next_length = length_up_to_next_sample_point - length_up_to_previous_segment;
		let mut next_segment_length = segments_length[next_segment_index];

		// Keep moving to the next segment while the length up to the next sample point is greater than the length up to the current segment.
		while next_length > next_segment_length {
			if next_segment_index == segments_length.len() - 1 {
				break;
			}
			length_up_to_previous_segment += next_segment_length;
			next_length = length_up_to_next_sample_point - length_up_to_previous_segment;
			next_segment_index += 1;
			next_segment_length = segments_length[next_segment_index];
		}

		let t = (next_length / next_segment_length).clamp(0., 1.);