use glam::Vec3;
#[inline(always)]
pub fn modifier_bend(point: Vec3, curvature: f32) -> Vec3 {
let (s, c) = alice_det_math::sin_cos(curvature * point.x);
Vec3::new(
c * point.x + -(s * point.y),
s * point.x + (c * point.y),
point.z,
)
}
#[inline(always)]
pub fn modifier_bend_x(point: Vec3, curvature: f32) -> Vec3 {
let (s, c) = alice_det_math::sin_cos(curvature * point.y);
Vec3::new(
c * point.x + -(s * point.z),
point.y,
s * point.x + (c * point.z),
)
}
#[inline(always)]
pub fn modifier_bend_z(point: Vec3, curvature: f32) -> Vec3 {
let (s, c) = alice_det_math::sin_cos(curvature * point.y);
Vec3::new(
point.x,
c * point.y + -(s * point.z),
s * point.y + (c * point.z),
)
}
#[inline(always)]
pub fn modifier_bend_cheap(point: Vec3, curvature: f32) -> Vec3 {
let bend = curvature * point.y * point.y;
Vec3::new(point.x + bend, point.y, point.z)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bend_zero() {
let p = Vec3::new(1.0, 2.0, 3.0);
let r = modifier_bend(p, 0.0);
assert!((r - p).length() < 1e-6);
}
#[test]
fn test_bend_at_origin() {
let point = Vec3::new(0.0, 1.0, 0.0);
let result = modifier_bend(point, 1.0);
assert!((result.x - 0.0).abs() < 0.0001);
}
#[test]
fn test_bend_cheap() {
let point = Vec3::new(0.0, 2.0, 0.0);
let result = modifier_bend_cheap(point, 0.5);
assert!((result.x - 2.0).abs() < 0.0001);
assert!((result.y - 2.0).abs() < 0.0001);
}
}