Project

General

Profile

Actions

Bug #1017

closed

WRectF: united returns wrong rectangles

Added by Boris Nagaev over 12 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
10/09/2011
Due date:
% Done:

0%

Estimated time:

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.

Actions #1

Updated by Boris Nagaev over 12 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);
}
Actions #2

Updated by Koen Deforche over 12 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

Actions #3

Updated by Boris Nagaev over 12 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.

Actions #4

Updated by Koen Deforche over 12 years ago

  • Status changed from Feedback to Resolved

Hey,

I fixed this in in git head.

Regards,

koen

Actions #5

Updated by Koen Deforche over 12 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF