include/vecmat/periodic.h file

Orthorhombic minimum image and wrap on vector3 arrays.

The box is axis-aligned. Lengths are in the same unit as the coordinates. The scalar reference is VECMAT_REMAINDER (remainder / remainderf), so the nearest integer uses ties-to-even. This is not a force kernel.

Functions

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.