There must be a better way

Emp empty at nomail.com
Tue Aug 1 18:57:07 PDT 2006


I wrap two values (x && y coordinates) like this:

uint wrap(uint axis, int value)
{
 int max=0;
 if (axis==1) max=25;
 if (axis==0) max=10;
 if(value>=max){
  return (value % max);
 }
 if(value<0){
  int newValue;
  newValue=value;
  while(newValue<0){
   newValue+=max;
  }
  return (newValue);
 }
return value;
}

So I need to do things like 'wrap(0,currentX)' everytime to wrap the
currentX. Like:

(the original x && y need to be untouched)
array[wrap(0,currentX)][wrap(1,currentY)];

Is this really the best way, or am I just missing some nifty D
programming?

Two small questions:
1. Isn't inout more used than out for functions, in contrast to what the
website says?
    I use inout quite often, or am I just doing something wrong?

2. Is it really difficult to make '>=" correctly compare an unsigned and a
signed int?
    (This took me some time to find out :)

Grtz, Emp








More information about the Digitalmars-d-learn mailing list