Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
3cd65dce54 | |||
11791bed70 | |||
820839abc0 | |||
865c855ac5 |
14
CHANGELOG.md
14
CHANGELOG.md
@ -1,3 +1,17 @@
|
|||||||
|
# 0.2.1
|
||||||
|
|
||||||
|
> Thu 20th September 2018
|
||||||
|
|
||||||
|
- Enhance the features documentation.
|
||||||
|
|
||||||
|
# 0.2
|
||||||
|
|
||||||
|
> Thu 6th September 2018
|
||||||
|
|
||||||
|
- Add the `"std"` feature gate, that can be used to compile with the standard library.
|
||||||
|
- Add the `"impl-cgmath"` in order to make it optional, if wanted, the `cgmath` dependency.
|
||||||
|
- Enhance the documentation.
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
|
||||||
> Wed 8th August 2018
|
> Wed 8th August 2018
|
||||||
|
10
Cargo.toml
10
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "splines"
|
name = "splines"
|
||||||
version = "0.1.1"
|
version = "0.2.1"
|
||||||
license = "BSD-3-Clause"
|
license = "BSD-3-Clause"
|
||||||
authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"]
|
authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"]
|
||||||
description = "Spline interpolation made easy"
|
description = "Spline interpolation made easy"
|
||||||
@ -18,12 +18,14 @@ is-it-maintained-open-issues = { repository = "phaazon/splines" }
|
|||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std", "impl-cgmath"]
|
||||||
serialization = ["serde", "serde_derive"]
|
serialization = ["serde", "serde_derive"]
|
||||||
std = []
|
std = []
|
||||||
|
impl-cgmath = ["cgmath"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies.cgmath]
|
||||||
cgmath = "0.16"
|
version = "0.16"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[dependencies.serde]
|
[dependencies.serde]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
@ -12,7 +12,10 @@ This crate has features! Here’s a comprehensive list of what you can enable:
|
|||||||
- **Serialization / deserialization.**
|
- **Serialization / deserialization.**
|
||||||
+ This feature implements both the `Serialize` and `Deserialize` traits from `serde`.
|
+ This feature implements both the `Serialize` and `Deserialize` traits from `serde`.
|
||||||
+ Enable with the `"serialization"` feature.
|
+ Enable with the `"serialization"` feature.
|
||||||
- **Standard library / no stdandard library**
|
- **[cgmath](https://crates.io/crates/cgmath) implementors**
|
||||||
|
+ Adds some usefull implementations of `Interpolate` for some cgmath types.
|
||||||
|
+ Enable with the `"impl-cgmath"` feature.
|
||||||
|
- **Standard library / no stdandard library.**
|
||||||
+ It’s possible to compile against the standard library or go on your own without it.
|
+ 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.
|
+ Compiling with the standard library is enabled by default.
|
||||||
+ Use `defaut-features = []` in your `Cargo.toml` to disable.
|
+ Use `defaut-features = []` in your `Cargo.toml` to disable.
|
||||||
|
30
src/lib.rs
30
src/lib.rs
@ -77,9 +77,13 @@
|
|||||||
//! So here’s a list of currently supported features and how to enable them:
|
//! So here’s a list of currently supported features and how to enable them:
|
||||||
//!
|
//!
|
||||||
//! - **Serialization / deserialization.**
|
//! - **Serialization / deserialization.**
|
||||||
//! + This feature implements both the `Serialize` and `Deserialize` traits from `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 `"serialization"` feature.
|
||||||
//! - **Standard library / no stdandard library**
|
//! - **[cgmath](https://crates.io/crates/cgmath) implementors.**
|
||||||
|
//! + Adds some usefull implementations of `Interpolate` for some cgmath types.
|
||||||
|
//! + Enable with the `"impl-cgmath"` feature.
|
||||||
|
//! - **Standard library / no stdandard library.**
|
||||||
//! + It’s possible to compile against the standard library or go on your own without it.
|
//! + 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.
|
//! + Compiling with the standard library is enabled by default.
|
||||||
//! + Use `defaut-features = []` in your `Cargo.toml` to disable.
|
//! + Use `defaut-features = []` in your `Cargo.toml` to disable.
|
||||||
@ -87,16 +91,17 @@
|
|||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
#![cfg_attr(not(feature = "std"), feature(alloc))]
|
||||||
|
#![cfg_attr(not(feature = "std"), feature(core_intrinsics))]
|
||||||
|
|
||||||
// on no_std, we also need the alloc crate for Vec
|
// on no_std, we also need the alloc crate for Vec
|
||||||
#[cfg(not(feature = "std"))] extern crate alloc;
|
#[cfg(not(feature = "std"))] extern crate alloc;
|
||||||
|
|
||||||
extern crate cgmath;
|
#[cfg(feature = "impl-cgmath")] extern crate cgmath;
|
||||||
|
|
||||||
#[cfg(feature = "serialization")] extern crate serde;
|
#[cfg(feature = "serialization")] extern crate serde;
|
||||||
#[cfg(feature = "serialization")] #[macro_use] extern crate serde_derive;
|
#[cfg(feature = "serialization")] #[macro_use] extern crate serde_derive;
|
||||||
|
|
||||||
use cgmath::{InnerSpace, Quaternion, Vector2, Vector3, Vector4};
|
#[cfg(feature = "impl-cgmath")] use cgmath::{InnerSpace, Quaternion, Vector2, Vector3, Vector4};
|
||||||
|
|
||||||
#[cfg(feature = "std")] use std::cmp::Ordering;
|
#[cfg(feature = "std")] use std::cmp::Ordering;
|
||||||
#[cfg(feature = "std")] use std::f32::consts;
|
#[cfg(feature = "std")] use std::f32::consts;
|
||||||
@ -227,7 +232,18 @@ impl<T> Spline<T> {
|
|||||||
Interpolation::Cosine => {
|
Interpolation::Cosine => {
|
||||||
let cp1 = &keys[i+1];
|
let cp1 = &keys[i+1];
|
||||||
let nt = normalize_time(t, cp0, cp1);
|
let nt = normalize_time(t, cp0, cp1);
|
||||||
let cos_nt = (1. - f32::cos(nt * consts::PI)) * 0.5;
|
let cos_nt = {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
{
|
||||||
|
(1. - f32::cos(nt * consts::PI)) * 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
{
|
||||||
|
use core::intrinsics::cosf32;
|
||||||
|
unsafe { (1. - cosf32(nt * consts::PI)) * 0.5 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Some(Interpolate::lerp(cp0.value, cp1.value, cos_nt))
|
Some(Interpolate::lerp(cp0.value, cp1.value, cos_nt))
|
||||||
},
|
},
|
||||||
@ -329,6 +345,7 @@ impl Interpolate for f32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "impl-cgmath")]
|
||||||
impl Interpolate for Vector2<f32> {
|
impl Interpolate for Vector2<f32> {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
a.lerp(b, t)
|
a.lerp(b, t)
|
||||||
@ -339,6 +356,7 @@ impl Interpolate for Vector2<f32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "impl-cgmath")]
|
||||||
impl Interpolate for Vector3<f32> {
|
impl Interpolate for Vector3<f32> {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
a.lerp(b, t)
|
a.lerp(b, t)
|
||||||
@ -349,6 +367,7 @@ impl Interpolate for Vector3<f32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "impl-cgmath")]
|
||||||
impl Interpolate for Vector4<f32> {
|
impl Interpolate for Vector4<f32> {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
a.lerp(b, t)
|
a.lerp(b, t)
|
||||||
@ -359,6 +378,7 @@ impl Interpolate for Vector4<f32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "impl-cgmath")]
|
||||||
impl Interpolate for Quaternion<f32> {
|
impl Interpolate for Quaternion<f32> {
|
||||||
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
fn lerp(a: Self, b: Self, t: f32) -> Self {
|
||||||
a.nlerp(b, t)
|
a.nlerp(b, t)
|
||||||
|
Reference in New Issue
Block a user