[librsvg] PathBuilder: use LargeArc and Sweep types instead of plain booleans
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] PathBuilder: use LargeArc and Sweep types instead of plain booleans
- Date: Tue, 29 Aug 2017 13:31:24 +0000 (UTC)
commit 40a049cee1705e768d43d67d6dfc4bcda0be0098
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Aug 29 08:27:18 2017 -0500
PathBuilder: use LargeArc and Sweep types instead of plain booleans
This makes it easier to see what the arguments PathBuilder::arc() are about.
rust/src/path_builder.rs | 27 ++++++++++++++++++++-------
rust/src/path_parser.rs | 11 +++++++++--
rust/src/shapes.rs | 8 ++++----
3 files changed, 33 insertions(+), 13 deletions(-)
---
diff --git a/rust/src/path_builder.rs b/rust/src/path_builder.rs
index ce9a816..30e4e49 100644
--- a/rust/src/path_builder.rs
+++ b/rust/src/path_builder.rs
@@ -5,6 +5,15 @@ use std::f64;
use std::f64::consts::*;
#[derive(Debug, PartialEq)]
+pub struct LargeArc(pub bool);
+
+#[derive(Debug, PartialEq)]
+pub enum Sweep {
+ Negative,
+ Positive
+}
+
+#[derive(Debug, PartialEq)]
pub enum PathCommand {
MoveTo (f64, f64),
LineTo (f64, f64),
@@ -50,16 +59,16 @@ impl RsvgPathBuilder {
* x1/y1: starting coordinates
* rx/ry: radiuses before rotation
* x_axis_rotation: Rotation angle for axes, in degrees
- * is_large_arc: false for arc length <= 180, true for arc >= 180
- * is_sweep: false for negative angle, true for positive angle
+ * large_arc: false for arc length <= 180, true for arc >= 180
+ * sweep: negative or positive angle
* x2/y2: ending coordinates
*/
pub fn arc (&mut self,
x1: f64, y1: f64,
mut rx: f64, mut ry: f64,
x_axis_rotation: f64,
- is_large_arc: bool,
- is_sweep: bool,
+ large_arc: LargeArc,
+ sweep: Sweep,
x2: f64, y2: f64) {
/* See Appendix F.6 Elliptical arc implementation notes
http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes */
@@ -87,6 +96,10 @@ impl RsvgPathBuilder {
return;
}
+ let is_positive_sweep = sweep == Sweep::Positive;
+
+ let is_large_arc = large_arc.0;
+
/* X-axis */
f = x_axis_rotation * PI / 180.0;
sinf = f.sin ();
@@ -122,7 +135,7 @@ impl RsvgPathBuilder {
}
k1 = ((rx * rx * ry * ry) / k1 - 1.0).abs ().sqrt ();
- if is_sweep == is_large_arc {
+ if is_positive_sweep == is_large_arc {
k1 = -k1;
}
@@ -165,9 +178,9 @@ impl RsvgPathBuilder {
delta_theta = -delta_theta;
}
- if is_sweep && delta_theta < 0.0 {
+ if is_positive_sweep && delta_theta < 0.0 {
delta_theta += PI * 2.0;
- } else if !is_sweep && delta_theta > 0.0 {
+ } else if !is_positive_sweep && delta_theta > 0.0 {
delta_theta -= PI * 2.0;
}
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index 3fc0e53..eaa1fed 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -369,7 +369,7 @@ impl<'b> PathParser<'b> {
self.builder.curve_to (x2, y2, x3, y3, x4, y4);
}
- fn emit_arc (&mut self, rx: f64, ry: f64, x_axis_rotation: f64, large_arc: bool, sweep: bool, x: f64, y:
f64) {
+ fn emit_arc (&mut self, rx: f64, ry: f64, x_axis_rotation: f64, large_arc: LargeArc, sweep: Sweep, x:
f64, y: f64) {
let (start_x, start_y) = (self.current_x, self.current_y);
self.set_current_point (x, y);
@@ -905,16 +905,23 @@ impl<'b> PathParser<'b> {
if let Some (large_arc_flag) = self.flag () {
assert! (self.optional_comma_whitespace ());
+ let large_arc = LargeArc (large_arc_flag);
+
if let Some (sweep_flag) = self.flag () {
assert! (self.optional_comma_whitespace ());
+ let sweep = match sweep_flag {
+ false => Sweep::Negative,
+ true => Sweep::Positive
+ };
+
if let Some ((mut x, mut y)) = self.coordinate_pair () {
if !absolute {
x += self.current_x;
y += self.current_y;
}
- self.emit_arc (rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x,
y);
+ self.emit_arc (rx, ry, x_axis_rotation, large_arc, sweep, x, y);
self.whitespace ();
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 61dd917..989f91f 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -394,25 +394,25 @@ impl NodeTrait for NodeRect {
builder.line_to (top_x2, top_y);
builder.arc (top_x2, top_y,
- rx, ry, 0.0, false, true,
+ rx, ry, 0.0, LargeArc (false), Sweep::Positive,
right_x, right_y1);
builder.line_to (right_x, right_y2);
builder.arc (right_x, right_y2,
- rx, ry, 0.0, false, true,
+ rx, ry, 0.0, LargeArc (false), Sweep::Positive,
bottom_x2, bottom_y);
builder.line_to (bottom_x1, bottom_y);
builder.arc (bottom_x1, bottom_y,
- rx, ry, 0.0, false, true,
+ rx, ry, 0.0, LargeArc (false), Sweep::Positive,
left_x, left_y2);
builder.line_to (left_x, left_y1);
builder.arc (left_x, left_y1,
- rx, ry, 0.0, false, true,
+ rx, ry, 0.0, LargeArc (false), Sweep::Positive,
top_x1, top_y);
builder.close_path ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]