Home » Developing U++ » U++ Developers corner » Rect::Union() question
Rect::Union() question [message #61726] |
Thu, 03 July 2025 22:33 |
Didier
Messages: 736 Registered: November 2008 Location: France
|
Contributor |
|
|
Hello,
While going through Upp::Rect code searching for the right methods to use to calculate a bounding box, I stumbled on some intriguing code:
two same methods : one fully template and the same template method specialized for <double>: nothing special ... except that I don't understand why one does 'p.x + 1' and the other one doesn't.
I see no valid reason to put the '+1' here : If I use 'float' instead of 'double' i will have a +1 applied even if my values are in the [0 ,0.1] range
So I think they're may be an error here or at least with 'float'
Cor/Gtypes.h
template <class T>
void Rect_<T>::Union(Pt p) {
if(IsNull(p)) return;
if(IsNullInstance()) {
right = 1 + (left = p.x);
bottom = 1 + (top = p.y);
}
else
{
if(p.x >= right) right = p.x +1;
else if(p.x < left) left = p.x;
if(p.y >= bottom) bottom = p.y +1;
else if(p.y < top) top = p.y;
}
}
template <>
inline void Rect_<double>::Union(Point_<double> p) {
if(IsNull(p)) return;
if(IsNullInstance())
{
left = right = p.x;
top = bottom = p.y;
}
else
{
if(p.x < left) left = p.x;
else if(p.x > right) right = p.x;
if(p.y < top) top = p.y;
else if(p.y > bottom) bottom = p.y;
}
}
|
|
|
Goto Forum:
Current Time: Tue Jul 08 00:33:18 CEST 2025
Total time taken to generate the page: 0.03016 seconds
|