32#ifndef RCSC_GEOM_RECT2D_H
33#define RCSC_GEOM_RECT2D_H
72 : M_top_left( 0.0, 0.0 )
83 Rect2D(
const double & left_x,
85 const double & length,
86 const double & width )
87 : M_top_left( left_x, top_y )
88 , M_size( length, width )
97 Rect2D(
const Vector2D & top_left,
98 const double & length,
99 const double & width )
100 : M_top_left( top_left )
101 , M_size( length, width )
112 : M_top_left( top_left )
126 : M_top_left( top_left )
127 , M_size( bottom_right.x - top_left.x,
128 bottom_right.y - top_left.y )
130 if ( bottom_right.
x - top_left.
x < 0.0 )
132 M_top_left.x = bottom_right.x;
134 if ( bottom_right.
y - top_left.
y < 0.0 )
136 M_top_left.y = bottom_right.y;
148 const double & length,
149 const double & width )
166 const double & center_y,
167 const double & length,
168 const double & width )
170 return Rect2D( center_x - length*0.5,
171 center_y - width*0.5,
185 return Rect2D( top_left, bottom_right );
213 Rect2D & assign(
const double & left_x,
214 const double & top_y,
215 const double & length,
216 const double & width )
218 M_top_left.
assign( left_x, top_y );
219 M_size.
assign( length, width );
231 Rect2D & assign(
const Vector2D & top_left,
232 const double & length,
233 const double & width )
235 M_top_left = top_left;
236 M_size.
assign( length, width );
251 M_top_left = top_left;
266 M_top_left.assign( point.
x - M_size.length() * 0.5,
267 point.
y - M_size.width() * 0.5 );
295 M_top_left.assign( point.
x - M_size.length(),
296 point.
y - M_size.width() );
335 M_top_left.x = x - M_size.length();
385 M_top_left.y = y - M_size.width();
559 const double & width )
561 M_size.assign( length, width );
583 return M_size.length() > 0.0
584 && M_size.width() > 0.0;
594 return M_size.length() * M_size.width();
605 return (
left() <= point.
x
618 const double & error_thr )
const
620 return (
left() - error_thr <= point.
x
621 && point.
x <=
right() + error_thr
622 &&
top() - error_thr <= point.
y
623 && point.
y <=
bottom() + error_thr );
844 return Rect2D( *
this ) &= other;
863 return Rect2D( *
this ) |= other;
2d straight line class
Definition line_2d.h:47
2D ray line class
Definition ray_2d.h:44
2D rectangle regin class.
Definition rect_2d.h:59
static Rect2D from_corners(const Vector2D &top_left, const Vector2D &bottom_right)
create rectangle with 2 corner points. just call one of constructor.
Definition rect_2d.h:182
Rect2D(const Vector2D &top_left, const Vector2D &bottom_right)
constructor with 2 points.
Definition rect_2d.h:124
const Rect2D & setSize(const Size2D &size)
set a new size
Definition rect_2d.h:571
virtual bool contains(const Vector2D &point) const
check if point is within this region.
Definition rect_2d.h:603
Vector2D bottomLeft() const
get the bottom-left corner point
Definition rect_2d.h:743
const double & left() const
get the left x coordinate of this rectangle.
Definition rect_2d.h:631
const Rect2D & setWidth(const double &width)
set a new y-range
Definition rect_2d.h:545
Line2D bottomEdge() const
get the bottom edge line
Definition rect_2d.h:788
const double & top() const
get the top y coordinate of this rectangle.
Definition rect_2d.h:650
Rect2D intersected(const Rect2D &other) const
get the intersected rectangle of this rectangle and the other rectangle. This method is equivalent to...
Definition rect_2d.h:842
const Rect2D & setMinX(const double &x)
alias of setLeft.
Definition rect_2d.h:462
Vector2D topRight() const
get the top-right corner point
Definition rect_2d.h:734
double bottom() const
get the bottom y coordinate of this rectangle.
Definition rect_2d.h:659
double minX() const
get minimum value of x coordinate of this rectangle
Definition rect_2d.h:668
double right() const
get the right x coordinate of this rectangle.
Definition rect_2d.h:640
const Rect2D & moveTopLeft(const Vector2D &point)
move the rectangle. the top-left coner is set to the given position. the size is unchanged.
Definition rect_2d.h:279
const Rect2D & moveLeft(const double &x)
move the rectangle. the left line is set to the given position. the size is unchanged.
Definition rect_2d.h:308
const Rect2D & setLength(const double &length)
set a new x-range
Definition rect_2d.h:533
static Rect2D from_center(const double ¢er_x, const double ¢er_y, const double &length, const double &width)
create rectangle with center point and size.
Definition rect_2d.h:165
const Rect2D & setBottomRight(const double &x, const double &y)
set the bottom-right corner of the rectangle. the size may be changed, but the top-left corner will n...
Definition rect_2d.cpp:71
static Rect2D from_center(const Vector2D ¢er, const double &length, const double &width)
create rectangle with center point and size.
Definition rect_2d.h:147
virtual double area() const
get the area value of this rectangle.
Definition rect_2d.h:592
Line2D leftEdge() const
get the left edge line
Definition rect_2d.h:761
Vector2D bottomRight() const
get the bottom-right corner point
Definition rect_2d.h:752
const Rect2D & setRight(const double &x)
set the right of rectangle. the size may be changed, but the left will never be changed.
Definition rect_2d.cpp:107
const Rect2D & setBottomRight(const Vector2D &point)
set the bottom-right corner of the rectangle. the size may be changed, but the top-left corner will n...
Definition rect_2d.h:442
Rect2D united(const Rect2D &other) const
get the united rectangle of this rectangle and the other rectangle. This method is equivalent to oper...
Definition rect_2d.h:861
const Rect2D & moveTop(const double &y)
move the rectangle. the top line is set to the given value. the size is unchanged.
Definition rect_2d.h:358
const Rect2D & setMaxX(const double &x)
alias of setRight.
Definition rect_2d.h:482
Line2D topEdge() const
get the top edge line
Definition rect_2d.h:779
const Size2D & size() const
get the XY range of this rectangle
Definition rect_2d.h:705
const Rect2D & setTopLeft(const double &x, const double &y)
set the top-left corner of the rectangle. the size may be changed, but the bottom-right corner will n...
Definition rect_2d.cpp:51
double maxY() const
get maximum value of y coordinate of this rectangle
Definition rect_2d.h:695
Rect2D()
default constructor creates a zero area rectanble at (0,0)
Definition rect_2d.h:71
const Rect2D & setTopLeft(const Vector2D &point)
set the top-left corner of the rectangle. the size may be changed, but the bottom-right corner will n...
Definition rect_2d.h:419
static Rect2D from_corners(const double &l, const double &t, const double &r, const double &b)
create rectangle with 2 corner points. just call one of constructor.
Definition rect_2d.h:196
const Rect2D & setBottom(const double &y)
set the bottom of rectangle. the size may be changed, but the top will never be changed.
Definition rect_2d.cpp:139
Rect2D(const Vector2D &top_left, const Size2D &size)
constructor with variables
Definition rect_2d.h:110
const Rect2D & setLeft(const double &x)
set the left of rectangle. the size may be changed, but the right will never be changed.
Definition rect_2d.cpp:91
const Rect2D & assign(const Vector2D &top_left, const Size2D &size)
assign new values
Definition rect_2d.h:248
double maxX() const
get maximum value of x coordinate of this rectangle
Definition rect_2d.h:677
bool contains(const Vector2D &point, const double &error_thr) const
check if point is within this region with error threshold.
Definition rect_2d.h:617
const Vector2D & topLeft() const
get the top-left corner point
Definition rect_2d.h:725
Line2D rightEdge() const
get the right edge line
Definition rect_2d.h:770
Vector2D center() const
get center point
Definition rect_2d.h:714
const Rect2D & moveMaxX(const double &x)
alias of moveRight.
Definition rect_2d.h:345
const Rect2D & moveBottomRight(const Vector2D &point)
move the rectangle. the bottom-right coner is set to the given position. the size is unchanged.
Definition rect_2d.h:293
const Rect2D & moveMinX(const double &x)
alias of moveLeft.
Definition rect_2d.h:320
const Rect2D & moveCenter(const Vector2D &point)
move the rectangle. the center point is set to the given position. the size is unchanged.
Definition rect_2d.h:264
const Rect2D & operator&=(const Rect2D &other)
convert this rectangle to the intersection rectangle with other. If no intersection between rectangle...
Definition rect_2d.cpp:302
const Rect2D & moveBottom(const double &y)
move the rectangle. the top line is set to the given value. the size is unchanged.
Definition rect_2d.h:383
double minY() const
get minimum value of y coordinate of this rectangle
Definition rect_2d.h:686
bool isValid() const
check if this rectangle is valid or not.
Definition rect_2d.h:581
const Rect2D & setMinY(const double &y)
alias of setTop.
Definition rect_2d.h:502
const Rect2D & setSize(const double &length, const double &width)
set a new size
Definition rect_2d.h:558
const Rect2D & moveMaxY(const double &y)
alias of moveTop.
Definition rect_2d.h:395
const Rect2D & setTop(const double &y)
set the top of rectangle. the size may be changed, but the bottom will never be changed.
Definition rect_2d.cpp:123
const Rect2D & moveMinY(const double &y)
alias of moveTop.
Definition rect_2d.h:370
const Rect2D & moveRight(const double &x)
move the rectangle. the right line is set to the given value. the size is unchanged.
Definition rect_2d.h:333
const Rect2D & setMaxY(const double &y)
alias of setBottom.
Definition rect_2d.h:522
int intersection(const Line2D &line, Vector2D *sol1, Vector2D *sol2) const
calculate intersection point with line.
Definition rect_2d.cpp:154
const Rect2D & operator|=(const Rect2D &other)
convert this rectangle to the united rectangle with other.
Definition rect_2d.cpp:335
Region2D()
accessible only from derived classes
Definition region_2d.h:49
2d segment line class
Definition segment_2d.h:46
2D size definition class
Definition size_2d.h:44
const double & length() const
get the value of X range
Definition size_2d.h:117
const Size2D & assign(const double &length, const double &width)
assign new range directly.
Definition size_2d.h:80
const double & width() const
get the value of Y range
Definition size_2d.h:127
2D point vector class
Definition vector_2d.h:47
double y
Y coordinate.
Definition vector_2d.h:65
double x
X coordinate.
Definition vector_2d.h:64
Vector2D & assign(const double &xx, const double &yy)
assign XY value directly.
Definition vector_2d.h:101
2d vector class Header File.
2D straight line Header File.
const rcsc::Rect2D operator&(const rcsc::Rect2D &lhs, const rcsc::Rect2D &rhs)
get the intersected rectangle of this rectangle and the other rectangle. If no intersection between r...
Definition rect_2d.h:876
const rcsc::Rect2D operator|(const rcsc::Rect2D &lhs, const rcsc::Rect2D &rhs)
get the united rectangle of this rectangle and the other rectangle.
Definition rect_2d.h:890
abstract 2D region class Header File.
2d size class Header File.