C

RectF Class

class Qul::PlatformInterface::RectF

The RectF class defines a rectangle in the plane using floating point precision. More...

Header: #include <platforminterface/rect.h>
Since: Qt Quick Ultralite (Platform) 1.5

Public Functions

RectF(const Qul::PlatformInterface::Rect &rectangle)
RectF(float x, float y, float width, float height)
RectF(const Qul::PlatformInterface::PointF &topLeft, const Qul::PlatformInterface::PointF &bottomRight)
RectF(const Qul::PlatformInterface::PointF &topLeft, const Qul::PlatformInterface::SizeF &size)
RectF()
void adjust(float dx1, float dy1, float dx2, float dy2)
Qul::PlatformInterface::RectF adjusted(float dx1, float dy1, float dx2, float dy2) const
float bottom() const
Qul::PlatformInterface::PointF bottomLeft() const
Qul::PlatformInterface::PointF bottomRight() const
Qul::PlatformInterface::PointF center() const
bool contains(const Qul::PlatformInterface::RectF &rectangle) const
bool contains(const Qul::PlatformInterface::PointF &point) const
bool contains(float x, float y) const
void getCoords(float *x1, float *y1, float *x2, float *y2) const
void getRect(float *x, float *y, float *width, float *height) const
float height() const
Qul::PlatformInterface::RectF intersected(const Qul::PlatformInterface::RectF &rectangle) const
bool intersects(const Qul::PlatformInterface::RectF &rectangle) const
bool isEmpty() const
bool isNull() const
bool isValid() const
float left() const
void moveBottom(float y)
void moveBottomLeft(const Qul::PlatformInterface::PointF &position)
void moveBottomRight(const Qul::PlatformInterface::PointF &position)
void moveCenter(const Qul::PlatformInterface::PointF &position)
void moveLeft(float x)
void moveRight(float x)
void moveTo(float x, float y)
void moveTo(const Qul::PlatformInterface::PointF &position)
void moveTop(float y)
void moveTopLeft(const Qul::PlatformInterface::PointF &position)
void moveTopRight(const Qul::PlatformInterface::PointF &position)
Qul::PlatformInterface::RectF normalized() const
float right() const
void setBottom(float y)
void setBottomLeft(const Qul::PlatformInterface::PointF &position)
void setBottomRight(const Qul::PlatformInterface::PointF &position)
void setCoords(float x1, float y1, float x2, float y2)
void setHeight(float height)
void setLeft(float x)
void setRect(float x, float y, float width, float height)
void setRight(float x)
void setSize(const Qul::PlatformInterface::SizeF &size)
void setTop(float y)
void setTopLeft(const Qul::PlatformInterface::PointF &position)
void setTopRight(const Qul::PlatformInterface::PointF &position)
void setWidth(float width)
void setX(float x)
void setY(float y)
Qul::PlatformInterface::SizeF size() const
Qul::PlatformInterface::Rect toAlignedRect() const
Qul::PlatformInterface::Rect toRect() const
float top() const
Qul::PlatformInterface::PointF topLeft() const
Qul::PlatformInterface::PointF topRight() const
void translate(float dx, float dy)
void translate(const Qul::PlatformInterface::PointF &offset)
Qul::PlatformInterface::RectF translated(float dx, float dy) const
Qul::PlatformInterface::RectF translated(const Qul::PlatformInterface::PointF &offset) const
Qul::PlatformInterface::RectF transposed() const
Qul::PlatformInterface::RectF united(const Qul::PlatformInterface::RectF &rectangle) const
float width() const
float x() const
float y() const
Qul::PlatformInterface::RectF operator&(const Qul::PlatformInterface::RectF &rectangle) const
Qul::PlatformInterface::RectF &operator&=(const Qul::PlatformInterface::RectF &rectangle)
Qul::PlatformInterface::RectF operator|(const Qul::PlatformInterface::RectF &rectangle) const
Qul::PlatformInterface::RectF &operator|=(const Qul::PlatformInterface::RectF &rectangle)
bool operator!=(const Qul::PlatformInterface::RectF &r1, const Qul::PlatformInterface::RectF &r2)
bool operator==(const Qul::PlatformInterface::RectF &r1, const Qul::PlatformInterface::RectF &r2)

Detailed Description

A rectangle is normally expressed as a top-left corner and a size. The size (width and height) of a RectF is always equivalent to the mathematical rectangle that forms the basis for its rendering.

A RectF can be constructed with a set of left, top, width and height coordinates, or from a PointF and a SizeF.

There is also a third constructor creating a RectF from a Rect, and a corresponding toRect() function that returns a Rect object based on the values of this rectangle (note that the coordinates in the returned rectangle are rounded to the nearest integer).

The RectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. RectF also provides functions to move the rectangle relative to the various coordinates. In addition there is a moveTo() function that moves the rectangle, leaving its top left corner at the given coordinates. Alternatively, the translate() function moves the rectangle the given offset relative to the current position, and the translated() function returns a translated copy of this rectangle.

The size() function returns the rectangle's dimensions as a SizeF. The dimensions can also be retrieved separately using the width() and height() functions. To manipulate the dimensions use the setSize(), setWidth() or setHeight() functions. Alternatively, the size can be changed by applying either of the functions setting the rectangle coordinates, for example, setBottom() or setRight().

The contains() function tells whether a given point is inside the rectangle or not, and the intersects() function returns true if this rectangle intersects with a given rectangle (otherwise false). The RectF class also provides the intersected() function which returns the intersection rectangle, and the united() function which returns the rectangle that encloses the given rectangle and this:

The isEmpty() function returns true if the rectangle's width or height is less than, or equal to, 0. Note that an empty rectangle is not valid: The isValid() function returns true if both width and height is larger than 0. A null rectangle (isNull() == true) on the other hand, has both width and height set to 0.

Note that due to the way Rect and RectF are defined, an empty RectF is defined in essentially the same way as Rect.

RectF objects can be compared.

Coordinates

The RectF class provides a collection of functions that return the various rectangle coordinates, and enable manipulation of these. RectF also provides functions to move the rectangle relative to the various coordinates.

For example: the bottom(), setBottom() and moveBottom() functions: bottom() returns the y-coordinate of the rectangle's bottom edge, setBottom() sets the bottom edge of the rectangle to the given y coordinate (it may change the height, but will never change the rectangle's top edge) and moveBottom() moves the entire rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate and its size unchanged.

It is also possible to add offsets to this rectangle's coordinates using the adjust() function, as well as retrieve a new rectangle based on adjustments of the original one using the adjusted() function. If either of the width and height is negative, use the normalized() function to retrieve a rectangle where the corners are swapped.

In addition, RectF provides the getCoords() function which extracts the position of the rectangle's top-left and bottom-right corner, and the getRect() function which extracts the rectangle's top-left corner, width and height. Use the setCoords() and setRect() function to manipulate the rectangle's coordinates and dimensions in one go.

See also Rect.

Member Function Documentation

RectF::RectF(const Qul::PlatformInterface::Rect &rectangle)

Constructs a RectF rectangle from the given Rect rectangle.

See also toRect().

RectF::RectF(float x, float y, float width, float height)

Constructs a rectangle with (x, y) as its top-left corner and the given width and height.

See also setRect().

RectF::RectF(const Qul::PlatformInterface::PointF &topLeft, const Qul::PlatformInterface::PointF &bottomRight)

Constructs a rectangle with the given topLeft and bottomRight corners.

See also setTopLeft() and setBottomRight().

RectF::RectF(const Qul::PlatformInterface::PointF &topLeft, const Qul::PlatformInterface::SizeF &size)

Constructs a rectangle with the given topLeft corner and the given size.

See also setTopLeft() and setSize().

RectF::RectF()

Constructs a null rectangle.

See also isNull().

void RectF::adjust(float dx1, float dy1, float dx2, float dy2)

Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.

See also adjusted() and setRect().

Qul::PlatformInterface::RectF RectF::adjusted(float dx1, float dy1, float dx2, float dy2) const

Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of this rectangle.

See also adjust().

float RectF::bottom() const

Returns the y-coordinate of the rectangle's bottom edge.

See also setBottom(), bottomLeft(), and bottomRight().

Qul::PlatformInterface::PointF RectF::bottomLeft() const

Returns the position of the rectangle's bottom-left corner.

See also setBottomLeft(), bottom(), and left().

Qul::PlatformInterface::PointF RectF::bottomRight() const

Returns the position of the rectangle's bottom-right corner.

See also setBottomRight(), bottom(), and right().

Qul::PlatformInterface::PointF RectF::center() const

Returns the center point of the rectangle.

See also moveCenter().

bool RectF::contains(const Qul::PlatformInterface::RectF &rectangle) const

This is an overloaded function.

Returns true if the given rectangle is inside this rectangle; otherwise returns false.

bool RectF::contains(const Qul::PlatformInterface::PointF &point) const

This is an overloaded function.

Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false.

See also intersects().

bool RectF::contains(float x, float y) const

This is an overloaded function.

Returns true if the point (x, y) is inside or on the edge of the rectangle; otherwise returns false.

void RectF::getCoords(float *x1, float *y1, float *x2, float *y2) const

Extracts the position of the rectangle's top-left corner to *x1 and *y1, and the position of the bottom-right corner to *x2 and *y2.

See also setCoords() and getRect().

void RectF::getRect(float *x, float *y, float *width, float *height) const

Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width and *height.

See also setRect() and getCoords().

float RectF::height() const

Returns the height of the rectangle.

See also setHeight(), width(), and size().

Qul::PlatformInterface::RectF RectF::intersected(const Qul::PlatformInterface::RectF &rectangle) const

Returns the intersection of this rectangle and the given rectangle. Note that r.intersected(s) is equivalent to r & s.

See also intersects(), united(), and operator&=().

bool RectF::intersects(const Qul::PlatformInterface::RectF &rectangle) const

Returns true if this rectangle intersects with the given rectangle (i.e. there is a non-empty area of overlap between them), otherwise returns false.

The intersection rectangle can be retrieved using the intersected() function.

See also contains().

bool RectF::isEmpty() const

Returns true if the rectangle is empty, otherwise returns false.

An empty rectangle has width() <= 0 or height() <= 0. An empty rectangle is not valid (i.e., isEmpty() == !isValid()).

Use the normalized() function to retrieve a rectangle where the corners are swapped.

See also isNull(), isValid(), and normalized().

bool RectF::isNull() const

Returns true if the rectangle is a null rectangle, otherwise returns false.

A null rectangle has both the width and the height set to 0. A null rectangle is also empty, and hence not valid.

See also isEmpty() and isValid().

bool RectF::isValid() const

Returns true if the rectangle is valid, otherwise returns false.

A valid rectangle has a width() > 0 and height() > 0. Note that non-trivial operations like intersections are not defined for invalid rectangles. A valid rectangle is not empty (i.e., isValid() == !isEmpty()).

See also isNull(), isEmpty(), and normalized().

float RectF::left() const

Returns the x-coordinate of the rectangle's left edge. Equivalent to x().

See also setLeft(), topLeft(), and bottomLeft().

void RectF::moveBottom(float y)

Moves the rectangle vertically, leaving the rectangle's bottom edge at the given y coordinate. The rectangle's size is unchanged.

See also bottom(), setBottom(), and moveTop().

void RectF::moveBottomLeft(const Qul::PlatformInterface::PointF &position)

Moves the rectangle, leaving the bottom-left corner at the given position. The rectangle's size is unchanged.

See also setBottomLeft(), moveBottom(), and moveLeft().

void RectF::moveBottomRight(const Qul::PlatformInterface::PointF &position)

Moves the rectangle, leaving the bottom-right corner at the given position. The rectangle's size is unchanged.

See also setBottomRight(), moveBottom(), and moveRight().

void RectF::moveCenter(const Qul::PlatformInterface::PointF &position)

Moves the rectangle, leaving the center point at the given position. The rectangle's size is unchanged.

See also center().

void RectF::moveLeft(float x)

Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate. The rectangle's size is unchanged.

See also left(), setLeft(), and moveRight().

void RectF::moveRight(float x)

Moves the rectangle horizontally, leaving the rectangle's right edge at the given x coordinate. The rectangle's size is unchanged.

See also right(), setRight(), and moveLeft().

void RectF::moveTo(float x, float y)

This is an overloaded function.

Moves the rectangle, leaving the top-left corner at the given position (x, y). The rectangle's size is unchanged.

See also translate() and moveTopLeft().

void RectF::moveTo(const Qul::PlatformInterface::PointF &position)

This is an overloaded function.

Moves the rectangle, leaving the top-left corner at the given position.

void RectF::moveTop(float y)

Moves the rectangle vertically, leaving the rectangle's top line at the given y coordinate. The rectangle's size is unchanged.

See also top(), setTop(), and moveBottom().

void RectF::moveTopLeft(const Qul::PlatformInterface::PointF &position)

Moves the rectangle, leaving the top-left corner at the given position. The rectangle's size is unchanged.

See also setTopLeft(), moveTop(), and moveLeft().

void RectF::moveTopRight(const Qul::PlatformInterface::PointF &position)

Moves the rectangle, leaving the top-right corner at the given position. The rectangle's size is unchanged.

See also setTopRight(), moveTop(), and moveRight().

Qul::PlatformInterface::RectF RectF::normalized() const

Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height.

If width() < 0 the function swaps the left and right corners, and it swaps the top and bottom corners if height() < 0.

See also isValid() and isEmpty().

Returns the x-coordinate of the rectangle's right edge.

See also setRight(), topRight(), and bottomRight().

void RectF::setBottom(float y)

Sets the bottom edge of the rectangle to the given y coordinate. May change the height, but will never change the top edge of the rectangle.

See also bottom() and moveBottom().

void RectF::setBottomLeft(const Qul::PlatformInterface::PointF &position)

Set the bottom-left corner of the rectangle to the given position. May change the size, but will never change the top-right corner of the rectangle.

See also bottomLeft() and moveBottomLeft().

void RectF::setBottomRight(const Qul::PlatformInterface::PointF &position)

Set the bottom-right corner of the rectangle to the given position. May change the size, but will never change the top-left corner of the rectangle.

See also bottomRight() and moveBottomRight().

void RectF::setCoords(float x1, float y1, float x2, float y2)

Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its bottom-right corner to (x2, y2).

See also getCoords() and setRect().

void RectF::setHeight(float height)

Sets the height of the rectangle to the given height. The bottom edge is changed, but not the top one.

See also height() and setSize().

void RectF::setLeft(float x)

Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.

Equivalent to setX().

See also left() and moveLeft().

void RectF::setRect(float x, float y, float width, float height)

Sets the coordinates of the rectangle's top-left corner to (x, y), and its size to the given width and height.

See also getRect() and setCoords().

void RectF::setRight(float x)

Sets the right edge of the rectangle to the given x coordinate. May change the width, but will never change the left edge of the rectangle.

See also right() and moveRight().

void RectF::setSize(const Qul::PlatformInterface::SizeF &size)

Sets the size of the rectangle to the given size. The top-left corner is not moved.

See also size(), setWidth(), and setHeight().

void RectF::setTop(float y)

Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.

Equivalent to setY().

See also top() and moveTop().

void RectF::setTopLeft(const Qul::PlatformInterface::PointF &position)

Set the top-left corner of the rectangle to the given position. May change the size, but will never change the bottom-right corner of the rectangle.

See also topLeft() and moveTopLeft().

void RectF::setTopRight(const Qul::PlatformInterface::PointF &position)

Set the top-right corner of the rectangle to the given position. May change the size, but will never change the bottom-left corner of the rectangle.

See also topRight() and moveTopRight().

void RectF::setWidth(float width)

Sets the width of the rectangle to the given width. The right edge is changed, but not the left one.

See also width() and setSize().

void RectF::setX(float x)

Sets the left edge of the rectangle to the given x coordinate. May change the width, but will never change the right edge of the rectangle.

Equivalent to setLeft().

See also x(), setY(), and setTopLeft().

void RectF::setY(float y)

Sets the top edge of the rectangle to the given y coordinate. May change the height, but will never change the bottom edge of the rectangle.

Equivalent to setTop().

See also y(), setX(), and setTopLeft().

Qul::PlatformInterface::SizeF RectF::size() const

Returns the size of the rectangle.

See also setSize(), width(), and height().

Qul::PlatformInterface::Rect RectF::toAlignedRect() const

Returns a Rect based on the values of this rectangle that is the smallest possible integer rectangle that completely contains this rectangle.

See also toRect().

Qul::PlatformInterface::Rect RectF::toRect() const

Returns a Rect based on the values of this rectangle. Note that the coordinates in the returned rectangle are rounded to the nearest integer.

See also RectF() and toAlignedRect().

float RectF::top() const

Returns the y-coordinate of the rectangle's top edge. Equivalent to y().

See also setTop(), topLeft(), and topRight().

Qul::PlatformInterface::PointF RectF::topLeft() const

Returns the position of the rectangle's top-left corner.

See also setTopLeft(), top(), and left().

Qul::PlatformInterface::PointF RectF::topRight() const

Returns the position of the rectangle's top-right corner.

See also setTopRight(), top(), and right().

void RectF::translate(float dx, float dy)

This is an overloaded function.

Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position. Positive values move the rectangle to the right and downwards.

See also moveTopLeft(), moveTo(), and translated().

void RectF::translate(const Qul::PlatformInterface::PointF &offset)

This is an overloaded function.

Moves the rectangle offset.x() along the x axis and offset.y() along the y axis, relative to the current position.

Qul::PlatformInterface::RectF RectF::translated(float dx, float dy) const

This is an overloaded function.

Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis, relative to the current position. Positive values move the rectangle to the right and down.

See also translate().

Qul::PlatformInterface::RectF RectF::translated(const Qul::PlatformInterface::PointF &offset) const

This is an overloaded function.

Returns a copy of the rectangle that is translated offset.x() along the x axis and offset.y() along the y axis, relative to the current position.

Qul::PlatformInterface::RectF RectF::transposed() const

Returns a copy of the rectangle that has its width and height exchanged.

See also SizeF::transposed().

Qul::PlatformInterface::RectF RectF::united(const Qul::PlatformInterface::RectF &rectangle) const

Returns the bounding rectangle of this rectangle and the given rectangle.

See also intersected().

float RectF::width() const

Returns the width of the rectangle.

See also setWidth(), height(), and size().

float RectF::x() const

Returns the x-coordinate of the rectangle's left edge. Equivalent to left().

See also setX(), y(), and topLeft().

float RectF::y() const

Returns the y-coordinate of the rectangle's top edge. Equivalent to top().

See also setY(), x(), and topLeft().

Qul::PlatformInterface::RectF RectF::operator&(const Qul::PlatformInterface::RectF &rectangle) const

Returns the intersection of this rectangle and the given rectangle. Returns an empty rectangle if there is no intersection.

See also operator&=() and intersected().

Qul::PlatformInterface::RectF &RectF::operator&=(const Qul::PlatformInterface::RectF &rectangle)

Intersects this rectangle with the given rectangle.

See also intersected() and operator|=().

Qul::PlatformInterface::RectF RectF::operator|(const Qul::PlatformInterface::RectF &rectangle) const

Returns the bounding rectangle of this rectangle and the given rectangle.

See also united() and operator|=().

Qul::PlatformInterface::RectF &RectF::operator|=(const Qul::PlatformInterface::RectF &rectangle)

Unites this rectangle with the given rectangle.

See also united() and operator|().

Related Non-Members

bool operator!=(const Qul::PlatformInterface::RectF &r1, const Qul::PlatformInterface::RectF &r2)

Returns true if the rectangles r1 r2 are different, otherwise returns false.

bool operator==(const Qul::PlatformInterface::RectF &r1, const Qul::PlatformInterface::RectF &r2)

Returns true if the rectangles r1 and r2 are equal, otherwise returns false.

Available under certain Qt licenses.
Find out more.