Rectangle

namespace ezgl

A library for creating a graphical user interface.

class rectangle
#include <rectangle.hpp>

Represents a rectangle as two diagonally opposite points.

Public Functions

inline rectangle() noexcept

Default constructor: Create a zero-sized rectangle at {0,0}.

inline rectangle(point2d origin_pt, point2d top_right_pt)

Create a rectangle from two diagonally opposite points.

inline rectangle(point2d origin_pt, double rec_width, double rec_height)

Create a rectangle with a given width and height.

inline double left() const

The minimum x-coordinate.

inline double right() const

The maximum x-coordinate.

inline double bottom() const

The minimum y-coordinate.

inline double top() const

The maximum y-coordinate.

inline point2d bottom_left() const

The minimum x-coordinate and the minimum y-coordinate.

inline point2d top_left() const

The minimum x-coordinate and the maximum y-coordinate.

inline point2d bottom_right() const

The maximum x-coordinate and the minimum y-coordinate.

inline point2d top_right() const

The maximum x-coordinate and the maximum y-coordinate.

inline bool contains(double x, double y) const

Test if the x and y values are within the rectangle.

inline bool contains(point2d point) const

Test if the x and y values are within the rectangle.

inline double width() const

The width of the rectangle.

inline double height() const

The height of the rectangle.

inline double area() const

The area of the rectangle.

inline double center_x() const

The center of the rectangle in the x plane.

inline double center_y() const

The center of the rectangle in the y plane.

inline point2d center() const

The center of the recangle.

inline bool operator==(const rectangle &rhs) const

Test for equality.

inline bool operator!=(const rectangle &rhs) const

Test for inequality.

Public Members

point2d m_first

The first point of the rectangle

point2d m_second

The second point of the rectangle

Friends

inline friend rectangle &operator+=(rectangle &lhs, point2d const &rhs)

translate the rectangle by positive offsets.

inline friend rectangle &operator-=(rectangle &lhs, point2d const &rhs)

translate the rectangle by negative offsets.

inline friend rectangle operator-(rectangle &lhs, point2d const &rhs)

Create a new rectangle that is translated (negative offsets).

inline friend rectangle operator+(rectangle &lhs, point2d const &rhs)

Create a new rectangle that is translated (positive offsets).