27#ifndef EASY3D_CORE_RECTANGLE_H
28#define EASY3D_CORE_RECTANGLE_H
32#include <easy3d/core/vec.h>
41 template <
typename FT>
46 x_min_ = std::min(q.x, p.x);
47 x_max_ = std::max(q.x, p.x);
48 y_min_ = std::min(q.y, p.y);
49 y_max_ = std::max(q.y, p.y);
56 : x_min_(std::
min(xmin, xmax))
57 , y_min_(std::
min(ymin, ymax))
58 , x_max_(std::
max(xmin, xmax))
59 , y_max_(std::
max(ymin, ymax))
63 FT& x_min() {
return x_min_; }
64 FT& y_min() {
return y_min_; }
65 FT& x_max() {
return x_max_; }
66 FT& y_max() {
return y_max_; }
67 FT x_min()
const {
return x_min_; }
68 FT y_min()
const {
return y_min_; }
69 FT x_max()
const {
return x_max_; }
70 FT y_max()
const {
return y_max_; }
72 FT& x() {
return x_min_; }
73 FT& y() {
return y_min_; }
74 FT x()
const {
return x_min_; }
75 FT y()
const {
return y_min_; }
78 FT
width()
const {
return x_max() - x_min(); }
80 FT
height()
const {
return y_max() - y_min(); }
82 FT& left() {
return x_min_; }
83 FT& top() {
return y_min_; }
84 FT& right() {
return x_max_; }
85 FT& bottom() {
return y_max_; }
86 FT left()
const {
return x_min_; }
87 FT top()
const {
return y_min_; }
88 FT right()
const {
return x_max_; }
89 FT bottom()
const {
return y_max_; }
101 Vec<2, FT> max_point()
const {
return Vec<2, FT>(x_max_, y_max_); }
105 return Vec<2, FT>(FT(0.5) * (x_max() + x_min()), FT(0.5) * (y_max() + y_min()));
The GenericRect class defines a rectangle in the 2D space.
Definition: rect.h:42
FT height() const
Returns the height of the rectangle.
Definition: rect.h:80
FT width() const
Returns the width of the rectangle.
Definition: rect.h:78
Vec< 2, FT > top_right() const
Returns the position of the rectangle's top-right corner.
Definition: rect.h:96
GenericRect(const Vec< 2, FT > &p, const Vec< 2, FT > &q)
Constructs a rectangle from two points p and q.
Definition: rect.h:45
Vec< 2, FT > top_left() const
Returns the position of the rectangle's top-left corner.
Definition: rect.h:92
Vec< 2, FT > bottom_right() const
Returns the position of the rectangle's bottom-right corner.
Definition: rect.h:94
Vec< 2, FT > center() const
Returns the center point of the rectangle.
Definition: rect.h:104
Vec< 2, FT > bottom_left() const
Returns the position of the rectangle's bottom-left corner.
Definition: rect.h:98
GenericRect(FT xmin, FT xmax, FT ymin, FT ymax)
Constructs a rectangle from its min coordinates (xmin and ymin) and max coordinates (xmax and ymax).
Definition: rect.h:55
Base class for vector types. It provides generic functionality for N dimensional vectors.
Definition: vec.h:34
Definition: collider.cpp:182
FT max()
Function returning maximum representable value for a given type.
FT min()
Function returning minimum representable value for a given type.