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,
87 : M_top_left( left_x, top_y )
88 , M_size( length, width )
97 Rect2D(
const Vector2D & top_left,
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;
166 const double center_y,
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,
218 M_top_left.
assign( left_x, top_y );
219 M_size.
assign( length, width );
231 Rect2D & assign(
const Vector2D & top_left,
235 M_top_left = top_left;
236 M_size.
assign( length, width );
250 M_top_left = top_left;
265 point.
y - M_size.
width() * 0.5 );
292 point.
y - M_size.
width() );
328 M_top_left.
x = x - M_size.
length();
374 M_top_left.
y = y - M_size.
width();
534 M_size.
assign( length, width );
555 return M_size.
length() > 0.0
556 && M_size.
width() > 0.0;
577 return (
left() <= point.
x
590 const double error_thr )
const
592 return (
left() - error_thr <= point.
x
593 && point.
x <=
right() + error_thr
594 &&
top() - error_thr <= point.
y
595 && point.
y <=
bottom() + error_thr );
811 return Rect2D( *
this ) &= other;
829 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
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...
Rect2D(const Vector2D &top_left, const Vector2D &bottom_right)
constructor with 2 points.
Definition: rect_2d.h:124
const Rect2D & setSize(const double length, const double width)
set a new size
Definition: rect_2d.h:531
int intersection(const Ray2D &ray, Vector2D *sol1, Vector2D *sol2) const
calculate intersection point with ray.
const Rect2D & setMaxY(const double y)
alias of setBottom.
Definition: rect_2d.h:498
const Rect2D & setSize(const Size2D &size)
set a new size
Definition: rect_2d.h:543
virtual bool contains(const Vector2D &point) const
check if point is within this region.
Definition: rect_2d.h:575
const Rect2D & setMinY(const double y)
alias of setTop.
Definition: rect_2d.h:480
Vector2D bottomLeft() const
get the bottom-left corner point
Definition: rect_2d.h:711
const Rect2D & moveMinY(const double y)
alias of moveTop.
Definition: rect_2d.h:360
Line2D bottomEdge() const
get the bottom edge line
Definition: rect_2d.h:756
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:809
int intersection(const Segment2D &segment, Vector2D *sol1, Vector2D *sol2) const
calculate intersection point with line segment.
const Rect2D & setRight(const double x)
set the right of rectangle. the size may be changed, but the left will never be changed.
Vector2D topRight() const
get the top-right corner point
Definition: rect_2d.h:702
double bottom() const
get the bottom y coordinate of this rectangle.
Definition: rect_2d.h:629
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
static Rect2D from_center(const double center_x, const double center_y, const double length, const double width)
create rectangle with center point and size.
Definition: rect_2d.h:165
const Rect2D & setBottom(const double y)
set the bottom of rectangle. the size may be changed, but the top will never be changed.
double left() const
get the left x coordinate of this rectangle.
Definition: rect_2d.h:602
double minX() const
get minimum value of x coordinate of this rectangle
Definition: rect_2d.h:638
double right() const
get the right x coordinate of this rectangle.
Definition: rect_2d.h:611
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:276
virtual double area() const
get the area value of this rectangle.
Definition: rect_2d.h:564
const Rect2D & setMinX(const double x)
alias of setLeft.
Definition: rect_2d.h:444
const Rect2D & moveMaxX(const double x)
alias of moveRight.
Definition: rect_2d.h:337
Line2D leftEdge() const
get the left edge line
Definition: rect_2d.h:729
Vector2D bottomRight() const
get the bottom-right corner point
Definition: rect_2d.h:720
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...
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:426
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:827
const Rect2D & setLength(const double length)
set a new x-range
Definition: rect_2d.h:508
const Rect2D & moveMaxY(const double y)
alias of moveTop.
Definition: rect_2d.h:383
Line2D topEdge() const
get the top edge line
Definition: rect_2d.h:747
const Size2D & size() const
get the XY range of this rectangle
Definition: rect_2d.h:674
double maxY() const
get maximum value of y coordinate of this rectangle
Definition: rect_2d.h:665
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:405
const Rect2D & setTop(const double y)
set the top of rectangle. the size may be changed, but the bottom will never be changed.
const Rect2D & setLeft(const double x)
set the left of rectangle. the size may be changed, but the right will never be changed.
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:326
const Rect2D & setMaxX(const double x)
alias of setRight.
Definition: rect_2d.h:462
Rect2D(const Vector2D &top_left, const Size2D &size)
constructor with variables
Definition: rect_2d.h:110
const Rect2D & assign(const Vector2D &top_left, const Size2D &size)
assign new values
Definition: rect_2d.h:247
const Rect2D & moveMinX(const double x)
alias of moveLeft.
Definition: rect_2d.h:314
double maxX() const
get maximum value of x coordinate of this rectangle
Definition: rect_2d.h:647
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:372
const Vector2D & topLeft() const
get the top-left corner point
Definition: rect_2d.h:693
Line2D rightEdge() const
get the right edge line
Definition: rect_2d.h:738
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:303
Vector2D center() const
get center point
Definition: rect_2d.h:683
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 & 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:289
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:262
const Rect2D & operator&=(const Rect2D &other)
convert this rectangle to the intersection rectangle with other. If no intersection between rectangle...
bool contains(const Vector2D &point, const double error_thr) const
check if point is within this region with error threshold.
Definition: rect_2d.h:589
double minY() const
get minimum value of y coordinate of this rectangle
Definition: rect_2d.h:656
const Rect2D & setWidth(const double width)
set a new y-range
Definition: rect_2d.h:519
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:349
bool isValid() const
check if this rectangle is valid or not.
Definition: rect_2d.h:553
double top() const
get the top y coordinate of this rectangle.
Definition: rect_2d.h:620
int intersection(const Line2D &line, Vector2D *sol1, Vector2D *sol2) const
calculate intersection point with line.
const Rect2D & operator|=(const Rect2D &other)
convert this rectangle to the united rectangle with other.
abstract 2D region class
Definition: region_2d.h:43
2d segment line class
Definition: segment_2d.h:46
2D size definition class
Definition: size_2d.h:44
const Size2D & assign(const double length, const double width)
assign new range directly.
Definition: size_2d.h:79
double length() const
get the value of X range
Definition: size_2d.h:113
const Size2D & setWidth(const double width)
set new Y range
Definition: size_2d.h:103
double width() const
get the value of Y range
Definition: size_2d.h:122
const Size2D & setLength(const double length)
set new X range
Definition: size_2d.h:92
2D point vector class
Definition: vector_2d.h:46
Vector2D & assign(const double xx, const double yy)
assign XY value directly.
Definition: vector_2d.h:100
double y
Y coordinate.
Definition: vector_2d.h:64
double x
X coordinate.
Definition: vector_2d.h:63
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:842
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:856
abstract 2D region class Header File.
2d size class Header File.
2d vector class Header File.