cubic_spline
Interpolation methods for computation of cubic spline points within the range of a discrete set of known points.
Example
use ;
let points = vec!;
let opts = new
.num_of_segments
.take;
let pts: = new;
let mut result = new;
pts.calc;
assert_eq!;
//
// Same as:
//
use ;
let spline_points = from_tuples;
assert_eq!;
For now source and resulting points may be Vec<f64> - (vec![x,y,x,y,...])
or Vec<(f64, f64)> - (vec![(x,y),(x,y), ...])
.
For this types of points there are two helper functions Spline::from_flatten_points
and Spline::from_tuples
Custom points
If you allready have some points to avoid unnecessary copying, creating new Vec
etc. you can implement GetPoint
trait. And if you need some particular result implement PushPoint
.
Example
use ;
;
;
let points: = vec!;
let pts = MySrcPoints;
let mut result = MyResult;
pts.calc;
See here for implementation example
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 |
invert_x_with_width | Option<u32> |
None |
If set to Some(canvas_width) generated points will be inverted by X-axis. |
invert_y_with_height | Option<u32> |
None |
If set to Some(canvas_height) generated points will be inverted by Y-axis. |
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 opts = SplineOpts ;
// or use builder
let opts2 = new
.num_of_segments
.invert_y_with_height
.take;
Enjoy using!
License
This module is MIT licensed.