[−][src]Struct cubic_spline::Points

`pub struct 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]

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<I: IntoIterator> TryFrom<I> for Points where    I::Item: Into<Point>, `[src]

`type Error = Error`

The type returned in the event of a conversion error.

Blanket Implementations

`impl<T> ToOwned for T where    T: Clone, `[src]

`type Owned = T`

The resulting type after obtaining ownership.

`impl<T, U> TryFrom<U> for T where    U: Into<T>, `[src]

`type Error = Infallible`

The type returned in the event of a conversion error.

`impl<T, U> TryInto<U> for T where    U: TryFrom<T>, `[src]

`type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.