[librsvg/rustification] marker.rs: Separate segment setup from the state machine logic
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] marker.rs: Separate segment setup from the state machine logic
- Date: Wed, 26 Oct 2016 18:06:25 +0000 (UTC)
commit eb0c09967103c01ab736e34a644ae6409f31164a
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Oct 26 12:06:09 2016 -0500
marker.rs: Separate segment setup from the state machine logic
We put all the housekeeping for coordinates at the beginning
of each match case, along with setting up the current segment.
This leaves the state machine logic at the end of each match case,
and this code is duplicated; hmmm.
rust/src/marker.rs | 58 ++++++++++++++++++++++++++--------------------------
1 files changed, 29 insertions(+), 29 deletions(-)
---
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index 3c3beef..4b0f17a 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -74,15 +74,15 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
cur_x = x;
cur_y = y;
- subpath_start_x = cur_x;
- subpath_start_y = cur_y;
-
seg = Segment::Degenerate {
x: cur_x,
y: cur_y
};
needs_new_segment = true;
+ subpath_start_x = cur_x;
+ subpath_start_y = cur_y;
+
state = SegmentState::Start;
},
@@ -90,17 +90,6 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
cur_x = x;
cur_y = y;
- match state {
- SegmentState::Start => {
- state = SegmentState::End;
- needs_new_segment = false;
- },
-
- SegmentState::End => {
- needs_new_segment = true;
- }
- }
-
seg = Segment::LineOrCurve {
x1: last_x,
y1: last_y,
@@ -114,14 +103,6 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
x4: cur_x,
y4: cur_y,
};
- },
-
- cairo::PathSegment::CurveTo ((mut x2, mut y2), (mut x3, mut y3), (x4, y4)) => {
- cur_x = x4;
- cur_y = y4;
-
- let x1 = last_x;
- let y1 = last_y;
match state {
SegmentState::Start => {
@@ -133,9 +114,17 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
needs_new_segment = true;
}
}
+ },
+
+ cairo::PathSegment::CurveTo ((mut x2, mut y2), (mut x3, mut y3), (x4, y4)) => {
+ cur_x = x4;
+ cur_y = y4;
/* Fix the tangents for when the middle control points coincide with their respective
endpoints */
+ let x1 = last_x;
+ let y1 = last_y;
+
if double_equals (x2, x1) && double_equals (y2, y1) {
x2 = x3;
y2 = y3;
@@ -159,11 +148,6 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
x4: x4,
y4: y4,
};
- }
-
- cairo::PathSegment::ClosePath => {
- cur_x = subpath_start_x;
- cur_y = subpath_start_y;
match state {
SegmentState::Start => {
@@ -172,10 +156,14 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
},
SegmentState::End => {
- needs_new_segment = false;
- /* nothing; closepath after moveto (or a single lone closepath) does nothing */
+ needs_new_segment = true;
}
}
+ }
+
+ cairo::PathSegment::ClosePath => {
+ cur_x = subpath_start_x;
+ cur_y = subpath_start_y;
seg = Segment::LineOrCurve {
x1: last_x,
@@ -190,6 +178,18 @@ pub fn path_to_segments (path: cairo::Path) -> Vec<Segment> {
x4: cur_x,
y4: cur_y,
};
+
+ match state {
+ SegmentState::Start => {
+ state = SegmentState::End;
+ needs_new_segment = false;
+ },
+
+ SegmentState::End => {
+ needs_new_segment = false;
+ /* nothing; closepath after moveto (or a single lone closepath) does nothing */
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]