[librsvg] PathCommand: derive PartialEq so we can remove a custom comparison function
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] PathCommand: derive PartialEq so we can remove a custom comparison function
- Date: Wed, 23 Aug 2017 01:57:39 +0000 (UTC)
commit 95355f7f0ab0cb1ad0313bbf7a93d0e403c5810e
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Aug 22 20:50:50 2017 -0500
PathCommand: derive PartialEq so we can remove a custom comparison function
rust/src/path_builder.rs | 3 +-
rust/src/path_parser.rs | 66 +--------------------------------------------
2 files changed, 4 insertions(+), 65 deletions(-)
---
diff --git a/rust/src/path_builder.rs b/rust/src/path_builder.rs
index b71f5dd..ce9a816 100644
--- a/rust/src/path_builder.rs
+++ b/rust/src/path_builder.rs
@@ -4,6 +4,7 @@ use ::cairo_sys;
use std::f64;
use std::f64::consts::*;
+#[derive(Debug, PartialEq)]
pub enum PathCommand {
MoveTo (f64, f64),
LineTo (f64, f64),
@@ -41,7 +42,7 @@ impl RsvgPathBuilder {
self.path_commands.push (PathCommand::ClosePath);
}
- pub fn get_path_commands (&self) -> &Vec<PathCommand> {
+ pub fn get_path_commands (&self) -> &[PathCommand] {
&self.path_commands
}
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index 2685f9f..3fc0e53 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -1003,68 +1003,6 @@ mod tests {
extern crate cairo;
- fn path_command_vectors_are_equal (a: &Vec<PathCommand>,
- b: &Vec<PathCommand>) -> bool {
-
- if a.len() != b.len () {
- return false;
- }
-
- if a.len () == 0 && b.len () == 0 {
- return true;
- }
-
- let mut iter = a.iter().zip (b);
-
- loop {
- if let Some ((seg1, seg2)) = iter.next () {
- match *seg1 {
- PathCommand::MoveTo (x, y) => {
- if let PathCommand::MoveTo (ox, oy) = *seg2 {
- if (x, y) != (ox, oy) {
- return false;
- }
- } else {
- return false;
- }
- },
-
- PathCommand::LineTo (x, y) => {
- if let PathCommand::LineTo (ox, oy) = *seg2 {
- if (x, y) != (ox, oy) {
- return false;
- }
- } else {
- return false;
- }
- },
-
- PathCommand::CurveTo ((x2, y2), (x3, y3), (x4, y4)) => {
- if let PathCommand::CurveTo ((ox2, oy2), (ox3, oy3), (ox4, oy4)) = *seg2 {
- if (ox2, oy2, ox3, oy3, ox4, oy4) != (x2, y2, x3, y3, x4, y4) {
- return false;
- }
- } else {
- return false;
- }
- },
-
- PathCommand::ClosePath => {
- if let PathCommand::ClosePath = *seg2 {
- /* okay */
- } else {
- return false;
- }
- }
- }
- } else {
- break;
- }
- }
-
- true
- }
-
fn print_error (error: &ParseError, path_str: &str) {
let prefix = "Error in \"";
@@ -1092,11 +1030,11 @@ mod tests {
}
fn test_parser (path_str: &str,
- expected_commands: &Vec<PathCommand>) {
+ expected_commands: &[PathCommand]) {
let builder = parse_path (path_str);
let commands = builder.get_path_commands ();
- assert! (path_command_vectors_are_equal (expected_commands, commands));
+ assert_eq! (expected_commands, commands);
}
fn moveto (x: f64, y: f64) -> PathCommand {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]