Skip to content

Commit 2b1578b

Browse files
authored
Merge pull request #98 from jneem/master
Be more permissive in segments_of_slice.
2 parents 7bd7e66 + 8115293 commit 2b1578b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/bezpath.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,11 @@ impl BezPath {
191191
// TODO: expose as pub method? Maybe should be a trait so slice.segments() works?
192192
fn segments_of_slice<'a>(slice: &'a [PathEl]) -> BezPathSegs<'a> {
193193
let first = match slice.get(0) {
194-
Some(PathEl::MoveTo(ref p)) => *p,
195-
Some(_) => panic!("First element has to be a PathEl::Moveto!"),
194+
Some(PathEl::MoveTo(p)) => *p,
195+
Some(PathEl::LineTo(p)) => *p,
196+
Some(PathEl::QuadTo(_, p2)) => *p2,
197+
Some(PathEl::CurveTo(_, _, p3)) => *p3,
198+
Some(PathEl::ClosePath) => panic!("Can't start a segment on a ClosePath"),
196199
None => Default::default(),
197200
};
198201

@@ -747,6 +750,10 @@ impl Shape for BezPath {
747750
}
748751
}
749752

753+
/// Implements [`Shape`] for a slice of [`PathEl`], provided that the first element of the slice is
754+
/// not a `PathEl::ClosePath`. If it is, several of these functions will panic.
755+
///
756+
/// If the slice starts with `LineTo`, `QuadTo`, or `CurveTo`, it will be treated as a `MoveTo`.
750757
impl<'a> Shape for &'a [PathEl] {
751758
type BezPathIter = std::iter::Cloned<std::slice::Iter<'a, PathEl>>;
752759

0 commit comments

Comments
 (0)