src/features/periodic.c file

Functions

static auto box_positive(const vector3 box) -> bool
True when every axis length is finite and positive.
static auto delta_axis(const vm_float_t a, const vm_float_t b, const vm_float_t length) -> vm_float_t
One axis of a - b, in [-L/2, L/2].
static auto wrap_axis(const vm_float_t v, const vm_float_t length) -> vm_float_t
Fold one coordinate into [0, L), with ±0 and L stored as +0.
auto vm_periodic_delta_ortho(vector3* res, const vector3* a, const vector3* b, vector3 box, int n) -> bool
Minimum image of a - b on an orthorhombic box.
auto vm_wrap_ortho(vector3* x, vector3 box, int n) -> bool
Fold each position into [0, L) in place.

Function documentation

bool vm_periodic_delta_ortho(vector3* res, const vector3* a, const vector3* b, vector3 box, int n)

Minimum image of a - b on an orthorhombic box.

Parameters
res Output images; length n. May exactly alias a or b.
a First positions; length n.
b Second positions; length n.
box Positive finite axis lengths.
n
Returns false on a structural error.

Each axis is remainder(a - b, L) and lies in [-L/2, L/2]. L/2 and 3L/2 may select opposite images of equal length. A whole-box translation at an exact tie need not keep the same sign. res may exactly alias a or b.

Returns false, and writes nothing, when n < 0, a box length is not finite and positive, or n > 0 and a pointer is missing. n == 0 with a valid box returns true and does not read the arrays. A nonfinite coordinate is not a physical input; that axis becomes NaN.

Away from an image boundary, and for |coordinate/L| at most 2^20 in f32 or 2^40 in f64, the absolute error is at most 16 eps × max(L, |a|, |b|).

bool vm_wrap_ortho(vector3* x, vector3 box, int n)

Fold each position into [0, L) in place.

Parameters
x
box Positive finite axis lengths.
n
Returns false on a structural error.

Uses VECMAT_REMAINDER, then shifts a negative image up by L. A result that lands on L, and a signed zero, are stored as +0.

Returns false, and writes nothing, when n < 0, a box length is not finite and positive, or n > 0 and x is missing. n == 0 with a valid box returns true and does not read x. A nonfinite coordinate becomes NaN.