use glam::{Vec2, Vec3};
use std::sync::Arc;
use super::SdfNode;
impl SdfNode {
#[must_use]
#[inline]
pub const fn sphere(radius: f32) -> Self {
Self::Sphere { radius }
}
#[must_use]
#[inline]
pub fn box3d(width: f32, height: f32, depth: f32) -> Self {
Self::Box3d {
half_extents: Vec3::new(width * 0.5, height * 0.5, depth * 0.5),
}
}
#[must_use]
#[inline]
pub const fn box3d_half_extents(hx: f32, hy: f32, hz: f32) -> Self {
Self::Box3d {
half_extents: Vec3::new(hx, hy, hz),
}
}
#[must_use]
#[inline]
pub fn cylinder(radius: f32, height: f32) -> Self {
Self::Cylinder {
radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub const fn torus(major_radius: f32, minor_radius: f32) -> Self {
Self::Torus {
major_radius,
minor_radius,
}
}
#[must_use]
#[inline]
pub fn plane(normal: Vec3, distance: f32) -> Self {
Self::Plane {
normal: normal.normalize(),
distance,
}
}
#[must_use]
#[inline]
pub const fn capsule(a: Vec3, b: Vec3, radius: f32) -> Self {
Self::Capsule {
point_a: a,
point_b: b,
radius,
}
}
#[must_use]
#[inline]
pub fn cone(radius: f32, height: f32) -> Self {
Self::Cone {
radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub const fn ellipsoid(rx: f32, ry: f32, rz: f32) -> Self {
Self::Ellipsoid {
radii: Vec3::new(rx, ry, rz),
}
}
#[must_use]
#[inline]
pub fn rounded_cone(r1: f32, r2: f32, height: f32) -> Self {
Self::RoundedCone {
r1,
r2,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn pyramid(height: f32) -> Self {
Self::Pyramid {
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub const fn octahedron(size: f32) -> Self {
Self::Octahedron { size }
}
#[must_use]
#[inline]
pub fn hex_prism(hex_radius: f32, height: f32) -> Self {
Self::HexPrism {
hex_radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn link(length: f32, r1: f32, r2: f32) -> Self {
Self::Link {
half_length: length * 0.5,
r1,
r2,
}
}
#[must_use]
#[inline]
pub const fn triangle(a: Vec3, b: Vec3, c: Vec3) -> Self {
Self::Triangle {
point_a: a,
point_b: b,
point_c: c,
}
}
#[must_use]
#[inline]
pub const fn bezier(a: Vec3, b: Vec3, c: Vec3, radius: f32) -> Self {
Self::Bezier {
point_a: a,
point_b: b,
point_c: c,
radius,
}
}
#[must_use]
#[inline]
pub const fn rounded_box(hx: f32, hy: f32, hz: f32, round_radius: f32) -> Self {
Self::RoundedBox {
half_extents: Vec3::new(hx, hy, hz),
round_radius,
}
}
#[must_use]
#[inline]
pub fn capped_cone(height: f32, r1: f32, r2: f32) -> Self {
Self::CappedCone {
half_height: height * 0.5,
r1,
r2,
}
}
#[must_use]
#[inline]
pub const fn capped_torus(major_radius: f32, minor_radius: f32, cap_angle: f32) -> Self {
Self::CappedTorus {
major_radius,
minor_radius,
cap_angle,
}
}
#[must_use]
#[inline]
pub fn rounded_cylinder(radius: f32, round_radius: f32, height: f32) -> Self {
Self::RoundedCylinder {
radius,
round_radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn triangular_prism(width: f32, depth: f32) -> Self {
Self::TriangularPrism {
width,
half_depth: depth * 0.5,
}
}
#[must_use]
#[inline]
pub const fn cut_sphere(radius: f32, cut_height: f32) -> Self {
Self::CutSphere { radius, cut_height }
}
#[must_use]
#[inline]
pub const fn cut_hollow_sphere(radius: f32, cut_height: f32, thickness: f32) -> Self {
Self::CutHollowSphere {
radius,
cut_height,
thickness,
}
}
#[must_use]
#[inline]
pub const fn death_star(ra: f32, rb: f32, d: f32) -> Self {
Self::DeathStar { ra, rb, d }
}
#[must_use]
#[inline]
pub const fn solid_angle(angle: f32, radius: f32) -> Self {
Self::SolidAngle { angle, radius }
}
#[must_use]
#[inline]
pub fn rhombus(la: f32, lb: f32, height: f32, round_radius: f32) -> Self {
Self::Rhombus {
la,
lb,
half_height: height * 0.5,
round_radius,
}
}
#[must_use]
#[inline]
pub fn horseshoe(angle: f32, radius: f32, length: f32, width: f32, thickness: f32) -> Self {
Self::Horseshoe {
angle,
radius,
half_length: length * 0.5,
width,
thickness,
}
}
#[must_use]
#[inline]
pub fn vesica(radius: f32, dist: f32) -> Self {
Self::Vesica {
radius,
half_dist: dist * 0.5,
}
}
#[must_use]
#[inline]
pub const fn infinite_cylinder(radius: f32) -> Self {
Self::InfiniteCylinder { radius }
}
#[must_use]
#[inline]
pub const fn infinite_cone(angle: f32) -> Self {
Self::InfiniteCone { angle }
}
#[must_use]
#[inline]
pub const fn gyroid(scale: f32, thickness: f32) -> Self {
Self::Gyroid { scale, thickness }
}
#[must_use]
#[inline]
pub const fn metric_ball(radius: f32, weights: alice_det_math::metric::MetricWeights) -> Self {
let (w_l1, w_l2, w_linf) = weights.weights();
Self::MetricBall {
radius,
w_l1,
w_l2,
w_linf,
}
}
#[must_use]
#[inline]
pub fn metric_blend(inner: Self, outer: Self, center: Vec3, radius: f32, skin: f32) -> Self {
Self::MetricBlend {
inner: Arc::new(inner),
outer: Arc::new(outer),
center,
radius,
skin,
}
}
#[must_use]
#[inline]
pub const fn heart(size: f32) -> Self {
Self::Heart { size }
}
#[must_use]
#[inline]
pub fn tube(outer_radius: f32, thickness: f32, height: f32) -> Self {
Self::Tube {
outer_radius,
thickness,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn barrel(radius: f32, height: f32, bulge: f32) -> Self {
Self::Barrel {
radius,
half_height: height * 0.5,
bulge,
}
}
#[must_use]
#[inline]
pub fn diamond(radius: f32, height: f32) -> Self {
Self::Diamond {
radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn chamfered_cube(width: f32, height: f32, depth: f32, chamfer: f32) -> Self {
Self::ChamferedCube {
half_extents: Vec3::new(width * 0.5, height * 0.5, depth * 0.5),
chamfer,
}
}
#[must_use]
#[inline]
pub const fn schwarz_p(scale: f32, thickness: f32) -> Self {
Self::SchwarzP { scale, thickness }
}
#[must_use]
#[inline]
pub fn superellipsoid(width: f32, height: f32, depth: f32, e1: f32, e2: f32) -> Self {
Self::Superellipsoid {
half_extents: Vec3::new(width * 0.5, height * 0.5, depth * 0.5),
e1,
e2,
}
}
#[must_use]
#[inline]
pub fn rounded_x(width: f32, round_radius: f32, height: f32) -> Self {
Self::RoundedX {
width,
round_radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn pie(angle: f32, radius: f32, height: f32) -> Self {
Self::Pie {
angle,
radius,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub fn trapezoid(r1: f32, r2: f32, trap_height: f32, depth: f32) -> Self {
Self::Trapezoid {
r1,
r2,
trap_height: trap_height * 0.5,
half_depth: depth * 0.5,
}
}
#[must_use]
#[inline]
pub fn parallelogram(width: f32, para_height: f32, skew: f32, depth: f32) -> Self {
Self::Parallelogram {
width,
para_height: para_height * 0.5,
skew,
half_depth: depth * 0.5,
}
}
#[must_use]
#[inline]
pub fn tunnel(width: f32, height_2d: f32, depth: f32) -> Self {
Self::Tunnel {
width,
height_2d,
half_depth: depth * 0.5,
}
}
#[must_use]
#[inline]
pub fn uneven_capsule(r1: f32, r2: f32, cap_height: f32, depth: f32) -> Self {
Self::UnevenCapsule {
r1,
r2,
cap_height: cap_height * 0.5,
half_depth: depth * 0.5,
}
}
#[must_use]
#[inline]
pub const fn egg(ra: f32, rb: f32) -> Self {
Self::Egg { ra, rb }
}
#[must_use]
pub fn arc_shape(aperture: f32, radius: f32, thickness: f32, height: f32) -> Self {
Self::ArcShape {
aperture,
radius,
thickness,
half_height: height * 0.5,
}
}
#[must_use]
pub fn moon(d: f32, ra: f32, rb: f32, height: f32) -> Self {
Self::Moon {
d,
ra,
rb,
half_height: height * 0.5,
}
}
#[must_use]
pub fn cross_shape(length: f32, thickness: f32, round_radius: f32, height: f32) -> Self {
Self::CrossShape {
length,
thickness,
round_radius,
half_height: height * 0.5,
}
}
#[must_use]
pub fn blobby_cross(size: f32, height: f32) -> Self {
Self::BlobbyCross {
size,
half_height: height * 0.5,
}
}
#[must_use]
pub fn parabola_segment(width: f32, para_height: f32, depth: f32) -> Self {
Self::ParabolaSegment {
width,
para_height,
half_depth: depth * 0.5,
}
}
#[must_use]
pub fn regular_polygon(radius: f32, n_sides: u32, height: f32) -> Self {
Self::RegularPolygon {
radius,
n_sides: n_sides as f32,
half_height: height * 0.5,
}
}
#[must_use]
pub fn star_polygon(radius: f32, n_points: u32, m: f32, height: f32) -> Self {
Self::StarPolygon {
radius,
n_points: n_points as f32,
m,
half_height: height * 0.5,
}
}
#[must_use]
pub fn stairs(step_width: f32, step_height: f32, n_steps: u32, depth: f32) -> Self {
Self::Stairs {
step_width,
step_height,
n_steps: n_steps as f32,
half_depth: depth * 0.5,
}
}
#[must_use]
pub fn helix(major_r: f32, minor_r: f32, pitch: f32, height: f32) -> Self {
Self::Helix {
major_r,
minor_r,
pitch,
half_height: height * 0.5,
}
}
#[must_use]
#[inline]
pub const fn tetrahedron(size: f32) -> Self {
Self::Tetrahedron { size }
}
#[must_use]
#[inline]
pub const fn dodecahedron(radius: f32) -> Self {
Self::Dodecahedron { radius }
}
#[must_use]
#[inline]
pub const fn icosahedron(radius: f32) -> Self {
Self::Icosahedron { radius }
}
#[must_use]
#[inline]
pub const fn truncated_octahedron(radius: f32) -> Self {
Self::TruncatedOctahedron { radius }
}
#[must_use]
#[inline]
pub const fn truncated_icosahedron(radius: f32) -> Self {
Self::TruncatedIcosahedron { radius }
}
#[must_use]
#[inline]
pub const fn box_frame(half_extents: Vec3, edge: f32) -> Self {
Self::BoxFrame { half_extents, edge }
}
#[must_use]
#[inline]
pub const fn diamond_surface(scale: f32, thickness: f32) -> Self {
Self::DiamondSurface { scale, thickness }
}
#[must_use]
#[inline]
pub const fn neovius(scale: f32, thickness: f32) -> Self {
Self::Neovius { scale, thickness }
}
#[must_use]
#[inline]
pub const fn lidinoid(scale: f32, thickness: f32) -> Self {
Self::Lidinoid { scale, thickness }
}
#[must_use]
#[inline]
pub const fn iwp(scale: f32, thickness: f32) -> Self {
Self::IWP { scale, thickness }
}
#[must_use]
#[inline]
pub const fn frd(scale: f32, thickness: f32) -> Self {
Self::FRD { scale, thickness }
}
#[must_use]
#[inline]
pub const fn fischer_koch_s(scale: f32, thickness: f32) -> Self {
Self::FischerKochS { scale, thickness }
}
#[must_use]
#[inline]
pub const fn pmy(scale: f32, thickness: f32) -> Self {
Self::PMY { scale, thickness }
}
#[must_use]
#[inline]
pub const fn circle_2d(radius: f32, half_height: f32) -> Self {
Self::Circle2D {
radius,
half_height,
}
}
#[must_use]
#[inline]
pub const fn rect_2d(half_w: f32, half_h: f32, half_height: f32) -> Self {
Self::Rect2D {
half_extents: Vec2::new(half_w, half_h),
half_height,
}
}
#[must_use]
#[inline]
pub const fn segment_2d(
ax: f32,
ay: f32,
bx: f32,
by: f32,
thickness: f32,
half_height: f32,
) -> Self {
Self::Segment2D {
a: Vec2::new(ax, ay),
b: Vec2::new(bx, by),
thickness,
half_height,
}
}
#[must_use]
#[inline]
pub const fn polygon_2d(vertices: Vec<Vec2>, half_height: f32) -> Self {
Self::Polygon2D {
vertices,
half_height,
}
}
#[must_use]
#[inline]
pub const fn rounded_rect_2d(
half_w: f32,
half_h: f32,
round_radius: f32,
half_height: f32,
) -> Self {
Self::RoundedRect2D {
half_extents: Vec2::new(half_w, half_h),
round_radius,
half_height,
}
}
#[must_use]
#[inline]
pub const fn annular_2d(outer_radius: f32, thickness: f32, half_height: f32) -> Self {
Self::Annular2D {
outer_radius,
thickness,
half_height,
}
}
}