Skip to content

Commit

Permalink
feat: move f32lerp into it's own package
Browse files Browse the repository at this point in the history
  • Loading branch information
nixon-voxell committed Jun 10, 2024
1 parent 70b8680 commit 0bd7e91
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 63 deletions.
14 changes: 11 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ license.workspace = true
repository.workspace = true

[dependencies]
motiongfx_f32lerp = { version = "0.1.0", path = "crates/motiongfx_f32lerp" }
motiongfx_core = { version = "0.1.0", path = "crates/motiongfx_core" }
motiongfx_vello = { version = "0.1.0", path = "crates/motiongfx_vello", optional = true }

[features]
default = ["vello"]
vello = ["dep:motiongfx_vello"]
default = ["vello_graphics"]
vello_graphics = ["dep:motiongfx_vello", "motiongfx_f32lerp/vello_graphics"]

[dev-dependencies]
bevy = "0.13"
Expand Down
11 changes: 2 additions & 9 deletions crates/motiongfx_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ license.workspace = true
repository.workspace = true

[dependencies]
motiongfx_core_macros = { path = "macros" }
motiongfx_core_macros = { version = "0.1.0", path = "macros" }
motiongfx_f32lerp = { version = "0.1.0", path = "../motiongfx_f32lerp" }

bevy = "0.13"
bevy_vello = { version = "0.4", optional = true }
bevy_vello_graphics = { version = "0.1.0", git = "https://github.com/voxell-tech/bevy_vello_graphics", optional = true }
smallvec = "1.11"

[lints]
workspace = true

[features]
default = ["vello_graphics"]
vello_graphics = ["dep:bevy_vello_graphics", "vello"]
vello = ["dep:bevy_vello"]
2 changes: 1 addition & 1 deletion crates/motiongfx_core/src/action.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bevy::prelude::*;
use motiongfx_f32lerp::F32Lerp;

use crate::{
ease::{cubic, EaseFn},
f32lerp::F32Lerp,
prelude::MultiSequenceOrdering,
sequence::Sequence,
};
Expand Down
24 changes: 0 additions & 24 deletions crates/motiongfx_core/src/f32lerp/bevy_f32lerp.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/motiongfx_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub use bevy_vello_graphics;
pub mod action;
pub mod color_palette;
pub mod ease;
pub mod f32lerp;
pub mod motion;
pub mod sequence;
pub mod slide;
Expand All @@ -21,7 +20,6 @@ pub mod prelude {
action::{act, Action, SequenceBuilderExt},
color_palette::{ColorKey, ColorPalette},
ease,
f32lerp::F32Lerp,
motion::{
standard_material_motion::StandardMaterialMotion, transform_motion::TransformMotion,
AddNewAssetCommandExtension, GetId, GetMut, GetMutValue,
Expand Down
20 changes: 20 additions & 0 deletions crates/motiongfx_f32lerp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "motiongfx_f32lerp"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
bevy = { version = "0.13", default-features = false, optional = true }
bevy_vello = { version = "0.4", optional = true }
bevy_vello_graphics = { version = "0.1.0", git = "https://github.com/voxell-tech/bevy_vello_graphics", optional = true }

[lints]
workspace = true

[features]
default = ["bevy"]
bevy = ["dep:bevy"]
vello = ["dep:bevy_vello", "bevy"]
vello_graphics = ["dep:bevy_vello_graphics", "vello"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
use bevy::math::{prelude::*, DQuat, DVec2, DVec3, DVec4};
use bevy::{
math::{DQuat, DVec2, DVec3, DVec4},
prelude::*,
};

use super::F32Lerp;
use crate::F32Lerp;

impl F32Lerp for f32 {
#[inline]
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
f32::lerp(*self, *rhs, t)
}
}

impl F32Lerp for f64 {
#[inline]
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
f64::lerp(*self, *rhs, t as f64)
}
}

impl F32Lerp for Vec2 {
#[inline]
Expand Down Expand Up @@ -57,3 +74,24 @@ impl F32Lerp for DQuat {
DQuat::lerp(*self, *rhs, t as f64)
}
}

impl F32Lerp for Transform {
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
Self {
translation: Vec3::f32lerp(&self.translation, &rhs.translation, t),
rotation: Quat::f32lerp(&self.rotation, &rhs.rotation, t),
scale: Vec3::f32lerp(&self.scale, &rhs.scale, t),
}
}
}

impl F32Lerp for Color {
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
Self::rgba(
f32::lerp(self.r(), rhs.r(), t),
f32::lerp(self.g(), rhs.g(), t),
f32::lerp(self.b(), rhs.b(), t),
f32::lerp(self.a(), rhs.a(), t),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use bevy::prelude::*;

#[cfg(feature = "bevy")]
pub mod bevy_f32lerp;
pub mod glam_f32lerp;
#[cfg(feature = "vello")]
pub mod vello_f32lerp;
#[cfg(feature = "vello_graphics")]
Expand All @@ -12,20 +10,6 @@ pub trait F32Lerp<T = Self, U = Self> {
fn f32lerp(&self, rhs: &T, t: f32) -> U;
}

impl F32Lerp for f32 {
#[inline]
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
f32::lerp(*self, *rhs, t)
}
}

impl F32Lerp for f64 {
#[inline]
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
f64::lerp(*self, *rhs, t as f64)
}
}

impl F32Lerp for u8 {
fn f32lerp(&self, rhs: &Self, t: f32) -> Self {
let other = *rhs as f32;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, utils::smallvec};
use bevy_vello::prelude::*;

use super::F32Lerp;
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
//! A [`Sequence`] is made up of multiple [`Action`]s. You can think of it as a group of actions. A [`Sequence`] also defines the order of [`Action`]s through the use of [action ordering functions](motiongfx_core::sequence).
pub use motiongfx_core;
#[cfg(feature = "vello")]
pub use motiongfx_f32lerp;
#[cfg(feature = "vello_graphics")]
pub use motiongfx_vello;

pub mod prelude {
pub use motiongfx_core::prelude::*;
#[cfg(feature = "vello")]
pub use motiongfx_f32lerp::F32Lerp;
#[cfg(feature = "vello_graphics")]
pub use motiongfx_vello::prelude::*;
}

0 comments on commit 0bd7e91

Please sign in to comment.