Bug #1017

WRectF: united returns wrong rectangles

Added by User Starius over 1 year ago. Updated over 1 year ago.

Status:ClosedStart date:10/09/2011
Priority:NormalDue date:
Assignee:Koen Deforche% Done:

0%

Category:-
Target version:3.2.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.

History

#1 Updated by User Starius over 1 year 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);
}

#2 Updated by Koen Deforche over 1 year 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

#3 Updated by User Starius over 1 year 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.

#4 Updated by Koen Deforche over 1 year ago

  • Status changed from Feedback to Resolved

Hey,

I fixed this in in git head.

Regards,
koen

#5 Updated by Koen Deforche over 1 year ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF