Remove vec allocation
This commit is contained in:
parent
e835cea03c
commit
730c57ba67
1 changed files with 35 additions and 34 deletions
|
|
@ -72,41 +72,42 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn dashed(path: &Path, line_dash: LineDash) -> 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| {
|
Path::new(|builder| {
|
||||||
for (idx, point) in points.into_iter().enumerate() {
|
let segments_odd = line_dash.segments.len() % 2 == 1;
|
||||||
let is_even = idx % 2 == 0;
|
|
||||||
|
|
||||||
if is_even {
|
let segments = segments_odd
|
||||||
builder.move_to(point);
|
.then(|| {
|
||||||
} else {
|
[&line_dash.segments[..], &line_dash.segments[..]].concat()
|
||||||
builder.line_to(point);
|
})
|
||||||
}
|
.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,
|
||||||
|
},
|
||||||
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue