Skip to main content

Crate helix_noise

Crate helix_noise 

Source
Expand description

§Helix Noise

A divergence-free helical (Beltrami) spectral flow-field noise. The field is an analytic sum of divergence-free helical modes, so it can be evaluated grid-free at any point in space and time and its curl (vorticity) and vector potential come out in closed form. Handy for curl-noise particle advection, smoke and fluid-looking motion, procedural vector textures, and GPU flow shaders.

This crate is a port of the JavaScript helix-noise library with numerical parity: the deterministic mulberry32 mode-construction stream is bit-identical, so a field built with the same options and seed reproduces the reference values to floating-point tolerance.

The crate has zero runtime dependencies and no threads or I/O in the hot path, so it compiles cleanly to WebAssembly.

§Quickstart

use helix_noise::{HelixField, HelixOptions};

let field = HelixField::new(HelixOptions { seed: 42, modes: 48, ..Default::default() });

// Velocity at a point.
let u = field.sample(1.0, 2.0, 3.0);

// Velocity animated in time.
let u_t = field.sample_t(1.0, 2.0, 3.0, 0.5);

// Velocity + vorticity in one pass.
let (u, w) = field.sample_uw(1.0, 2.0, 3.0, 0.0);

§Custom spectrum

use helix_noise::{HelixField, HelixOptions};
let field = HelixField::new(HelixOptions {
    spectrum: Some(Box::new(|k: f64| (-k).exp())),
    ..Default::default()
});

§Obstacles (free-slip boundary)

use helix_noise::{HelixField, HelixOptions, BoundaryOptions};
let field = HelixField::new(HelixOptions::default());
let bounded = field.with_boundary(
    |x: f64, y: f64, z: f64| ((x - 3.0).powi(2) + (y - 3.0).powi(2) + (z - 3.0).powi(2)).sqrt() - 1.2,
    BoundaryOptions { thickness: 0.9, ..Default::default() },
);
let u = bounded.sample(2.0, 2.0, 2.0, 0.0);

§Scope

Covers both engines — the spectral HelixField and the sparse-atom HelixAtoms — plus the free-slip SDF boundary (which wraps either) and the GLSL/shader emitter. The atom-engine GLSL emitter of the JS reference is a documented follow-up and not yet ported.

Structs§

AtomOptions
Options for constructing a HelixAtoms field.
BoundaryOptions
Options for HelixField::with_boundary.
BoundedField
A base flow field constrained by an SDF obstacle. Borrows the base field, which may be either engine (anything implementing VectorPotential).
GlslOptions
Options for HelixField::glsl.
HelixAtoms
The sparse-atom engine. See the module docs.
HelixField
A divergence-free helical flow field, evaluatable grid-free as an analytic sum of Beltrami modes. Construct via HelixField::new or HelixField::create.
HelixOptions
Options for constructing a crate::HelixField.
ModeSnapshot
A read-only snapshot of a field’s built per-mode spectral arrays. See HelixField::mode_snapshot.
Mulberry32
A mulberry32 generator. Call Mulberry32::next_f64 to draw the next uniform in [0, 1).

Enums§

Layout
Mode layout strategy.

Constants§

TAU
2*pi.
VERSION
Library version string, mirroring the reference package.

Traits§

VectorPotential
A divergence-free flow field that exposes its exact vector potential A — the one requirement for the free-slip boundary wrapper. Implemented by both engines (HelixField and HelixAtoms), so any field can be wrapped with an obstacle.

Functions§

ga
Golden angle in radians — the Fibonacci-sphere azimuth increment.

Type Aliases§

ScalarField3
A spatially-varying scalar field (x, y, z) -> value, sampled once at each atom’s center.
SpectrumFn
A user-supplied spectral amplitude law |k| -> amplitude.