wovo / hwlib

C++ OO micro-controller library for close-to-the-hardware programming
Boost Software License 1.0
57 stars 26 forks source link

If statements that always result to false #4

Closed ManDeJan closed 3 years ago

ManDeJan commented 7 years ago

link to code

      uint_fast16_t Dx = x1 - x0; 
      uint_fast16_t Dy = y1 - y0;

      uint_fast16_t steep = (abs(Dy) >= abs(Dx));

      if( steep ){
         swap( x0, y0 );
         swap( x1, y1 );

         // recompute Dx, Dy after swap
         Dx = x1 - x0;
         Dy = y1 - y0;
      }

      uint_fast16_t xstep = 1;
      if( Dx < 0 ){
         xstep = -1;
         Dx = -Dx;
      }

      uint_fast16_t ystep = 1;
      if( Dy < 0 ){
         ystep = -1;    
         Dy = -Dy; 
      }

First you declare Dx and Dy to be an unsigned integer, then you check if they're smaller than 0. This is always false and does nothing.

wovo commented 3 years ago

Dx and Dy were changed to signed,