use glam::Vec3;
#[inline(always)]
pub fn modifier_bend(point: Vec3, curvature: f32) -> Vec3 {
let (s, c) = (curvature * point.x).sin_cos();
Vec3::new(
c.mul_add(point.x, -(s * point.y)),
s.mul_add(point.x, c * point.y),
point.z,
)
}
#[inline(always)]
pub fn modifier_bend_x(point: Vec3, curvature: f32) -> Vec3 {
let (s, c) = (curvature * point.y).sin_cos();
Vec3::new(
c.mul_add(point.x, -(s * point.z)),
point.y,
s.mul_add(point.x, c * point.z),
)
}
#[inline(always)]
pub fn modifier_bend_z(point: Vec3, curvature: f32) -> Vec3 {
let (s, c) = (curvature * point.y).sin_cos();
Vec3::new(
point.x,
c.mul_add(point.y, -(s * point.z)),
s.mul_add(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);
}
}