@@ -1147,27 +1147,33 @@ async fn sample_points(_: impl Ctx, vector_data: VectorDataTable, spacing: f64,
1147
1147
let spacing = spacing. max ( 0.01 ) ;
1148
1148
1149
1149
let vector_data_transform = vector_data. transform ( ) ;
1150
- // Using [stroke_bezpath_iter] so that the [subpath_segment_lengths] is aligned to the segments of each bezpaths.
1151
- // So we can index into [subpath_segment_lengths] to get the length of the segments.
1152
- // NOTE: [subpath_segment_lengths] has precalulated lengths with transformation applied.
1150
+
1151
+ // Using `stroke_bezpath_iter` so that the `subpath_segment_lengths` is aligned to the segments of each bezpath.
1152
+ // So we can index into `subpath_segment_lengths` to get the length of the segments.
1153
+ // NOTE: `subpath_segment_lengths` has precalulated lengths with transformation applied.
1153
1154
let bezpaths = vector_data. one_instance_ref ( ) . instance . stroke_bezpath_iter ( ) ;
1154
1155
1155
1156
// Initialize the result VectorData with the same transformation as the input.
1156
1157
let mut result = VectorDataTable :: default ( ) ;
1157
1158
* result. transform_mut ( ) = vector_data_transform;
1158
1159
1159
- // To keep the index of the first segment of the next bezpath to get lengths of segments.
1160
+ // Keeps track of the index of the first segment of the next bezpath in order to get lengths of all segments.
1160
1161
let mut next_segment_index = 0 ;
1161
1162
1162
1163
for mut bezpath in bezpaths {
1163
1164
let mut sample_bezpath = BezPath :: new ( ) ;
1165
+
1164
1166
// Apply the tranformation to the current bezpath to calculate points after transformation.
1165
1167
bezpath. apply_affine ( Affine :: new ( vector_data_transform. to_cols_array ( ) ) ) ;
1168
+
1166
1169
let segment_count = bezpath. segments ( ) . count ( ) ;
1167
- // For the current bezpath the get its segments length by calculating the start index and end index.
1170
+
1171
+ // For the current bezpath we get its segment's length by calculating the start index and end index.
1168
1172
let lengths = & subpath_segment_lengths[ next_segment_index..next_segment_index + segment_count] ;
1169
- // Increment the segment index by the number of segments in the current bezpath to calculate the next bezpath segments length.
1173
+
1174
+ // Increment the segment index by the number of segments in the current bezpath to calculate the next bezpath segment's length.
1170
1175
next_segment_index += segment_count;
1176
+
1171
1177
// Calculate the total length of the collected segments.
1172
1178
let total_length: f64 = lengths. iter ( ) . sum ( ) ;
1173
1179
@@ -1203,9 +1209,9 @@ async fn sample_points(_: impl Ctx, vector_data: VectorDataTable, spacing: f64,
1203
1209
let fraction = c as f64 / count;
1204
1210
let current_length = fraction * used_length + start_offset;
1205
1211
let t = current_length / total_length;
1206
- let point = position_on_bezpath ( & bezpath, t, true , Some ( & lengths) ) ;
1212
+ let point = position_on_bezpath ( & bezpath, t, true , Some ( lengths) ) ;
1207
1213
1208
- if sample_bezpath. elements ( ) . len ( ) == 0 {
1214
+ if sample_bezpath. elements ( ) . is_empty ( ) {
1209
1215
sample_bezpath. move_to ( point)
1210
1216
} else {
1211
1217
sample_bezpath. line_to ( point)
@@ -1214,6 +1220,7 @@ async fn sample_points(_: impl Ctx, vector_data: VectorDataTable, spacing: f64,
1214
1220
1215
1221
// Reverse the transformation applied to the bezpath as the `result` already has the transformation set.
1216
1222
sample_bezpath. apply_affine ( Affine :: new ( vector_data_transform. to_cols_array ( ) ) . inverse ( ) ) ;
1223
+
1217
1224
// Append the bezpath (subpath) that connects generated points by lines.
1218
1225
result. one_instance_mut ( ) . instance . append_bezpath ( sample_bezpath) ;
1219
1226
}
0 commit comments