Compare commits
	
		
			48 Commits
		
	
	
		
			4.0
			...
			EmbarkStud
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | da43539b70 | ||
|  | eca09f1baf | ||
|  | e1b78070c6 | ||
|  | cdc48a49a7 | ||
|  | decd85dba2 | ||
|  | df9815a464 | ||
|  | ca8e797932 | ||
|  | 5b746aaf57 | ||
|  | 88a7ee7a8d | ||
|  | 5463fd11d6 | ||
|  | d9770ad60b | ||
|  | 3dfea81856 | ||
|  | 604dcc6e27 | ||
|  | 8c952ae242 | ||
|  | b52643b5d7 | ||
|  | dc6ef0a5cc | ||
|  | 043a8608c3 | ||
|  | 295043e5af | ||
|  | 1c249215c9 | ||
|  | 5a7e74d79c | ||
|  | 2012105a72 | ||
|  | f25ebb2c64 | ||
|  | e9c1de389f | ||
|  | bdeaefd9f9 | ||
|  | ace0f4ec50 | ||
|  | b056a4e9a7 | ||
|  | 042253ab9c | ||
|  | 270f225394 | ||
|  | 138828e798 | ||
|  | 0ca1c5aa48 | ||
|  | f4c8be33b9 | ||
|  | 26bd5c88eb | ||
|  | a4cd49fd20 | ||
|  | 09bc7069b2 | ||
|  | 8dc8606bf0 | ||
|  | fc2f53200f | ||
|  | b3836975c3 | ||
|  | 322d271499 | ||
|  | e64298dc88 | ||
|  | 32e5122339 | ||
|  | 1be94935cf | ||
|  | 06f6e4b578 | ||
|  | 87e27e732d | ||
|  | fb678f9613 | ||
|  | ee4230340b | ||
|  | f585119883 | ||
|  | 25d5c5217e | ||
|  | 355178f5fa | 
| @@ -1,12 +0,0 @@ | ||||
| version: 1 | ||||
| update_configs: | ||||
|   - package_manager: "rust:cargo" | ||||
|     directory: "." | ||||
|     update_schedule: "live" | ||||
|     target_branch: "master" | ||||
|     default_reviewers: | ||||
|       - "phaazon" | ||||
|     default_assignees: | ||||
|       - "phaazon" | ||||
|     default_labels: | ||||
|       - "dependency-update" | ||||
							
								
								
									
										25
									
								
								.github/dependabot.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								.github/dependabot.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| version: 2 | ||||
| updates: | ||||
| - package-ecosystem: cargo | ||||
|   directory: "/." | ||||
|   schedule: | ||||
|     interval: daily | ||||
|     time: "04:00" | ||||
|   open-pull-requests-limit: 10 | ||||
|   target-branch: master | ||||
|   reviewers: | ||||
|   - phaazon | ||||
|   assignees: | ||||
|   - phaazon | ||||
|   labels: | ||||
|   - dependency-update | ||||
|   ignore: | ||||
|   - dependency-name: glam | ||||
|     versions: | ||||
|     - 0.13.0 | ||||
|   - dependency-name: nalgebra | ||||
|     versions: | ||||
|     - 0.25.0 | ||||
|   - dependency-name: cgmath | ||||
|     versions: | ||||
|     - 0.18.0 | ||||
							
								
								
									
										22
									
								
								.github/workflows/ci.yaml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										22
									
								
								.github/workflows/ci.yaml
									
									
									
									
										vendored
									
									
								
							| @@ -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 | ||||
|   | ||||
							
								
								
									
										62
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										62
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -1,7 +1,11 @@ | ||||
| # Changelog | ||||
|  | ||||
| <!-- vim-markdown-toc GFM --> | ||||
|  | ||||
| * [4.1.2](#412) | ||||
| * [4.1.1](#411) | ||||
| * [4.1](#41) | ||||
| * [4.0.3](#403) | ||||
| * [4.0.2](#402) | ||||
| * [4.0.1](#401) | ||||
| * [4.0](#40) | ||||
|   * [Major changes](#major-changes) | ||||
|   * [Patch changes](#patch-changes) | ||||
| @@ -37,7 +41,59 @@ | ||||
| * [0.1.1](#011) | ||||
| * [0.1](#01) | ||||
|  | ||||
| <!-- vim-markdown-toc --> | ||||
| # 4.2.0 | ||||
|  | ||||
| > Feb 1, 2023 | ||||
|  | ||||
| - Add support for `glam-0.22`. | ||||
| - Add support for `nalgebra-0.32`. | ||||
| - Add deprecation lints for `impl-*` feature gates. Those shouldn’t 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 | ||||
|  | ||||
| - **Yanked.** | ||||
|  | ||||
| # 4.0.1 | ||||
|  | ||||
| > Jul 11, 2021 | ||||
|  | ||||
| - Add support up to `glam-0.17`. | ||||
| - Add support up to `nalgebra-0.27`. | ||||
| - Replace the name of some feature gates: | ||||
|   - `serialization` becomes `serde`. | ||||
|   - `impl-*` becomes `*`. | ||||
|   - The previous feature gates are kept around to prevent a breaking change but will eventually be removed in the next | ||||
|     major update. | ||||
|  | ||||
| # 4.0 | ||||
|  | ||||
|   | ||||
							
								
								
									
										25
									
								
								Cargo.toml
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								Cargo.toml
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| [package] | ||||
| name = "splines" | ||||
| version = "4.0.0" | ||||
| version = "4.2.0" | ||||
| license = "BSD-3-Clause" | ||||
| authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"] | ||||
| description = "Spline interpolation made easy" | ||||
| @@ -11,39 +11,32 @@ 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"] | ||||
| impl-cgmath = ["cgmath"] | ||||
| impl-glam = ["glam"] | ||||
| impl-nalgebra = ["nalgebra"] | ||||
| serialization = ["serde", "serde_derive"] | ||||
| serialization = ["serde"] | ||||
| std = [] | ||||
|  | ||||
| [dependencies] | ||||
| cgmath = { version = ">=0.17, <0.19", optional = true } | ||||
| glam = { version = ">=0.10, <0.13", optional = true } | ||||
| nalgebra = { version = ">=0.21, <0.25", optional = true } | ||||
| serde =  { version = "1", optional = true } | ||||
| serde_derive = { version = "1", optional = true } | ||||
| glam = { version = ">=0.10, <0.25", optional = true } | ||||
| nalgebra = { version = ">=0.21, <0.33", 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" | ||||
|  | ||||
| [[example]] | ||||
| name = "serialization" | ||||
| required-features = ["serialization"] | ||||
| required-features = ["serde"] | ||||
|   | ||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							| @@ -83,19 +83,19 @@ not. It’s especially important to see how it copes with the documentation. | ||||
|  | ||||
| So here’s a list of currently supported features and how to enable them: | ||||
|  | ||||
|   - **Serialization / deserialization.** | ||||
|   - **Serde.** | ||||
|     - This feature implements both the `Serialize` and `Deserialize` traits from `serde` for all | ||||
|       types exported by this crate. | ||||
|     - Enable with the `"serialization"` feature. | ||||
|     - Enable with the `"serde"` feature. | ||||
|   - **[cgmath](https://crates.io/crates/cgmath) implementors.** | ||||
|     - Adds some useful implementations of `Interpolate` for some cgmath types. | ||||
|     - Enable with the `"impl-cgmath"` feature. | ||||
|     - Enable with the `"cgmath"` feature. | ||||
|   - **[glam](https://crates.io/crates/glam) implementors.** | ||||
|     - Adds some useful implementations of `Interpolate` for some glam types. | ||||
|     - Enable with the `"impl-glam"` feature. | ||||
|     - Enable with the `"glam"` feature. | ||||
|   - **[nalgebra](https://crates.io/crates/nalgebra) implementors.** | ||||
|     - Adds some useful implementations of `Interpolate` for some nalgebra types. | ||||
|     - Enable with the `"impl-nalgebra"` feature. | ||||
|     - Enable with the `"nalgebra"` feature. | ||||
|   - **Standard library / no standard library.** | ||||
|     - It’s possible to compile against the standard library or go on your own without it. | ||||
|     - Compiling with the standard library is enabled by default. | ||||
|   | ||||
| @@ -127,15 +127,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) | ||||
|       } | ||||
| @@ -163,5 +164,74 @@ macro_rules! impl_Interpolate { | ||||
|   }; | ||||
| } | ||||
|  | ||||
| #[macro_export] | ||||
| macro_rules! impl_InterpolateT { | ||||
|   ($t:ty, $v:ty, $pi:expr) => { | ||||
|     impl $crate::interpolate::Interpolate<$t> for $v { | ||||
|       fn step(t: $t, threshold: $t, a: Self, b: Self) -> Self { | ||||
|         if t < threshold { | ||||
|           a | ||||
|         } else { | ||||
|           b | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       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) | ||||
|       } | ||||
|  | ||||
|       fn lerp(t: $t, a: Self, b: Self) -> Self { | ||||
|         let t = Self::from(t); | ||||
|         a * (1. - t) + b * t | ||||
|       } | ||||
|  | ||||
|       fn cubic_hermite(t: $t, x: ($t, Self), a: ($t, Self), b: ($t, Self), y: ($t, Self)) -> Self { | ||||
|         // sampler stuff | ||||
|         let t = Self::from(t); | ||||
|         let two_t = t * 2.; | ||||
|         let three_t = t * 3.; | ||||
|         let t2 = t * t; | ||||
|         let t3 = t2 * 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)) * (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 - two_t2 + t) | ||||
|           + b.1 * (three_t2 - two_t3) | ||||
|           + m1 * (t3 - t2) | ||||
|       } | ||||
|  | ||||
|       fn quadratic_bezier(t: $t, a: Self, u: Self, b: Self) -> Self { | ||||
|         let t = Self::from(t); | ||||
|         let one_t = 1. - t; | ||||
|         let one_t2 = one_t * one_t; | ||||
|  | ||||
|         u + (a - u) * one_t2 + (b - u) * t * t | ||||
|       } | ||||
|  | ||||
|       fn cubic_bezier(t: $t, a: Self, u: Self, v: Self, b: Self) -> Self { | ||||
|         let t = Self::from(t); | ||||
|         let one_t = 1. - t; | ||||
|         let one_t2 = one_t * one_t; | ||||
|         let one_t3 = one_t2 * one_t; | ||||
|         let t2 = t * t; | ||||
|  | ||||
|         a * one_t3 + (u * one_t2 * t + v * one_t * t2) * 3. + b * t2 * t | ||||
|       } | ||||
|  | ||||
|       fn cubic_bezier_mirrored(t: $t, a: Self, u: Self, v: Self, b: Self) -> Self { | ||||
|         <Self as $crate::interpolate::Interpolate<$t>>::cubic_bezier(t, a, u, b + b - v, b) | ||||
|       } | ||||
|     } | ||||
|   }; | ||||
| } | ||||
|  | ||||
| impl_Interpolate!(f32, f32, std::f32::consts::PI); | ||||
| impl_Interpolate!(f64, f64, std::f64::consts::PI); | ||||
| impl_InterpolateT!(f32, f64, std::f32::consts::PI); | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| //! Available interpolation modes. | ||||
|  | ||||
| #[cfg(feature = "serialization")] | ||||
| use serde_derive::{Deserialize, Serialize}; | ||||
| #[cfg(any(feature = "serialization", feature = "serde"))] | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| /// Available kind of interpolations. | ||||
| /// | ||||
| @@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize}; | ||||
| #[non_exhaustive] | ||||
| #[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||||
| #[cfg_attr( | ||||
|   feature = "serialization", | ||||
|   any(feature = "serialization", feature = "serde"), | ||||
|   derive(Deserialize, Serialize), | ||||
|   serde(rename_all = "snake_case") | ||||
| )] | ||||
|   | ||||
| @@ -7,8 +7,8 @@ | ||||
| //! interpolation mode on a key-based way, allowing you to implement and encode complex curves. | ||||
|  | ||||
| use crate::interpolation::Interpolation; | ||||
| #[cfg(feature = "serialization")] | ||||
| use serde_derive::{Deserialize, Serialize}; | ||||
| #[cfg(any(feature = "serialization", feature = "serde"))] | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| /// A spline control point. | ||||
| /// | ||||
| @@ -19,7 +19,7 @@ use serde_derive::{Deserialize, Serialize}; | ||||
| /// [`Interpolation`]: crate::interpolation::Interpolation | ||||
| #[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||||
| #[cfg_attr( | ||||
|   feature = "serialization", | ||||
|   any(feature = "serialization", feature = "serde"), | ||||
|   derive(Deserialize, Serialize), | ||||
|   serde(rename_all = "snake_case") | ||||
| )] | ||||
|   | ||||
							
								
								
									
										27
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/lib.rs
									
									
									
									
									
								
							| @@ -84,19 +84,19 @@ | ||||
| //! | ||||
| //! So here’s a list of currently supported features and how to enable them: | ||||
| //! | ||||
| //!   - **Serialization / deserialization.** | ||||
| //!   - **Serde.** | ||||
| //!     - This feature implements both the `Serialize` and `Deserialize` traits from `serde` for all | ||||
| //!       types exported by this crate. | ||||
| //!     - Enable with the `"serialization"` feature. | ||||
| //!     - Enable with the `"serde"` feature. | ||||
| //!   - **[cgmath](https://crates.io/crates/cgmath) implementors.** | ||||
| //!     - Adds some useful implementations of `Interpolate` for some cgmath types. | ||||
| //!     - Enable with the `"impl-cgmath"` feature. | ||||
| //!     - Enable with the `"cgmath"` feature. | ||||
| //!   - **[glam](https://crates.io/crates/glam) implementors.** | ||||
| //!     - Adds some useful implementations of `Interpolate` for some glam types. | ||||
| //!     - Enable with the `"impl-glam"` feature. | ||||
| //!     - Enable with the `"glam"` feature. | ||||
| //!   - **[nalgebra](https://crates.io/crates/nalgebra) implementors.** | ||||
| //!     - Adds some useful implementations of `Interpolate` for some nalgebra types. | ||||
| //!     - Enable with the `"impl-nalgebra"` feature. | ||||
| //!     - Enable with the `"nalgebra"` feature. | ||||
| //!   - **Standard library / no standard library.** | ||||
| //!     - It’s possible to compile against the standard library or go on your own without it. | ||||
| //!     - Compiling with the standard library is enabled by default. | ||||
| @@ -108,19 +108,30 @@ | ||||
| #![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; | ||||
|  | ||||
| #[cfg(feature = "impl-cgmath")] | ||||
| #[cfg(any(feature = "impl-cgmath", feature = "cgmath"))] | ||||
| mod cgmath; | ||||
| #[cfg(feature = "impl-glam")] | ||||
| #[cfg(any(feature = "impl-glam", feature = "glam"))] | ||||
| mod glam; | ||||
| pub mod interpolate; | ||||
| pub mod interpolation; | ||||
| pub mod iter; | ||||
| pub mod key; | ||||
| #[cfg(feature = "impl-nalgebra")] | ||||
| #[cfg(any(feature = "impl-nalgebra", feature = "nalgebra"))] | ||||
| mod nalgebra; | ||||
| pub mod spline; | ||||
|  | ||||
|   | ||||
| @@ -10,8 +10,8 @@ use alloc::vec::Vec; | ||||
| use core::cmp::Ordering; | ||||
| #[cfg(not(feature = "std"))] | ||||
| use core::ops::{Div, Mul}; | ||||
| #[cfg(feature = "serialization")] | ||||
| use serde_derive::{Deserialize, Serialize}; | ||||
| #[cfg(any(feature = "serialization", feature = "serde"))] | ||||
| use serde::{Deserialize, Serialize}; | ||||
| #[cfg(feature = "std")] | ||||
| use std::cmp::Ordering; | ||||
|  | ||||
| @@ -28,7 +28,10 @@ use std::cmp::Ordering; | ||||
| ///   - [`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)] | ||||
| #[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))] | ||||
| #[cfg_attr( | ||||
|   any(feature = "serialization", feature = "serde"), | ||||
|   derive(Deserialize, Serialize) | ||||
| )] | ||||
| pub struct Spline<T, V>(pub(crate) Vec<Key<T, V>>); | ||||
|  | ||||
| impl<T, V> Spline<T, V> { | ||||
| @@ -53,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 don’t have to be | ||||
|   /// sorted. | ||||
|   /// | ||||
| @@ -315,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) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user