Skip to content

wrap()

wrap(delta, count): number

Defined in: math/wrap.ts:29

Continuous depth of a card, wrapped into [-1, count - 1).

Depth 0 is the front card. Depth -1 is the off-screen exit slot. The range starts at -1 rather than 0 so a card just past the front reads as a small negative number and slides out, instead of teleporting to the back.

For count === 1 the range [-1, count - 1) collapses to [-1, 0), which excludes 0 and would park the only card off-screen at every delta. That matches the legacy library’s special case: a stack of one always shows its single card at depth 0 and never moves.

Near the wrap seam, delta + 1 can be a tiny negative number, and the d += count correction below can round up to exactly count in floating point, which would put the result at count - 1, outside the documented range. The trailing d -= count guard corrects that.

number

cardIndex - position

number

number of cards in the ring

number

import { wrap } from '@rpxl/riffle'
// card index 2, position 0.4, 5 cards in the ring
const depth = wrap(2 - 0.4, 5)