[−][src]Struct cubic_spline::Points
Wrapper for your source points.
Prepares and validates points before calculating spline.
Create it with try_from
/
try_into
.
Or if you are very confident in the validity of your points use usual From/Into
traits,
which will return an empty Vec
on error.
Example
use cubic_spline::{Points, TryFrom}; let src1 = vec![[1.2, 3.3], [122.2, 333.3]]; let src2 = [[1.2, 3.3], [122.2, 333.3]]; let src3 = [(1.2, 3.3), (122.2, 333.3)]; let src4 = [1.2, 3.3, 122.2, 333.3]; assert!(Points::try_from(&src1).is_ok()); assert!(Points::try_from(&src2).is_ok()); assert_eq!(Points::from(&src3).get_ref().len(), 2); let points1 = Points::try_from_flatten(&src4).unwrap(); let points2: Points = src1.into(); let first1 = points1.get_ref().first().unwrap(); assert!(first1.approx_eq(&points2.into_inner()[0]));
Implementations
impl Points
[src]
pub fn get_ref(&self) -> &Vec<Point>
[src]
Gets a reference to the underlying Vec<Point>
.
pub fn get_mut(&mut self) -> &mut Vec<Point>
[src]
Gets a mutable reference to the underlying Vec<Point>
.
pub fn into_inner(self) -> Vec<Point>
[src]
Consumes the Points
, returning the wrapped Vec<Point>
.
pub fn try_from_flatten<'a, I: IntoIterator<Item = &'a f64>>(
into_f64_iter: I
) -> Result<Self>
[src]
into_f64_iter: I
) -> Result<Self>
Similar to try_from
but takes a flatten sequence of f64
numbers
where value at even index is x
and value at odd index is y
(e.g. vec![12.0f64, 12.77, 15.3, 17.9]
, [x,y,x,y,x...]
).
pub fn invert_horizontally(&mut self, width: f64)
[src]
Inverts the x-value of all points based on the width of the canvas.
Example
use cubic_spline::Points; let mut pts = Points::from(&[(1.0, 3.0), (2.0, 2.0)]); pts.invert_horizontally(7.0); let inverted: Vec<(f64,f64)> = pts.into(); assert_eq!(&[(6.0, 3.0), (5.0,2.0)].as_ref(), &inverted );
pub fn invert_vertically(&mut self, height: f64)
[src]
Inverts the y-value of all points based on the height of the canvas.
Example
use cubic_spline::Points; let mut pts = Points::from(&[(1.0, 3.0), (2.0, 2.0)]); pts.invert_vertically(7.0); let inverted: Vec<(f64,f64)> = pts.into(); assert_eq!(&[(1.0, 4.0), (2.0,5.0)].as_ref(), &inverted );
pub fn calc_spline(&self, opts: &SplineOpts) -> Result<Points>
[src]
The main function that does all the work.
Returns points of curve constructed within the range of passed points using cubic spline interpolation.
Example
use cubic_spline::{Points, TryFrom, SplineOpts}; let src_points = vec![(1.0, 1.0), (3.3, 2.7), (5.1, 0.9)]; let prepared_points = Points::try_from(&src_points).expect("cant convert points"); let options = SplineOpts::new() .tension(0.7) .num_of_segments(16); let calculated_points = prepared_points.calc_spline(&options).unwrap(); assert_eq!(calculated_points.get_ref().len(), 33);
Trait Implementations
impl Clone for Points
[src]
impl Debug for Points
[src]
impl<I: IntoIterator> From<I> for Points where
I::Item: Into<Point>,
[src]
I::Item: Into<Point>,
impl From<Points> for Vec<(f64, f64)>
[src]
impl From<Points> for Vec<[f64; 2]>
[src]
impl From<Points> for Vec<f64>
[src]
impl<I: IntoIterator> TryFrom<I> for Points where
I::Item: Into<Point>,
[src]
I::Item: Into<Point>,
Auto Trait Implementations
impl RefUnwindSafe for Points
[src]
impl Send for Points
[src]
impl Sync for Points
[src]
impl Unpin for Points
[src]
impl UnwindSafe for Points
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,