nativeview-physics 0.1.0-rc.1

Zero-dependency, zero-allocation closed-form spring, decay, rubber-band, smooth-wheel, velocity, and easing solvers for Native View Engine.
Documentation
  • Coverage
  • 59.02%
    36 out of 61 items documented0 out of 0 items with examples
  • Size
  • Source code size: 103.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 937.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • nativeview/nativeview
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • samuelscheit

nativeview-physics

Zero-dependency, zero-allocation closed-form physics and timing-curve primitives shared across nativeview-layout, nativeview-motion, nativeview-ui, and pluggable scroll/animation engines.

Primitives

  • Springs (SpringSpec, SpringState): Unconditionally stable f64 closed-form damped harmonic oscillator covering under-damped, critically-damped, and over-damped regimes with velocity-preserving mid-flight retargeting.
  • Exponential Decay (DecaySpec, DecayState): Closed-form inertial deceleration, exact boundary hit-time intersection, projected resting distance, and inverse launch velocity for snap targeting.
  • Rubber-Band Resistance (RubberBandSpec): Apple-style asymptotic drag resistance with exact forward and inverse transforms.
  • Smooth Wheel (SmoothWheelSpec): Closed-form exponential smoothing for discrete wheel detents.
  • Velocity Tracking (VelocityTracker, VelocityTrackerConfig): Copy, zero-heap EMA gesture velocity estimator with pause reset and clamping.
  • Easing Curves (CubicBezier, StepPosition, EasingCurve): Bracketed Newton-Raphson / bisection CSS cubic-bezier, steps(), and spring step-response curves.

Example

use nativeview_physics::{
    CubicBezier, DecaySpec, EasingCurve, RubberBandSpec, SmoothWheelSpec, SpringSpec, SpringState,
    VelocityTracker, VelocityTrackerConfig,
};

let spec = SpringSpec::snappy();
let mut spring = SpringState::new(0.0, 100.0);
for _ in 0..300 {
    if spring.step(&spec, 1.0 / 60.0) {
        break;
    }
}
assert_eq!(spring.value, 100.0);

let decay = DecaySpec::apple();
let dist = decay.projected_distance(1200.0);
let v0 = decay.initial_velocity_for_distance(dist);
assert!((v0 - 1200.0).abs() < 1e-2);

let rb = RubberBandSpec::APPLE;
let vis = rb.forward(120.0, 400.0);
assert!((rb.inverse(vis, 400.0) - 120.0).abs() < 1e-3);

let (next_pos, _) = SmoothWheelSpec::apple().step(0.0, 120.0, 1.0 / 60.0);
assert!(next_pos > 0.0 && next_pos < 120.0);

let mut tracker = VelocityTracker::new(VelocityTrackerConfig::SCROLL);
tracker.record_dt(16.0, 16);
assert!((tracker.velocity() - 1000.0).abs() < 1e-2);

assert!((CubicBezier::EASE_IN_OUT.evaluate(0.5) - 0.5).abs() < 1e-4);
assert_eq!(EasingCurve::Linear.evaluate(0.25), 0.25);

Verification

cargo test --locked -p nativeview-physics
cargo bench --locked -p nativeview-physics --no-run