Bug #1017
closedWRectF: united returns wrong rectangles
0%
Description
Hello!
As I understand, united() should return minimal rectangle, including all points of both rectangles.
Consider the example:
Wt::WRectF one(0, 0, 9, 0);
Wt::WRectF two(0, 9, 9, 0);
// one.united(two) => Wt::WRect(0, 9, 9, 0)
United rectangle does not contain points from rectangle one
.
Updated by Boris Nagaev about 13 years ago
This function works as expected:
Wt::WRectF united(const Wt::WRectF& one, const Wt::WRectF& two) {
double left = std::min(one.left(), two.left());
double top = std::min(one.top(), two.top());
double right = std::max(one.right(), two.right());
double bottom = std::max(one.bottom(), two.bottom());
double width = right - left;
double height = bottom - top;
return Wt::WRectF(left, top, width, height);
}
Updated by Koen Deforche about 13 years ago
- Status changed from New to Feedback
- Assignee set to Koen Deforche
- Target version set to 3.2.0
Hey,
I see what is wrong --- isEmpty() considers that either the width or height of a rectangle is 0 (as documented actually).
I'm now in doubt whether we need to change the semantics of isEmpty() or we need to fix united().
We probably need to fix isEmpty(): because one expects that the union of an empty rect with another rect is the other rect. So in your case, rect one cannot be considered empty ?
Regards,
koen
Updated by Boris Nagaev about 13 years ago
Hello!
In my case, united() should not take into account emptiness of rectangles. I need rectangle, which includes 4 points. For this, I create two rectangles (from points 1 and 2 and from points 3 and 4, respectively) and than get united() of them.
IMHO, current definition of isEmpty() should not be changed, but united() should be defined more exactly (the rectangle, including all points of two rectangles) and fixed.
BR.
Updated by Koen Deforche about 13 years ago
- Status changed from Feedback to Resolved
Hey,
I fixed this in in git head.
Regards,
koen
Updated by Koen Deforche almost 13 years ago
- Status changed from Resolved to Closed