Trying to map a 2d array into a disk

if the space wraps around by N=5, that is: only numbers 0,1,2,3,4 exist, then

if you pick the interval going from 4 across the boundary to 2 (interval A=4, B=2) then the number X=1 is within that interval <A,B>

but your X>A at the begining does not handle it

EDIT:

Hey actually you can make it quite simple:

bool a = A<=X;
bool b = X<=B;
return (a && b) || (A>B && (a || b));

where 0 <= A,B,X < M
A is the beggining of the interval, B is the end of the interval, M is the boundary (the modulo).

this is the number line when A<B:
0--------X1---------A=====X2=====B-------X3-------M
X2 is inside the interval

when A>B:
0=====X1=====B---------X2--------A====X3====M
X1 and X3 are in the interval

3 Likes