summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseancarroll <seanc28@gmail.com>2021-01-02 16:53:48 -0600
committerseancarroll <seanc28@gmail.com>2021-01-02 16:53:48 -0600
commitc2e4d99301432e0bfcda1b3218c454e7c1379500 (patch)
tree3c4034b91e8c79561e6f24d6f38ce47ebbd424fa
parentecf32922605a565c0a915c1c4a4fc06d55dfcb7f (diff)
downloaddotavious-c2e4d99301432e0bfcda1b3218c454e7c1379500.zip
tweak Point constructors
-rw-r--r--src/lib.rs58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0b22966..898cf6b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1381,24 +1381,22 @@ pub struct Point {
impl Point {
- pub fn new_2d(x: f32, y: f32, force_pos: bool) -> Self {
- Self {
- x,
- y,
- z: None,
- force_pos,
- }
+ pub fn new_2d(x: f32, y: f32) -> Self {
+ Self::new(x, y, None, false)
+ }
+
+ pub fn new_3d(x: f32, y: f32, z: f32) -> Self {
+ Self::new(x, y, Some(z), false)
}
- pub fn new_3d(x: f32, y: f32, z: f32, force_pos: bool) -> Self {
+ pub fn new(x: f32, y: f32, z: Option<f32>, force_pos: bool) -> Self {
Self {
x,
y,
- z: Some(z),
+ z,
force_pos,
}
}
-
}
impl<'a> From<Point> for AttributeText<'a> {
@@ -3627,9 +3625,9 @@ fn spline_type() {
end: None,
start: None,
spline_points: vec![
- Point::new_2d(0.0, 0.0, false),
- Point::new_2d(1.0, 1.0, false),
- Point::new_2d(1.0, -1.0, false)
+ Point::new_2d(0.0, 0.0),
+ Point::new_2d(1.0, 1.0),
+ Point::new_2d(1.0, -1.0)
],
};
@@ -3639,12 +3637,12 @@ fn spline_type() {
#[test]
fn spline_type_end() {
let spline_type = SplineType {
- end: Some(Point::new_2d(2.0, 0.0, false)),
+ end: Some(Point::new_2d(2.0, 0.0)),
start: None,
spline_points: vec![
- Point::new_2d(0.0, 0.0, false),
- Point::new_2d(1.0, 1.0, false),
- Point::new_2d(1.0, -1.0, false)
+ Point::new_2d(0.0, 0.0),
+ Point::new_2d(1.0, 1.0),
+ Point::new_2d(1.0, -1.0)
],
};
@@ -3655,11 +3653,11 @@ fn spline_type_end() {
fn spline_type_start() {
let spline_type = SplineType {
end: None,
- start: Some(Point::new_2d(-1.0, 0.0, false)),
+ start: Some(Point::new_2d(-1.0, 0.0)),
spline_points: vec![
- Point::new_2d(0.0, 0.0, false),
- Point::new_2d(1.0, 1.0, false),
- Point::new_2d(1.0, -1.0, false)
+ Point::new_2d(0.0, 0.0),
+ Point::new_2d(1.0, 1.0),
+ Point::new_2d(1.0, -1.0)
],
};
@@ -3669,12 +3667,12 @@ fn spline_type_start() {
#[test]
fn spline_type_complete() {
let spline_type = SplineType {
- end: Some(Point::new_2d(2.0, 0.0, false)),
- start: Some(Point::new_2d(-1.0, 0.0, false)),
+ end: Some(Point::new_2d(2.0, 0.0)),
+ start: Some(Point::new_2d(-1.0, 0.0)),
spline_points: vec![
- Point::new_2d(0.0, 0.0, false),
- Point::new_2d(1.0, 1.0, false),
- Point::new_2d(1.0, -1.0, false)
+ Point::new_2d(0.0, 0.0),
+ Point::new_2d(1.0, 1.0),
+ Point::new_2d(1.0, -1.0)
],
};
@@ -3683,10 +3681,10 @@ fn spline_type_complete() {
#[test]
fn point_string() {
- assert_eq!("1.0,2.0", Point::new_2d(1.0, 2.0, false).dot_string());
- assert_eq!("1.0,2.0!", Point::new_2d(1.0, 2.0, true).dot_string());
- assert_eq!("1.0,2.0,0.0", Point::new_3d(1.0, 2.0, 0.0, false).dot_string());
- assert_eq!("1.0,2.0,0.0!", Point::new_3d(1.0, 2.0, 0.0, true).dot_string());
+ assert_eq!("1.0,2.0", Point::new_2d(1.0, 2.0).dot_string());
+ assert_eq!("1.0,2.0,0.0", Point::new_3d(1.0, 2.0, 0.0).dot_string());
+ assert_eq!("1.0,2.0!", Point::new(1.0, 2.0, None, true).dot_string());
+ assert_eq!("1.0,2.0,0.0!", Point::new(1.0, 2.0, Some(0.0), true).dot_string());
}
#[test]