summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Cory Forsstrom <cory.forsstrom@lich.io>2022-01-27 10:01:03 -0800
committerLibravatar Cory Forsstrom <cory.forsstrom@lich.io>2022-01-27 10:01:03 -0800
commit730c57ba67e20e2179418961e50fdc24acfdb677 (patch)
treec159891d40a4e663ef88678739aada9d15cfa263 /graphics
parente835cea03c5d6eeba2d76b52206516dcc2a6b628 (diff)
downloadiced-730c57ba67e20e2179418961e50fdc24acfdb677.tar.gz
iced-730c57ba67e20e2179418961e50fdc24acfdb677.tar.bz2
iced-730c57ba67e20e2179418961e50fdc24acfdb677.zip
Remove vec allocation
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/widget/canvas/path.rs71
1 files changed, 36 insertions, 35 deletions
diff --git a/graphics/src/widget/canvas/path.rs b/graphics/src/widget/canvas/path.rs
index b52c1f90..bc258b67 100644
--- a/graphics/src/widget/canvas/path.rs
+++ b/graphics/src/widget/canvas/path.rs
@@ -72,41 +72,42 @@ impl Path {
}
pub(super) fn dashed(path: &Path, line_dash: LineDash) -> Path {
- let segments_odd = line_dash.segments.len() % 2 == 1;
-
- let segments = segments_odd
- .then(|| [&line_dash.segments[..], &line_dash.segments[..]].concat())
- .unwrap_or(line_dash.segments);
-
- let mut points = vec![];
-
- walk_along_path(
- path.raw().iter().flattened(0.01),
- 0.0,
- &mut RepeatedPattern {
- callback: |position: lyon_algorithms::math::Point,
- _tangent,
- _distance| {
- points.push(Point {
- x: position.x,
- y: position.y,
- });
- true
- },
- index: line_dash.offset,
- intervals: &segments,
- },
- );
-
Path::new(|builder| {
- for (idx, point) in points.into_iter().enumerate() {
- let is_even = idx % 2 == 0;
-
- if is_even {
- builder.move_to(point);
- } else {
- builder.line_to(point);
- }
- }
+ let segments_odd = line_dash.segments.len() % 2 == 1;
+
+ let segments = segments_odd
+ .then(|| {
+ [&line_dash.segments[..], &line_dash.segments[..]].concat()
+ })
+ .unwrap_or(line_dash.segments);
+
+ let mut draw_line = false;
+
+ walk_along_path(
+ path.raw().iter().flattened(0.01),
+ 0.0,
+ &mut RepeatedPattern {
+ callback: |position: lyon_algorithms::math::Point,
+ _tangent,
+ _distance| {
+ let point = Point {
+ x: position.x,
+ y: position.y,
+ };
+
+ if draw_line {
+ builder.line_to(point);
+ } else {
+ builder.move_to(point);
+ }
+
+ draw_line = !draw_line;
+
+ true
+ },
+ index: line_dash.offset,
+ intervals: &segments,
+ },
+ );
})
}