Skip to content

Commit

Permalink
Ver 0.37.6
Browse files Browse the repository at this point in the history
- More generic Spline
- Implement B-Spline
  • Loading branch information
Axect committed Jun 19, 2024
2 parents 7e4d525 + 220161c commit fd5127b
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "peroxide"
version = "0.37.5"
version = "0.37.6"
authors = ["axect <axect@outlook.kr>"]
edition = "2018"
description = "Rust comprehensive scientific computation library contains linear algebra, numerical analysis, statistics and machine learning tools with farmiliar syntax"
Expand Down
15 changes: 15 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Release 0.37.6 (2024-06-19)

## Huge Spline Change

- Generic Spline trait
- `Spline<T>`: desired output type is `T`
- Split `PolynomialSpline` from `Spline`
- `CubicSpline` & `CubicHermiteSpline` are now `PolynomialSpline`
- Implement `Spline<f64>` for `PolynomialSpline`
- Implement B-Spline
- `BSpline { degree: usize, knots: Vec<f64>, control_points: Vec<Vec<f64>> }`
- `BSpline::open(degree, knots, control_points)` : Open B-Spline
- `BSpline::clamped(degree, knots, control_points)` : Clamped B-Spline
- Implement `Spline<(f64, f64)>` for `BSpline`

# Release 0.37.5 (2024-06-10)

- More generic & stable root finding macros (except `Newton`)
Expand Down
Binary file added example_data/b_spline_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions examples/b_spline_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use peroxide::fuga::*;

fn main() -> Result<(), Box<dyn Error>> {
let knots = vec![0f64, 1f64, 2f64, 3f64];
let degree = 3;
let control_points = vec![
vec![0f64, 2f64],
vec![0.2, -1f64],
vec![0.4, 1f64],
vec![0.6, -1f64],
vec![0.8, 1f64],
vec![1f64, 2f64],
];


let spline = BSpline::clamped(degree, knots, control_points.clone())?;
let t = linspace(0f64, 3f64, 200);
let (x, y): (Vec<f64>, Vec<f64>) = spline.eval_vec(&t).into_iter().unzip();

#[cfg(feature = "plot")]
{
let control_x = control_points.iter().map(|v| v[0]).collect::<Vec<f64>>();
let control_y = control_points.iter().map(|v| v[1]).collect::<Vec<f64>>();

let mut plt = Plot2D::new();
plt
.insert_pair((x.clone(), y.clone()))
.insert_pair((control_x.clone(), control_y.clone()))
.set_plot_type(vec![(1, PlotType::Scatter)])
.set_color(vec![(0, "darkblue"), (1, "red")])
.set_xlabel(r"$x$")
.set_ylabel(r"$y$")
.set_style(PlotStyle::Nature)
.set_dpi(600)
.set_path("example_data/b_spline_test.png")
.savefig()?;
}

let mut df = DataFrame::new(vec![]);
df.push("t", Series::new(t));
df.push("x", Series::new(x));
df.push("y", Series::new(y));
df.print();

Ok(())
}
Loading

0 comments on commit fd5127b

Please sign in to comment.