Update integration tests for stroke Bézier.
This commit is contained in:
		| @@ -35,6 +35,7 @@ serde =  { version = "1", optional = true } | ||||
| serde_derive = { version = "1", optional = true } | ||||
|  | ||||
| [dev-dependencies] | ||||
| float-cmp = "0.5" | ||||
| serde_json = "1" | ||||
|  | ||||
| [package.metadata.docs.rs] | ||||
|   | ||||
							
								
								
									
										67
									
								
								tests/mod.rs
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								tests/mod.rs
									
									
									
									
									
								
							| @@ -1,55 +1,9 @@ | ||||
| use splines::{ Interpolate, Interpolation, Key, Spline}; | ||||
| use splines::interpolate::{Additive, Linear}; | ||||
| use std::ops::{Add, Div, Sub, Mul}; | ||||
| use float_cmp::approx_eq; | ||||
| use splines::{Interpolation, Key, Spline}; | ||||
|  | ||||
| #[cfg(feature = "cgmath")] use cgmath as cg; | ||||
| #[cfg(feature = "nalgebra")] use nalgebra as na; | ||||
|  | ||||
| // Small utility 2D-point. | ||||
| #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] | ||||
| struct P2<T> { | ||||
|   x: T, | ||||
|   y: T | ||||
| } | ||||
|  | ||||
| impl<T> Add for P2<T> where T: Add<T, Output = T> { | ||||
|   type Output = Self; | ||||
|  | ||||
|   fn add(self, rhs: Self) -> Self::Output { | ||||
|     P2 { | ||||
|       x: self.x + rhs.x, | ||||
|       y: self.y + rhs.y | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| impl<T> Sub for P2<T> where T: Sub<T, Output = T> { | ||||
|   type Output = Self; | ||||
|  | ||||
|   fn sub(self, rhs: Self) -> Self::Output { | ||||
|     P2 { | ||||
|       x: self.x - rhs.x, | ||||
|       y: self.y - rhs.y | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| impl<T> Linear<T> for P2<T> where Self: Additive, T: Mul<T, Output = T> + Div<T, Output = T> { | ||||
|   fn outer_mul(self, t: T) -> Self { | ||||
|     P2 { | ||||
|       x: self.x * t, | ||||
|       y: self.y * t, | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   fn outer_div(self, t: T) -> Self { | ||||
|     P2 { | ||||
|       x: self.x / t, | ||||
|       y: self.y / t, | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| #[test] | ||||
| fn step_interpolation_f32() { | ||||
|   let start = Key::new(0., 0., Interpolation::Step(0.)); | ||||
| @@ -196,20 +150,21 @@ fn several_interpolations_several_keys() { | ||||
|   assert_eq!(spline.clamped_sample(11.), Some(4.)); | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "cgmath")] | ||||
| #[test] | ||||
| fn stroke_bezier_straight() { | ||||
|   let keys = vec![ | ||||
|     Key::new(0.0, [0., 1.], Interpolation::StrokeBezier([0., 1.], [0., 1.])), | ||||
|     Key::new(5.0, [5., 1.], Interpolation::StrokeBezier([5., 1.], [5., 1.])) | ||||
|     Key::new(0.0, cg::Vector2::new(0., 1.), Interpolation::StrokeBezier(cg::Vector2::new(0., 1.), cg::Vector2::new(0., 1.))), | ||||
|     Key::new(5.0, cg::Vector2::new(5., 1.), Interpolation::StrokeBezier(cg::Vector2::new(5., 1.), cg::Vector2::new(5., 1.))) | ||||
|   ]; | ||||
|   let spline = Spline::from_vec(keys); | ||||
|  | ||||
|   assert_eq!(spline.clamped_sample(0.0)[1], 1.); | ||||
|   assert_eq!(spline.clamped_sample(1.0)[1], 1.); | ||||
|   assert_eq!(spline.clamped_sample(2.0)[1], 1.); | ||||
|   assert_eq!(spline.clamped_sample(3.0)[1], 1.); | ||||
|   assert_eq!(spline.clamped_sample(4.0)[1], 1.); | ||||
|   assert_eq!(spline.clamped_sample(5.0)[1], 1.); | ||||
|   assert!(approx_eq!(f32, spline.clamped_sample(0.0).unwrap().y, 1.)); | ||||
|   assert!(approx_eq!(f32, spline.clamped_sample(1.0).unwrap().y, 1.)); | ||||
|   assert!(approx_eq!(f32, spline.clamped_sample(2.0).unwrap().y, 1.)); | ||||
|   assert!(approx_eq!(f32, spline.clamped_sample(3.0).unwrap().y, 1.)); | ||||
|   assert!(approx_eq!(f32, spline.clamped_sample(4.0).unwrap().y, 1.)); | ||||
|   assert!(approx_eq!(f32, spline.clamped_sample(5.0).unwrap().y, 1.)); | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "cgmath")] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user