Major problems with rect<T>?
Posted: Sun Oct 12, 2008 4:24 am
Perhaps I'm missing something really obvious here, (and it seems like something that would be immediately noticed), but it looks like rect<T> is broken for quite a few functions. For instance, try out this code:
You'll notice that the rectangle named invalidRect returns 0 for invalidRect->isValid(); the rectangle is perfectly valid, however, since a rectangle constructed with the upperLeft coordinate at (-1, 1) and the lowerRight coordinate at (1, -1) looks like this:
This isn't a perfect square, I realize, but you get the point
The problem is in rect.h, where isValid() tests if LowerRightCorner.X >= UpperLeftCorner.X (which is fine), but it's also testing for LowerRightCorner.Y >= UpperLeftCorner.Y. Why would we test if the lower y coordinate is greater than the upper y coordinate? :\
This problem is also found in several other fuctions.
The reason that the rectangle
is found to be valid is because in the constructor rect(const position2d<T>& pos, const dimension2d<T>& size), for the y coordinate it's adding the height and the y-coordinate of the position instead of subtracting it.
I'll provide a full patch later so that if this is truly a bug it can be fixed quickly
Thanks
-wyrmmage
Code: Select all
#include <iostream>
#include "irrlicht/irrlicht.h"
int main()
{
using namespace irr;
using namespace core;
rect<f32>* validRect = new rect<f32>(position2d<f32>(0, 0), dimension2d<f32>(2, 2)); //works
rect<f32>* invalidRect = new rect<f32>(position2d<f32>(-1, 1), position2d<f32>(1, -1)); //doesn't work
std::cout << "validRect: " << validRect->isValid() << "\n";
std::cout << "invalidRect: " << invalidRect->isValid() << "\n";
std::cout << "\n";
std::cout << "validWidth: " << validRect->getWidth() << ", validHeight: " << validRect->getHeight() << "\n";
std::cout << "invalidWidth: " << invalidRect->getWidth() << ", invalidHeight: " << invalidRect->getHeight() << "\n";
int tempInt;
std::cin >> tempInt;
return 1;
}
Code: Select all
(-1, 1)----------(1, 1)
| |
| |
| |
(-1, -1)---------(1, -1)
The problem is in rect.h, where isValid() tests if LowerRightCorner.X >= UpperLeftCorner.X (which is fine), but it's also testing for LowerRightCorner.Y >= UpperLeftCorner.Y. Why would we test if the lower y coordinate is greater than the upper y coordinate? :\
This problem is also found in several other fuctions.
The reason that the rectangle
Code: Select all
rect<f32>* validRect = new rect<f32>(position2d<f32>(0, 0), dimension2d<f32>(2, 2));
I'll provide a full patch later so that if this is truly a bug it can be fixed quickly
Thanks
-wyrmmage