haply 1.1.0

Haply Robotics Client Library for the Inverse Service
Documentation
//! Shared SDF primitive shapes, easing types, and related enums.
//! Used by both the navigation module and the SDF HFX module.

use serde::{Deserialize, Serialize};
use ts_rs::TS;

use super::base_types::Linear3D;

// ============================================================
// SDF Primitive shapes
// ============================================================

/// An SDF shape definition: a primitive type with its parameters.
///
/// Serializes as `{ "primitive": "sphere", "parameters": { "r": 0.05 } }`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, TS)]
#[serde(tag = "primitive", content = "parameters", rename_all = "snake_case")]
pub enum SdfPrimitive {
    /// Sphere — `{ "r": radius }`
    Sphere { r: f32 },

    /// Axis-aligned box — `{ "b": half_extents_vec3 }`
    Box { b: Linear3D },

    /// Rounded box — `{ "b": half_extents, "r": corner_radius }`
    RoundedBox { b: Linear3D, r: f32 },

    /// Capsule between two endpoints — `{ "a": start, "b": end, "r": radius }`
    Capsule { a: Linear3D, b: Linear3D, r: f32 },

    /// Vertical capsule — `{ "h": height, "r": radius }`
    CapsuleVertical { h: f32, r: f32 },

    /// Capped cylinder between two axis endpoints — `{ "a": start, "b": end, "r": radius }`
    CappedCylinder { a: Linear3D, b: Linear3D, r: f32 },

    /// Vertical capped cylinder — `{ "h": height, "r": radius }`
    CappedCylinderVertical { h: f32, r: f32 },

    /// Infinite plane — `{ "n": normal_vec3, "h": offset }`
    Plane {
        #[serde(default)]
        n: Option<Linear3D>,
        h: f32,
    },

    /// Ellipsoid — `{ "a": semi_axes_vec3 }`
    Ellipsoid { a: Linear3D },
}

// ============================================================
// Easing types
// ============================================================

/// Easing curve type — used by navigation velocity mapping and SDF force ramps.
#[derive(Copy, Clone, Debug, PartialEq, Default, Deserialize, Serialize, TS)]
#[serde(rename_all = "snake_case")]
pub enum EasingType {
    #[default]
    Linear,
    QuadraticIn,
    QuadraticOut,
    QuadraticInOut,
    CubicIn,
    CubicOut,
    CubicInOut,
    QuinticIn,
    QuinticOut,
    QuinticInOut,
    SineOut,
}

// ============================================================
// Symmetry modes (SDF HFX)
// ============================================================

/// Controls how SDF forces behave relative to the surface.
#[derive(Copy, Clone, Debug, PartialEq, Default, Deserialize, Serialize, TS)]
#[serde(rename_all = "snake_case")]
pub enum SymmetryMode {
    /// Force only on one side (default).
    #[default]
    Single,
    /// Symmetric with opposite direction.
    Mirror,
    /// Symmetric with same direction.
    Align,
}

// ============================================================
// Center modes (Navigation)
// ============================================================

/// Controls how the navigation bubble center tracks the cursor.
#[derive(Copy, Clone, Debug, PartialEq, Default, Deserialize, Serialize, TS)]
#[serde(rename_all = "snake_case")]
pub enum CenterMode {
    /// Center drifts toward cursor at `center_drift_speed` (default).
    #[default]
    AutoFollow,
    /// Center never moves.
    Fixed,
    /// Center snaps to cursor each tick.
    TrackCursor,
}