// pls add the possibility to add/sub rects to others,
// to get a new desired rect quickly
Code: Select all
//! add rectangles
template <class T>
irr::core::rect<T> operator+ (const irr::core::rect<T>& rThis, const irr::core::rect<T>& rOther)
{
irr::core::rect<T> result(rThis);
result.UpperLeftCorner.X += rOther.UpperLeftCorner.X;
result.UpperLeftCorner.Y += rOther.UpperLeftCorner.Y;
result.LowerRightCorner.X += rOther.LowerRightCorner.X;
result.LowerRightCorner.Y += rOther.LowerRightCorner.Y;
return result;
}
Code: Select all
//! sub rectangles
template <class T>
irr::core::rect<T> operator- (const irr::core::rect<T>& rThis, const irr::core::rect<T>& rOther)
{
irr::core::rect<T> result(rThis);
result.UpperLeftCorner.X -= rOther.UpperLeftCorner.X;
result.UpperLeftCorner.Y -= rOther.UpperLeftCorner.Y;
result.LowerRightCorner.X -= rOther.LowerRightCorner.X;
result.LowerRightCorner.Y -= rOther.LowerRightCorner.Y;
return result;
}
// USAGE: if you have a rect AbsoluteRect, like in IGUIElement
// and you like to have a new rect that fits in AbsoluteRect
// but 2 pixels border on each side just add rect(2,2,-2,-2)
//
// Example:
Code: Select all
irr::core::recti NewRect = AbsoluteRect + irr::core::recti(2,2,-2,-2);
Code: Select all
//! compares size of rectangles
bool operator<(const rect<T>& other) const
{
return getArea() < other.getArea();
}
// This behaviour does not make any sense for most cases,
// because it does not compare absolute coords,
// pls change behaviour! if you like to compare Areas, just do
// what the function does getArea() < other.getArea(), but
// pls dont waste operators for such simple, never needed behaviour.
// REPLACEMENTS:
Code: Select all
//! compares coords of rectangles
template <class T>
bool operator< (const irr::core::rect<T>& rThis, const irr::core::rect<T>& rOther)
{
return (
(rThis.UpperLeftCorner.X<rOther.UpperLeftCorner.X) &&
(rThis.UpperLeftCorner.Y<rOther.UpperLeftCorner.Y) &&
(rThis.LowerRightCorner.X<rOther.LowerRightCorner.X) &&
(rThis.LowerRightCorner.Y<rOther.LowerRightCorner.Y));
}
//! compares coords of rectangles
template <class T>
bool operator> (const irr::core::rect<T>& rThis, const irr::core::rect<T>& rOther)
{
return (
(rThis.UpperLeftCorner.X>rOther.UpperLeftCorner.X) &&
(rThis.UpperLeftCorner.Y>rOther.UpperLeftCorner.Y) &&
(rThis.LowerRightCorner.X>rOther.LowerRightCorner.X) &&
(rThis.LowerRightCorner.Y>rOther.LowerRightCorner.Y));
}
template <class T>
bool operator<= (const irr::core::rect<T>& rThis, const irr::core::rect<T>& rOther)
{
return (
(rThis.UpperLeftCorner.X<=rOther.UpperLeftCorner.X) &&
(rThis.UpperLeftCorner.Y<=rOther.UpperLeftCorner.Y) &&
(rThis.LowerRightCorner.X<=rOther.LowerRightCorner.X) &&
(rThis.LowerRightCorner.Y<=rOther.LowerRightCorner.Y));
}
//! compares coords of rectangles
template <class T>
bool operator>= (const irr::core::rect<T>& rThis, const irr::core::rect<T>& rOther)
{
return (
(rThis.UpperLeftCorner.X>=rOther.UpperLeftCorner.X) &&
(rThis.UpperLeftCorner.Y>=rOther.UpperLeftCorner.Y) &&
(rThis.LowerRightCorner.X>=rOther.LowerRightCorner.X) &&
(rThis.LowerRightCorner.Y>=rOther.LowerRightCorner.Y));
}