Finding wall point

Started by
22 comments, last by P0jahn 10 years, 5 months ago

Hmm ok then, they are all integers then. So get rid of the floats.

It also says there are 8 cases to consider as well.

However, as mentioned above this is only for the first octant. This means there are eight possible cases to consider. The simplest way to extend the same algorithm, if implemented in hardware, is to flip the co-ordinate system on the input and output of the single-octant drawer.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement

The error from the line is still using floats .


What operation in the original code produces something that is not an integer?

If you read the code which was originally posted you would have see the use of floats and not have asked.

I am rather confused. Are you saying that the code mutated? The code in the first post (which doesn't seem to have been altered) uses the type `float' but none of the operations can possibly result in a value that doesn't represent an integer. If you disagree with this, please explain what operation produces something that is not an integer.


public static boolean solidSpace (int x0, int y0, int x1, int y1)
{
     float dx = Math.abs(x1-x0);
     float dy = Math.abs(y1-y0); 

     float err = dx-dy;

     while (true)
     {

          float e2 = 2*err;
          if (e2 > -dy)
          {
               err -= dy;

          }
          if (e2 < dx)
          {
               err += dx;
          }
     }
}

The code above is from the original post with only the parts relating to floating point numbers left. Subtracting 2 integers does result in an integer but the result is then placed into a floating point number which will get converted into a floating point number.

Rereading what you have said, you asked what in the original code does not use floats and I have shown which parts of the code does use floating points. I think what you meant that floating points are not needed as all the maths involved can be represented with integer maths.

Also, why are you using `float' at all? All your numbers are integers...


This is the comment that started the whole argument between us. I stand by that comment. If you don't know what "integer" means (it's a notion in Math, not programming), you might have misunderstood.

Using all integers works fine, no floats required. But it did not increase the speed of the function at all. Mather fact, the function is actually fast, taking about 10000-15000 ns to complete.

I thought it was lagging but the issue was not in that function. Thanks for all the help anyway!

This topic is closed to new replies.

Advertisement