Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Possible inconsistency with Rect::Contains() right-bottom bounds?
Possible inconsistency with Rect::Contains() right-bottom bounds? [message #53038] Sun, 16 February 2020 13:06 Go to next message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
Hello,

I've noticed that:

template <class T>
bool Rect_<T>::Contains(T x, T y) const {
	return x >= left && x < right && y >= top && y < bottom;
}                            ---                      ---
                              x                        x
template <>
inline bool Rect_<double>::Contains(double x, double y) const {
	return x >= left && x <= right && y >= top && y <= bottom;
}                             ---                       ---
                               ^                         ^

template <class T>
bool Rect_<T>::Contains(const Rect_<T>& r) const {
	return r.left >= left && r.top >= top && r.right <= right && r.bottom <= bottom;
}                                                        ---                 ---
                                                          ^                    ^



Best regards,
Obiivion


Re: Possible inconsistency with Rect::Contains() right-bottom bounds? [message #53040 is a reply to message #53038] Sun, 16 February 2020 19:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Oblivion wrote on Sun, 16 February 2020 13:06
Hello,

I've noticed that:

template <class T>
bool Rect_<T>::Contains(T x, T y) const {
	return x >= left && x < right && y >= top && y < bottom;
}                            ---                      ---
                              x                        x
template <>
inline bool Rect_<double>::Contains(double x, double y) const {
	return x >= left && x <= right && y >= top && y <= bottom;
}                             ---                       ---
                               ^                         ^

template <class T>
bool Rect_<T>::Contains(const Rect_<T>& r) const {
	return r.left >= left && r.top >= top && r.right <= right && r.bottom <= bottom;
}                                                        ---                 ---
                                                          ^                    ^



Best regards,
Obiivion


Thats intentional. It might be inconsistent, but for doubles it is better to include bottom-right corner into the rectangle.

Mirek
Re: Possible inconsistency with Rect::Contains() right-bottom bounds? [message #53041 is a reply to message #53040] Sun, 16 February 2020 20:20 Go to previous message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
OK, thanks for the clarification.

Best regards,
Oblivion


Previous Topic: Problem linking using RegExp
Next Topic: Vector& Vector::operator<<(T&& x) is missing
Goto Forum:
  


Current Time: Sat Apr 20 07:49:02 CEST 2024

Total time taken to generate the page: 0.03513 seconds