Skip to main content

Module cyclic

Module cyclic 

Source
Expand description

Cyclic-distance helpers for closed-loop line topologies. Cyclic-distance helpers for closed-loop topologies.

These helpers operate on positions along a one-dimensional axis that wraps modulo circumference. They are the foundation that LineKind::Loop consumers — movement physics, ETA math, headway clamping — build on.

All helpers treat any of the following as degenerate and return safe values (typically 0.0 or the input unchanged) rather than panicking or propagating NaN:

  • circumference <= 0.0
  • non-finite circumference (including NaN and ±∞)
  • non-finite position arguments

Construction-time validation is responsible for rejecting such configurations before they reach these helpers; the defensive returns exist so a misconfigured run degrades gracefully rather than producing NaN cascades through ETA / dispatch math.

Functions§

cyclic_distance
Shortest unsigned cyclic distance between a and b along a loop.
forward_distance
Forward (one-way) cyclic distance from from to to along a loop.
wrap_position
Normalize a position into [0, circumference).