cubic_spline
Interpolation method for computation of cubic spline points within the range of a discrete set of known points.
Example
use ;
let source = vec!;
let opts = new.tension;
let mut points = try_from.expect;
let result = points.calc_spline.expect;
assert_eq!;
points.get_mut.push;
points.get_mut.x += 0.79;
points.invert_vertically;
assert_eq!;
let calculated_points = points
.calc_spline
.unwrap;
assert_eq!;
For information on how a curve can be constructed and which points to accept, see the appropriate structures.
Custom points
If you already have some points you can implement From trait for Point
struct and pass your points directly.
Example
use ;
let my_points: = vec!;
let spline = from
.calc_spline
.unwrap;
assert_eq!;
Example for JS
import from 'cubic-spline-rs'
const NUM_OF_SEGMENTS = 22
const points =
const curvePoints =
If you want to draw result points to canvas - code like this:
const ctx =
ctx.
ctx. = 3
ctx. = '#ffcc00'
ctx.
const length = curvePoints. - 1
ctx.
ctx.
See example here.
Options
| Name | Type | Default | Description |
|---|---|---|---|
| tension | f64 |
0.5 |
Tension |
| num_of_segments | u32 |
16 |
Number of calculated points between known points |
| hidden_point_at_start | Option<(f64,f64)> |
None |
A point that will not be drawn, but the beginning of the graph will bend as if it is there. |
| hidden_point_at_end | Option<(f64,f64)> |
None |
A point that will not be drawn, but the end of the graph will bend as if it is there. |
use ;
let options = new
.tension
.num_of_segments
// .hidden_point_at_start((1.2, 3.1))
// .hidden_point_at_end((397.9, 105.5))
;
Enjoy using!
License
This module is MIT licensed.