10#ifndef COMMON_RECT_HPP
11#define COMMON_RECT_HPP
14#include <opencv2/core.hpp>
96 operator cv::Rect()
const;
97 operator cv::Vec4i()
const;
98 operator std::vector<int>()
const;
111 template <
typename U>
141 return std::hash<int>()(
rect.
x) ^ std::hash<int>()(
rect.
y) ^ std::hash<int>()(
rect.width) ^ std::hash<int>()(
rect.height);
156inline Rect::Margin::Margin(
int top,
int right,
int bottom,
int left) : top(top), right(right), bottom(bottom), left(left) {}
215inline Rect::Rect(
int x,
int y,
int width,
int height) : x(x), y(y), width(width), height(height) {
308inline Rect::operator cv::Rect()
const {
309 return cv::Rect(x, y, width, height);
321inline Rect::operator cv::Vec4i()
const {
322 return {x, y, width, height};
334inline Rect::operator std::vector<int>()
const {
335 return {x, y, width, height};
499 out <<
"{ x: " <<
rect.
x <<
", y: " <<
rect.
y <<
", width: " <<
rect.width <<
", height: " <<
rect.height <<
" }";
579 return this->
Include(
Point2i(rect.
x,
rect.
y),
margin,
is_include_boundaries) && this->
Include(
Point2i(rect.
x +
rect.width,
rect.
y),
margin,
is_include_boundaries) && this->
Include(
Point2i(rect.
x,
rect.
y +
rect.height),
margin,
is_include_boundaries) && this->
Include(
Point2i(rect.
x +
rect.width,
rect.
y +
rect.height),
margin,
is_include_boundaries);
605 return Line(
x -
margin.left,
y,
x +
width +
margin.right,
y).
IsIntersect(
Line(
rect.
x,
rect.
y,
rect.
x +
rect.width,
rect.
y),
INTERSECT_X,
is_include_boundaries) &&
Line(
x,
y -
margin.top,
x,
y +
height +
margin.bottom).
IsIntersect(
Line(
rect.
x,
rect.
y,
rect.
x,
rect.
y +
rect.height),
INTERSECT_Y,
is_include_boundaries);
607 throw Exception(
"The type(IntersectType) of param \"type\" is incorrect!");
643 throw Exception(
"The type(IntersectType) of param \"type\" is incorrect!");
705 std::vector<Line> lines;
714 if (
line.IsIntersect(lines[
i]))
715 return {
line.Intersect(lines[
i]),
i};
bool IsIntersect(const Line &line, IntersectType type=INTERSECT_XY, bool is_include_boundaries=false) const
判断两线是否相交
Point2i pt2
线的第二个点(默认:对于横线是右边的点,对于竖线是下面的点)
Point2i pt1
线的第一个点(默认:对于横线是左边的点;对于竖线是上面的点)
friend bool operator>=(const Rect &rect1, const Rect &rect2)
矩形类重载大于等于号
int x
矩形的左上角 x 坐标(仅当矩形宽高为正数时)
friend bool operator==(const Rect &rect1, const Rect &rect2)
矩形类重载等于号
bool IsIntersect(const Rect &rect, IntersectType type=INTERSECT_XY, const Margin &margin=0, bool is_include_boundaries=false) const
判断所给矩形是否与矩形相交(不算边界)
Rect & Translate(int dx, int dy)
矩形平移
friend bool operator<(const Rect &rect1, const Rect &rect2)
矩形类重载小于号
Rect Intersect(const Rect &rect) const
计算两相交矩形所返回的新矩形(包含边界)
int y
矩形的左上角 y 坐标(仅当矩形宽高为正数时)
Point2d CenterPoint() const
获取矩形的中心坐标
Rect Union(const Rect &rect) const
计算两个矩形的并集
Point2i DiagonalPoint(bool is_left_top=false) const
获取矩形的对角点坐标
Rect & Scale(double factor)
矩形缩放
bool IsPoint() const
判断矩形是否为一个点
friend bool operator<=(const Rect &rect1, const Rect &rect2)
矩形类重载小于等于号
friend std::ostream & operator<<(std::ostream &out, const Rect &rect)
矩形类重载输出流运算符
friend bool operator>(const Rect &rect1, const Rect &rect2)
矩形类重载大于号
friend bool operator!=(const Rect &rect1, const Rect &rect2)
矩形类重载不等于号
bool Include(const Point< U > &pt, const Margin &margin=0, bool is_include_boundaries=true) const
判断所给点是否被矩形包含
#define Cm_Assert(expr, message)
断言宏
bool operator>=(const Interval &interval1, const Interval &interval2)
区间类重载大于等于号
bool operator!=(const Interval &interval1, const Interval &interval2)
区间类重载不等于号
Point< int > Point2i
整型坐标点类型
bool operator<(const Interval &interval1, const Interval &interval2)
区间类重载小于号
bool operator==(const Interval &interval1, const Interval &interval2)
区间类重载等于号
bool operator<=(const Interval &interval1, const Interval &interval2)
区间类重载小于等于号
std::ostream & operator<<(std::ostream &out, const Interval &interval)
区间类重载输出流运算符
bool operator>(const Interval &interval1, const Interval &interval2)
区间类重载大于号
size_t operator()(const Rect &rect) const
矩形类的哈希仿函数
Margin(int top, int right, int bottom, int left)
矩形外边距结构体的带参构造函数