Compare commits

...

47 Commits

Author SHA1 Message Date
35881a8122 fix no_std 2024-01-05 15:50:26 +01:00
Dimitri Sabadie
f6fa4ecbce
Merge pull request #102 from phaazon/release/4.3.1
Prepare v4.3.1.
2023-11-22 19:13:05 +01:00
Dimitri Sabadie
e2f220ec15
Prepare v4.3.1. 2023-11-22 19:10:19 +01:00
Dimitri Sabadie
c3670d6b0a
Merge pull request #100 from perlindgren/master
Default for Spline
2023-11-22 00:09:57 +01:00
Per Lindgren
c6ba8476f2 Default for Spline 2023-10-27 21:20:24 +02:00
Dimitri Sabadie
389f4d182d
Update changelog (links). 2023-09-23 16:25:54 +02:00
Dimitri Sabadie
8af9151dac
Changelog fix. 2023-09-23 16:10:14 +02:00
Dimitri Sabadie
a82cf85619
Merge pull request #99 from phaazon/release/v4.3.0
Prepare v4.3.0.
2023-09-23 15:57:48 +02:00
Dimitri Sabadie
37d3cc5f29
Prepare v4.3.0. 2023-09-23 15:54:10 +02:00
Dimitri Sabadie
1e70ab882c
Rustfmt. 2023-09-23 15:40:58 +02:00
Dimitri Sabadie
2179c8300f
Merge pull request #98 from EmbarkStudios/master
Add `clear` method to `Spline`
2023-09-23 15:40:26 +02:00
Dimitri Sabadie
e7a9723ae0
Fix rustfmt. 2023-09-23 13:01:18 +02:00
Gray Olson
eca09f1baf add clear method to Spline 2023-09-13 15:52:43 +02:00
Dimitri Sabadie
e1b78070c6
Merge pull request #97 from phaazon/dependabot/cargo/master/glam-gte-0.10-and-lt-0.25
Update glam requirement from >=0.10, <0.23 to >=0.10, <0.25
2023-05-30 10:27:54 +02:00
dependabot[bot]
cdc48a49a7
Update glam requirement from >=0.10, <0.23 to >=0.10, <0.25
Updates the requirements on [glam](https://github.com/bitshifter/glam-rs) to permit the latest version.
- [Release notes](https://github.com/bitshifter/glam-rs/releases)
- [Changelog](https://github.com/bitshifter/glam-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitshifter/glam-rs/compare/0.10.0...0.24.0)

---
updated-dependencies:
- dependency-name: glam
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-24 04:59:27 +00:00
Dimitri Sabadie
decd85dba2
Merge pull request #95 from phaazon/update-deps
Bump dependencies (cgmath, nalgebra) to latest.
2023-02-01 19:41:51 +01:00
Dimitri Sabadie
df9815a464
Add deprecation lints if using impl-* feature gates. 2023-02-01 19:29:31 +01:00
Dimitri Sabadie
ca8e797932
Prepare version 4.2.0. 2023-02-01 19:19:45 +01:00
Dimitri Sabadie
5b746aaf57
Bump dependencies (cgmath, nalgebra) to latest. 2023-02-01 19:12:11 +01:00
Dimitri Sabadie
88a7ee7a8d
Merge pull request #91 from timethy/patch-1
Update CHANGELOG.md
2022-07-27 16:29:24 +02:00
Tim
5463fd11d6
Update CHANGELOG.md
Small typo
2022-07-27 09:22:51 +02:00
Dimitri Sabadie
d9770ad60b
Merge pull request #90 from phaazon/release/4.1.1
Release/4.1.1
2022-07-27 00:49:00 +02:00
Dimitri Sabadie
3dfea81856 Update changelog. 2022-07-27 00:42:42 +02:00
Dimitri Sabadie
604dcc6e27 Increment version number. 2022-07-27 00:42:30 +02:00
Dimitri Sabadie
8c952ae242
Merge pull request #86 from hokwangchoi/master
Fix cubic_hermite interpolation
2022-07-27 00:42:23 +02:00
Dimitri Sabadie
b52643b5d7
Merge pull request #85 from phaazon/dependabot/cargo/master/nalgebra-gte-0.21-and-lt-0.32
Update nalgebra requirement from >=0.21, <0.31 to >=0.21, <0.32
2022-07-27 00:41:30 +02:00
dependabot[bot]
dc6ef0a5cc
Update nalgebra requirement from >=0.21, <0.31 to >=0.21, <0.32
Updates the requirements on [nalgebra](https://github.com/dimforge/nalgebra) to permit the latest version.
- [Release notes](https://github.com/dimforge/nalgebra/releases)
- [Changelog](https://github.com/dimforge/nalgebra/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/dimforge/nalgebra/compare/v0.21.0...v0.31.0)

---
updated-dependencies:
- dependency-name: nalgebra
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-26 22:10:25 +00:00
Dimitri Sabadie
043a8608c3
Merge pull request #88 from phaazon/dependabot/cargo/master/glam-gte-0.10-and-lt-0.22
Update glam requirement from >=0.10, <0.21 to >=0.10, <0.22
2022-07-27 00:09:22 +02:00
Dimitri Sabadie
295043e5af rustfmt 2022-07-27 00:08:26 +02:00
Dimitri Sabadie
1c249215c9
Merge pull request #89 from timethy/interpolation-made-fast
Interpolation made fast
2022-07-27 00:02:17 +02:00
Tim Taubner
5a7e74d79c Binary Search to achieve promised logarithmic running time for sample (instead of linear!)
(cherry picked from commit ffcf289f713d5d92a74038ffa2fb6059d9995175)
2022-06-23 16:58:30 +02:00
dependabot[bot]
2012105a72
Update glam requirement from >=0.10, <0.21 to >=0.10, <0.22
Updates the requirements on [glam](https://github.com/bitshifter/glam-rs) to permit the latest version.
- [Release notes](https://github.com/bitshifter/glam-rs/releases)
- [Changelog](https://github.com/bitshifter/glam-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitshifter/glam-rs/compare/0.10.0...0.21.1)

---
updated-dependencies:
- dependency-name: glam
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-23 07:31:20 +00:00
Hokwang Choi
f25ebb2c64 remove unfinished test 2022-06-07 12:50:18 -04:00
Hokwang Choi
e9c1de389f scale tangent 2022-06-07 12:47:17 -04:00
Hokwang Choi
bdeaefd9f9 fix cubic_hermite coefficients & powers 2022-06-07 12:01:25 -04:00
Dimitri Sabadie
ace0f4ec50
Merge pull request #84 from phaazon/release/4.1
4.1.0.
2022-03-28 11:43:48 +02:00
Dimitri Sabadie
b056a4e9a7
4.1.0. 2022-03-28 11:38:25 +02:00
Dimitri Sabadie
042253ab9c
Merge pull request #83 from phaazon/nalgebra-update
Bump nalgebra dependency.
2022-03-25 09:14:31 +01:00
Dimitri Sabadie
270f225394
Bump nalgebra dependency. 2022-03-24 17:09:20 +01:00
Dimitri Sabadie
138828e798
Merge pull request #79 from phaazon/dependabot/cargo/master/glam-gte-0.10-and-lt-0.21
Update glam requirement from >=0.10, <0.18 to >=0.10, <0.21
2022-03-22 20:34:31 +01:00
Dimitri Sabadie
0ca1c5aa48
Merge pull request #75 from phaazon/dependabot/cargo/master/float-cmp-gte-0.6-and-lt-0.10
Update float-cmp requirement from >=0.6, < 0.9 to >=0.6, < 0.10
2022-03-22 20:33:36 +01:00
Dimitri Sabadie
f4c8be33b9
Merge pull request #82 from phaazon/edition-2021
Edition 2021
2022-03-22 20:20:01 +01:00
Dimitri Sabadie
26bd5c88eb
Update and simplify the CI. 2022-03-22 16:15:39 +01:00
Dimitri Sabadie
a4cd49fd20
Switch to edition 2021. 2022-03-22 16:14:28 +01:00
dependabot[bot]
09bc7069b2
Update glam requirement from >=0.10, <0.18 to >=0.10, <0.21
Updates the requirements on [glam](https://github.com/bitshifter/glam-rs) to permit the latest version.
- [Release notes](https://github.com/bitshifter/glam-rs/releases)
- [Changelog](https://github.com/bitshifter/glam-rs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bitshifter/glam-rs/compare/0.10.0...0.20.0)

---
updated-dependencies:
- dependency-name: glam
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-02 04:13:32 +00:00
dependabot[bot]
8dc8606bf0
Update float-cmp requirement from >=0.6, < 0.9 to >=0.6, < 0.10
Updates the requirements on [float-cmp](https://github.com/mikedilger/float-cmp) to permit the latest version.
- [Release notes](https://github.com/mikedilger/float-cmp/releases)
- [Commits](https://github.com/mikedilger/float-cmp/commits)

---
updated-dependencies:
- dependency-name: float-cmp
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-22 04:19:29 +00:00
Dimitri Sabadie
fc2f53200f
Fix previous commit (new implementors). 2021-07-11 17:46:59 +02:00
9 changed files with 143 additions and 99 deletions

View File

@ -6,38 +6,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: |
cargo build --verbose --all-features
- name: Test
run: |
cargo test --verbose --all-features
run: cargo test --verbose --all-features
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: |
cargo build --verbose --all-features
- name: Test
run: |
cargo test --verbose --all-features
run: cargo test --verbose --all-features
build-macosx:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Rust requirements
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
- name: Build
run: |
. ~/.cargo/env
cargo build --verbose --all-features
- name: Test
run: |
. ~/.cargo/env
cargo test --verbose --all-features
run: cargo test --verbose --all-features
quality:
runs-on: ubuntu-latest

View File

@ -1,7 +1,11 @@
# Changelog
<!-- vim-markdown-toc GFM -->
* [4.3.1](#431)
* [4.3](#43)
* [4.2](#42)
* [4.1.1](#411)
* [4.1](#41)
* [4.0.3](#403)
* [4.0.2](#402)
* [4.0.1](#401)
* [4.0](#40)
@ -39,13 +43,60 @@
* [0.1.1](#011)
* [0.1](#01)
<!-- vim-markdown-toc -->
# 4.3.1
> Nov 22, 2023
- Add `Default` implementation for `Spline`. [c6ba847](https://github.com/phaazon/splines/commit/c6ba847)
# 4.3
> Sep 23, 2023
- Add support for `glam-0.23` and `glam-0.24`. [cdc48a4](https://github.com/phaazon/splines/commit/cdc48a4)
- Add `Spline::clear` to clear a spline keys without deallocating its internal storage. [eca09f1](https://github.com/phaazon/splines/commit/eca09f1)
# 4.2
> Feb 1, 2023
- Add support for `glam-0.22`.
- Add support for `nalgebra-0.32`.
- Add deprecation lints for `impl-*` feature gates. Those shouldnt be used anymore and the `*` variant should be
preferred. For instance, if you used `impl-cgmath`, you should just use the `cgmath` feature gate now.
# 4.1.1
> Jul 27, 2022
- Internal enhancement of sampling splines by looking for control points. That brings the lookup from _O(N)_ to
_O(log(N))_. That is super embarassing because it should have been the default from the very first commit. Sorry
about that.
- Fix hermite cubic interpolation.
- Add support for `glam-0.21`.
- Add support for `nalgebra-0.31`.
# 4.1
> Mar 28, 2022
- Support for edition 2021.
- Bump `float-cmp` dependency.
- Bump `glam` dependency.
- Bump `nalgebra` dependency.
- Simplify the CI.
# 4.0.3
> Jul 11, 2021
- Add more implementors for `Interpolate`.
# 4.0.2
> Jul 11, 2021
- Add more implementors for `Interpolate`.
- **Yanked.**
# 4.0.1

View File

@ -1,6 +1,6 @@
[package]
name = "splines"
version = "4.0.2"
version = "4.3.1"
license = "BSD-3-Clause"
authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"]
description = "Spline interpolation made easy"
@ -11,13 +11,7 @@ repository = "https://github.com/phaazon/splines"
documentation = "https://docs.rs/splines"
readme = "README.md"
edition = "2018"
[badges]
travis-ci = { repository = "phaazon/splines", branch = "master" }
is-it-maintained-issue-resolution = { repository = "phaazon/splines" }
is-it-maintained-open-issues = { repository = "phaazon/splines" }
maintenance = { status = "actively-developed" }
edition = "2021"
[features]
default = ["std"]
@ -25,20 +19,20 @@ impl-cgmath = ["cgmath"]
impl-glam = ["glam"]
impl-nalgebra = ["nalgebra"]
serialization = ["serde"]
std = []
std = ["nalgebra/std"]
[dependencies]
cgmath = { version = ">=0.17, <0.19", optional = true }
glam = { version = ">=0.10, <0.18", optional = true }
nalgebra = { version = ">=0.21, <0.28", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
glam = { version = ">=0.10, <0.25", optional = true }
nalgebra = { version = ">=0.21, <0.33", default-features = false, optional = true }
serde = { version = "1", features = ["derive"], optional = true }
[dev-dependencies]
float-cmp = ">=0.6, < 0.9"
float-cmp = ">=0.6, < 0.10"
serde_json = "1"
[package.metadata.docs.rs]
all-features = true
features = ["std", "cgmath", "glam", "nalgebra", "serde"]
[[example]]
name = "hello-world"

View File

@ -1,6 +1,6 @@
edition = "2018"
fn_args_layout = "Tall"
fn_params_layout = "Tall"
force_explicit_abi = true
hard_tabs = false
max_width = 100

View File

@ -1,4 +1,4 @@
use crate::{impl_Interpolate, impl_InterpolateT!};
use crate::impl_Interpolate;
use cgmath::{Quaternion, Vector1, Vector2, Vector3, Vector4};
@ -13,10 +13,3 @@ impl_Interpolate!(f64, Vector2<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector3<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector4<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Quaternion<f64>, std::f64::consts::PI);
impl_InterpolateT!(f64, Vector1<f32>, std::f32::consts::PI);
impl_InterpolateT!(f64, Vector2<f32>, std::f32::consts::PI);
impl_InterpolateT!(f64, Vector3<f32>, std::f32::consts::PI);
impl_InterpolateT!(f64, Vector4<f32>, std::f32::consts::PI);
impl_InterpolateT!(f64, Quaternion<f32>, std::f32::consts::PI);

View File

@ -112,10 +112,15 @@ macro_rules! impl_Interpolate {
}
}
#[cfg(feature = "std")]
fn cosine(t: $t, a: Self, b: Self) -> Self {
let cos_nt = (1. - (t * $pi).cos()) * 0.5;
<Self as $crate::interpolate::Interpolate<$t>>::lerp(cos_nt, a, b)
}
#[cfg(not(feature = "std"))]
fn cosine(t: $t, a: Self, b: Self) -> Self {
unimplemented!();
}
fn lerp(t: $t, a: Self, b: Self) -> Self {
a * (1. - t) + b * t
@ -127,15 +132,16 @@ macro_rules! impl_Interpolate {
let three_t = t * 3.;
let t2 = t * t;
let t3 = t2 * t;
let two_t3 = t3 * two_t;
let three_t2 = t2 * three_t;
let two_t3 = t2 * two_t;
let two_t2 = t * two_t;
let three_t2 = t * three_t;
// tangents
let m0 = (b.1 - x.1) / (b.0 - x.0);
let m1 = (y.1 - a.1) / (y.0 - a.0);
let m0 = (b.1 - x.1) / (b.0 - x.0) * (b.0 - a.0);
let m1 = (y.1 - a.1) / (y.0 - a.0) * (b.0 - a.0);
a.1 * (two_t3 - three_t2 + 1.)
+ m0 * (t3 - t2 * two_t + t)
+ m0 * (t3 - two_t2 + t)
+ b.1 * (three_t2 - two_t3)
+ m1 * (t3 - t2)
}
@ -175,10 +181,15 @@ macro_rules! impl_InterpolateT {
}
}
#[cfg(feature = "std")]
fn cosine(t: $t, a: Self, b: Self) -> Self {
let cos_nt = (1. - (t * $pi).cos()) * 0.5;
<Self as $crate::interpolate::Interpolate<$t>>::lerp(cos_nt, a, b)
}
#[cfg(not(feature = "std"))]
fn cosine(t: $t, a: Self, b: Self) -> Self {
unimplemented!()
}
fn lerp(t: $t, a: Self, b: Self) -> Self {
let t = Self::from(t);
@ -192,15 +203,16 @@ macro_rules! impl_InterpolateT {
let three_t = t * 3.;
let t2 = t * t;
let t3 = t2 * t;
let two_t3 = t3 * two_t;
let three_t2 = t2 * three_t;
let two_t3 = t2 * two_t;
let two_t2 = t * two_t;
let three_t2 = t * three_t;
// tangents
let m0 = (b.1 - x.1) / (Self::from(b.0 - x.0));
let m1 = (y.1 - a.1) / (Self::from(y.0 - a.0));
let m0 = (b.1 - x.1) / (Self::from(b.0 - x.0)) * (Self::from(b.0 - a.0));
let m1 = (y.1 - a.1) / (Self::from(y.0 - a.0)) * (Self::from(b.0 - a.0));
a.1 * (two_t3 - three_t2 + 1.)
+ m0 * (t3 - t2 * two_t + t)
+ m0 * (t3 - two_t2 + t)
+ b.1 * (three_t2 - two_t3)
+ m1 * (t3 - t2)
}
@ -230,6 +242,6 @@ macro_rules! impl_InterpolateT {
};
}
impl_Interpolate!(f32, f32, std::f32::consts::PI);
impl_Interpolate!(f64, f64, std::f64::consts::PI);
impl_InterpolateT!(f32, f64, std::f32::consts::PI);
impl_Interpolate!(f32, f32, f32::consts::PI);
impl_Interpolate!(f64, f64, f64::consts::PI);
impl_InterpolateT!(f32, f64, f32::consts::PI);

View File

@ -108,6 +108,17 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]
#![cfg_attr(
any(
feature = "impl-cgmath",
feature = "impl-glam",
feature = "impl-nalgebra"
),
deprecated(
since = "4.2.0",
note = "you are using an impl-* feature gate; please switch to * (e.g. impl-cgmath becomes cgmath)"
)
)]
#[cfg(not(feature = "std"))]
extern crate alloc;

View File

@ -1,18 +1,27 @@
#[cfg(not(feature = "std"))]
use core::f32;
#[cfg(not(feature = "std"))]
use core::f64;
#[cfg(feature = "std")]
use std::f32;
#[cfg(feature = "std")]
use std::f64;
use crate::impl_Interpolate;
use nalgebra::{Quaternion, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6};
impl_Interpolate!(f32, Vector1<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Vector2<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Vector3<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Vector4<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Vector5<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Vector6<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Quaternion<f32>, std::f32::consts::PI);
impl_Interpolate!(f32, Vector1<f32>, f32::consts::PI);
impl_Interpolate!(f32, Vector2<f32>, f32::consts::PI);
impl_Interpolate!(f32, Vector3<f32>, f32::consts::PI);
impl_Interpolate!(f32, Vector4<f32>, f32::consts::PI);
impl_Interpolate!(f32, Vector5<f32>, f32::consts::PI);
impl_Interpolate!(f32, Vector6<f32>, f32::consts::PI);
impl_Interpolate!(f32, Quaternion<f32>, f32::consts::PI);
impl_Interpolate!(f64, Vector1<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector2<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector3<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector4<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector5<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector6<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Quaternion<f64>, std::f64::consts::PI);
impl_Interpolate!(f64, Vector1<f64>, f64::consts::PI);
impl_Interpolate!(f64, Vector2<f64>, f64::consts::PI);
impl_Interpolate!(f64, Vector3<f64>, f64::consts::PI);
impl_Interpolate!(f64, Vector4<f64>, f64::consts::PI);
impl_Interpolate!(f64, Vector5<f64>, f64::consts::PI);
impl_Interpolate!(f64, Vector6<f64>, f64::consts::PI);
impl_Interpolate!(f64, Quaternion<f64>, f64::consts::PI);

View File

@ -1,6 +1,6 @@
//! Spline curves and operations.
#[cfg(feature = "std")]
// #[cfg(feature = "std")]
use crate::interpolate::{Interpolate, Interpolator};
use crate::interpolation::Interpolation;
use crate::key::Key;
@ -27,7 +27,7 @@ use std::cmp::Ordering;
/// for the required interpolation mode, you get `None`.
/// - [`Spline::clamped_sample`]: behaves like [`Spline::sample`] but will return either the first
/// or last key if out of bound; it will return `None` if not enough key.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
#[cfg_attr(
any(feature = "serialization", feature = "serde"),
derive(Deserialize, Serialize)
@ -56,6 +56,13 @@ impl<T, V> Spline<T, V> {
spline
}
/// Clear the spline by removing all keys. Keeps the underlying allocated storage, so adding
/// new keys should be faster than creating a new [`Spline`]
#[inline]
pub fn clear(&mut self) {
self.0.clear()
}
/// Create a new spline by consuming an `Iterater<Item = Key<T>>`. They keys dont have to be
/// sorted.
///
@ -318,37 +325,20 @@ pub struct KeyMut<'a, T, V> {
}
// Find the lower control point corresponding to a given time.
// It has the property to have a timestamp smaller or equal to t
fn search_lower_cp<T, V>(cps: &[Key<T, V>], t: T) -> Option<usize>
where
T: PartialOrd,
{
let mut i = 0;
let len = cps.len();
if len < 2 {
return None;
}
loop {
let cp = &cps[i];
let cp1 = &cps[i + 1];
if t >= cp1.t {
if i >= len - 2 {
return None;
}
i += 1;
} else if t < cp.t {
if i == 0 {
return None;
}
i -= 1;
} else {
break; // found
}
match cps.binary_search_by(|key| key.t.partial_cmp(&t).unwrap()) {
Err(i) if i >= len => None,
Err(i) if i == 0 => None,
Err(i) => Some(i - 1),
Ok(i) if i == len - 1 => None,
Ok(i) => Some(i),
}
Some(i)
}