Geometry Structure and Algorithm.#
Geometry Structure#
-
struct Radian#
Can easily get the degree of the radian conversion.
-
struct Vector2f#
浮点型向量
表示从原点(0,0)出发的一个具有大小和方向的浮点型向量.
-
struct Vector2i#
整型向量
表示从原点(0,0)出发的一个具有大小和方向的整型向量.
-
struct Point2f#
浮点型点
Public Types
-
using Elem = float#
Element type.
Public Functions
-
Point2f() = default#
Default constructor,no initialization.
-
using Elem = float#
-
struct Point2i#
整型点
Public Types
-
using Elem = int32_t#
Element type.
Public Functions
-
Point2i() = default#
Default constructor,no initialization.
-
using Elem = int32_t#
-
struct Line2f#
浮点型直线
Public Types
Public Functions
-
struct Line2i#
整型直线
Public Types
Public Functions
-
struct Ray2f#
浮点型射线
Public Types
Public Functions
-
struct Ray2i#
整型射线
Public Types
Public Functions
-
struct LineString2f : public std::vector<Point2f>#
浮点型线
一条线被认为是一些点的集合(std::vector),且按一定顺序连接相邻两点形成折线段.
Note
线可以是自交的,但这对于某些算法会产生错误的影响.可以通过 is_simple() 检测是否自交等问题.
-
struct LineString2i : public std::vector<Point2i>#
整型线
一条线被认为是一些点的集合(std::vector),且按一定顺序形成折线段.
Note
线可以是自交的,但这对于某些算法会产生错误的影响.可以通过 is_simple() 检测是否自交等问题.
-
struct Ring2f : public std::vector<Point2f>#
浮点型环
环是一条不应自交的闭合线,即不带孔的多边形. 应遵循从x轴正方向向y轴正方向描述环上的点,开包(第一点与最后一点不同).
Public Types
-
using LineString = LineString2f#
环对应的同类型线 convert()
-
using Rect = Rect2f#
环对应的同类型矩形 envelope()
-
using Ring = Ring2f#
用于统一与polygon的部分算法接口 convex_hull()
-
using LineString = LineString2f#
-
struct Ring2i : public std::vector<Point2i>#
整型环
环是一条不应自交的闭合线,即不带孔的多边形. 应遵循从x轴正方向向y轴正方向描述环上的点,开包(第一点与最后一点不同).
Public Types
-
using LineString = LineString2i#
环对应的同类型线 convert()
-
using Rect = Rect2i#
环对应的同类型矩形 envelope()
-
using Ring = Ring2i#
用于统一与polygon的部分算法接口 convex_hull()
-
using LineString = LineString2i#
-
struct Size2f#
Specify rect or image size.
Public Types
-
using Elem = float#
Element type.
Public Functions
-
using Elem = float#
-
struct Size2i#
Specify rect or image size.
Public Types
-
using Elem = uint32_t#
Element type.
Public Functions
-
using Elem = uint32_t#
-
struct Rect2f#
浮点型矩形
有一个角为直角的平行四边形,与坐标轴平行.
Public Types
-
using LineString = LineString2f#
矩形边对应类型的线段
Public Functions
-
Rect2f() = default#
Default constructor,no initialization.
-
Point xmin_ymin() const#
x最小,y最小顶点,同 min_corner.
-
using LineString = LineString2f#
-
struct Rect2i#
整型矩形
有一个角为直角的平行四边形,与坐标轴平行.
Public Types
-
using LineString = LineString2i#
矩形边对应类型的线段
Public Functions
-
Rect2i() = default#
Default constructor,no initialization.
-
Point xmin_ymin() const#
x最小,y最小顶点,同 min_corner.
-
using LineString = LineString2i#
-
struct Polygon2f#
浮点型多边形
多边形由一个外环和零个或多个内环组成,内环方向与外环相反,形成带孔或不带孔的多边形. 应遵循从x轴正方向向y轴正方向描述外环上的点,开包(第一点与最后一点不同).
Public Types
-
using Rect = Rect2f#
多边形对应的同类型矩形 envelope()
Public Functions
-
Polygon2f() = default#
Default constructor,creating an empty Polygon.
-
Polygon2f(const std::initializer_list<Ring> &rhs)#
Constructor taking std::initializer_list,filling the Polygon.
-
float area() const#
多边形面积
Warning
如果内环描述不正确,如与外环相同方向,则计算面积时会重复计算内环面积. 可以通过 correct() 来修正几何图形,以得到正确的期望结果. 内环相互相切或与外环相切时仍可以得到正确的多边形面积.
-
float perimeter() const#
多边形周长
Warning
如果内环互相相切,或与外环相切,则计算周长时会重复计算相切边长.
-
using Rect = Rect2f#
-
struct Polygon2i#
整型多边形
多边形由一个外环和零个或多个内环组成,内环方向与外环相反,形成带孔或不带孔的多边形. 应遵循从x轴正方向向y轴正方向描述外环上的点,开包(第一点与最后一点不同).
Public Types
-
using Rect = Rect2i#
多边形对应的同类型矩形 envelope()
Public Functions
-
Polygon2i() = default#
Default constructor,creating an empty Polygon.
-
Polygon2i(const std::initializer_list<Ring> &rhs)#
Constructor taking std::initializer_list,filling the Polygon.
-
float area() const#
多边形面积
Warning
如果内环描述不正确,如与外环相同方向,则计算面积时会重复计算内环面积. 可以通过 correct() 来修正几何图形,以得到正确的期望结果. 内环相互相切或与外环相切时仍可以得到正确的多边形面积.
-
float perimeter() const#
多边形周长
Warning
如果内环互相相切,或与外环相切,则计算周长时会重复计算相切边长.
-
using Rect = Rect2i#
-
struct RotateRect2f#
浮点型旋转矩形
有一个角为直角的平行四边形,不一定与坐标轴平行.
Public Types
-
using LineString = LineString2f#
旋转矩形边对应类型的线段
-
using Rect = Rect2f#
旋转矩形对应的同类型矩形 envelope()
Public Functions
-
RotateRect2f() = default#
Default constructor,no initialization.
-
RotateRect2f(const Point &min_corner, const float &w, const float &h, const Radian &radian = Radian())#
y最小点,宽,高和方位角描述旋转矩形.
-
Point ymin() const#
y最小点,同 min_corner.
-
float area() const#
旋转矩形面积
-
float perimeter() const#
旋转矩形周长
-
using LineString = LineString2f#
-
struct RotateRect2i#
整型旋转矩形
有一个角为直角的平行四边形,不一定与坐标轴平行.
Public Types
-
using LineString = LineString2i#
旋转矩形边对应类型的线段
-
using Rect = Rect2i#
旋转矩形对应的同类型矩形 envelope()
Public Functions
-
RotateRect2i() = default#
Default constructor,no initialization.
-
RotateRect2i(const Point &min_corner, const float &w, const float &h, const Radian &radian = Radian())#
y最小点,宽,高和方位角描述旋转矩形.
-
Point ymin() const#
y最小点,同 min_corner.
-
float area() const#
旋转矩形面积
-
float perimeter() const#
旋转矩形周长
-
using LineString = LineString2i#
-
struct Arc2f#
浮点型弧
-
struct Arc2i#
整型弧
-
struct Circle2f#
浮点型圆
-
struct Circle2i#
整型圆
-
class Matrix3f#
3x3 float matrix.
Transformation matrix.
Public Functions
-
explicit Matrix3f(float diag = 1)#
Construct a 3*3 float matrix.
The value of the principal diagonal is diag, the rest are 0.
- Parameters:
diag – The principal diagonal value. If rhs is 1(As default), it will construct a identity matrix.
-
Matrix3f(float mat_0_0, float mat_0_1, float mat_0_2, float mat_1_0, float mat_1_1, float mat_1_2, float mat_2_0, float mat_2_1, float mat_2_2)#
Construct a 3*3 float matrix.
Read parameters in first row the col order.
-
Matrix3f(const Matrix3f &rhs)#
Deep copy constructor.
It will not share the same references as the source object.
- Parameters:
rhs – other Matrix3f.
-
Matrix3f operator*(const Matrix3f &rhs) const#
Matrix multiplication.
A * B = C.
- Parameters:
rhs – B matrix.
- Returns:
Matrix3f C matrix.
-
float &at(size_t row, size_t col)#
Return a reference to the specified array element.
if row or col out of range, an aidi::excepts::InvalidArgument will be thrown.
- Parameters:
row – Index along the dimension 1.
col – Index along the dimension 2.
- Throws:
aidi::excepts::InvalidArgument – if row or col out of range.
- Returns:
NO_DISCARD float& array element.
-
float at(size_t row, size_t col) const#
Return the specified array element.
if row or col out of range, an aidi::excepts::InvalidArgument will be thrown.
- Parameters:
row – Index along the dimension 1.
col – Index along the dimension 2.
- Throws:
aidi::excepts::InvalidArgument – if row or col out of range.
- Returns:
NO_DISCARD float array element.
-
explicit Matrix3f(float diag = 1)#
-
enum aidi::geometry::GeoIsSampleFailType#
The enumeration GeoIsSampleFailType enumerates the possible reasons for which a geometry may be found as not simple or invalid by the is_simple() and is_valid() algorithms.
Values:
-
enumerator kNoFailure = 0#
The geometry is simple/valid.
-
enumerator kEmpty = 1#
The geometry is empty.
-
enumerator kDuplicatePoints = 2#
The geometry has (consecutive) duplicate points.
-
enumerator kSpikes = 4#
The geometry contains spikes.
-
enumerator kSelfIntersections = 8#
The geometry has self-intersections.
-
enumerator kPolygonOuterFailure = 16#
The exterior ring of geometry is not simple/valid.
-
enumerator kPolygonInnersFailure = 32#
The interior rings of geometry is not simple/valid.
-
enumerator kFewPoints = 64#
The geometry has a very small number of points.
-
enumerator kWrongTopologicalDimension = 128#
The topological dimension of the geometry is smaller than its dimension.
-
enumerator kInvalidCoordinate = 256#
The geometry has at least one point with an invalid coordinate.
-
enumerator kWrongOrientation = 512#
The actual orientation of the geometry is different from the one defined.
-
enumerator kInteriorRingsOutside = 1024#
The geometry contains interior rings that lie outside the exterior ring.
-
enumerator kNestedInteriorRings = 2048#
The geometry has nested interior rings.
-
enumerator kNoFailure = 0#
Geometry algorithms#
-
template<typename LinearOrAreal, typename MultiPointOrPoint>
void aidi::geometry::append(LinearOrAreal &lhs, const MultiPointOrPoint &rhs)# 几何图形的数据扩展
LinearOrAreal
MultiPointOrPoint
LineString
点集或单点
Ring
点集或单点
Polygon
体现在外环和内环上
MultiPoint
点集或单点
- Template Parameters:
LinearOrAreal – 可扩展的几何图形
MultiPointOrPoint – 点集或单点
- Parameters:
lhs – [inout]
rhs –
-
template<typename Areal>
float aidi::geometry::area(const Areal &rhs)# 多边形的面积
Warning
多边形的内环方向以及数据是否遵循约定方向等会对结果产生影响.
- Template Parameters:
Areal – 多边形,矩形以及圆
- Parameters:
rhs –
Areal
Ring
Polygon
Rect
RotateRect
Circle
MultiPolygon
- Returns:
NO_DISCARD float 浮点型面积
-
int32_t aidi::geometry::area(const Rect2i &rhs)#
整型矩形面积
- Parameters:
rhs – Rect2i
- Returns:
NO_DISCARD int32_t 整型面积
-
template<typename Point>
bool aidi::geometry::operator==(const typename Point::Vector &lhs, const Point &rhs)# 点和向量之间的数值比较
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 点对应的同类型向量
rhs – 点
- Returns:
true 点与向量数值上相等.
- Returns:
false 点与向量数值上不等.
-
template<typename Point>
Point aidi::geometry::operator+(const typename Point::Vector &lhs, const Point &rhs)# 向量+点=点
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 点对应的同类型向量
rhs – 点
- Returns:
Point 结果不改变点的类型
-
Point2f aidi::geometry::operator+(const Point2i &lhs, const Vector2f &rhs)#
整型点+浮点型向量=浮点型点
- Parameters:
lhs – 整型点
rhs – 浮点型向量
- Returns:
Point2f 浮点型点
-
template<typename Point>
Point::Vector aidi::geometry::operator-(const Point &lhs, const Point &rhs)# 点-点=向量
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被减点
rhs – 减点
- Returns:
Point::Vector 点对应的同类型向量
-
Point2f aidi::geometry::operator-(const Point2i &lhs, const Vector2f &rhs)#
整型点-浮点型向量=浮点型点
- Parameters:
lhs – 整型点
rhs – 浮点型向量
- Returns:
Point2f 浮点型点
-
Vector2f aidi::geometry::operator-(const Point2i &lhs, const Point2f &rhs)#
整型点-浮点型点=浮点型向量
- Parameters:
lhs – 整型点
rhs – 浮点型点
- Returns:
Vector2f 浮点型向量
-
Vector2f aidi::geometry::operator-(const Point2f &lhs, const Point2i &rhs)#
浮点型-整形点=浮点型向量
- Parameters:
lhs – 浮点型点
rhs – 整形点
- Returns:
Vector2f 浮点型向量
-
template<typename PointLike>
PointLike aidi::geometry::operator*(const typename PointLike::Elem &lhs, const PointLike &rhs)# 点和向量的放大
- Template Parameters:
PointLike – 任意类型的点或向量
- Parameters:
lhs – 点或向量的Elem
rhs – 点或向量
- Returns:
PointLike 结果不改变点或向量的类型
-
Point2f aidi::geometry::operator*(const Point2i &lhs, const float &rhs)#
整型点*浮点数=浮点型点
- Parameters:
lhs – 整形点
rhs – 浮点数
- Returns:
Point2f 浮点型点
-
Vector2f aidi::geometry::operator*(const Vector2i &lhs, const float &rhs)#
整型向量*浮点数=浮点型向量
- Parameters:
lhs – 整型向量
rhs – 浮点数
- Returns:
Vector2f 浮点型向量
-
template<typename Point>
void aidi::geometry::add_point(Point &lhs, const Point &rhs)# 将第一个点的值加上第二个
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的第一个点
rhs – 同类型的第二个点不发生变化
-
template<typename Point>
void aidi::geometry::add_value(Point &lhs, const typename Point::Elem &rhs)# 将一个点的坐标加上相同值
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的点
rhs – 点对应的同类型值
-
template<typename Point>
Point::Elem aidi::geometry::cross_product(const Point &lhs, const Point &rhs)# 向量积,叉积
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 点
rhs – 同类型的点
- Returns:
NO_DISCARD 点对应的同类型值
-
template<typename Point>
void aidi::geometry::divide_point(Point &lhs, const Point &rhs)# 将第一个点除以第二个点
Note
注意int和float不同产生的结果.
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的第一个点
rhs – 同类型的第二个点不发生变化
-
template<typename Point>
void aidi::geometry::divide_value(Point &lhs, const typename Point::Elem &rhs)# 将一个点的坐标除以相同值
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的点
rhs – 点对应的同类型值
-
template<typename PointLike>
PointLike::Elem aidi::geometry::dot_product(const PointLike &lhs, const PointLike &rhs)# 数量积,点积
- Template Parameters:
PointLike – 任意类型的点或向量
- Parameters:
lhs – 点或向量
rhs – 同类型的点或向量
- Returns:
NO_DISCARD 点或向量对应的同类型的值
-
template<typename Point>
void aidi::geometry::multiply_point(Point &lhs, const Point &rhs)# 将第一个点乘以第二个点
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的第一个点
rhs – 同类型的第二个点不发生变化
-
template<typename Point>
void aidi::geometry::multiply_value(Point &lhs, const typename Point::Elem &rhs)# 将一个点的坐标乘以相同值
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的点
rhs – 点对应的同类型值
-
template<typename Point>
void aidi::geometry::subtract_point(Point &lhs, const Point &rhs)# 将第一个点减去第二个点
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的第一个点
rhs – 同类型的第二个点不发生改变
-
template<typename Point>
void aidi::geometry::subtract_value(Point &lhs, const typename Point::Elem &rhs)# 将一个点的坐标减去相同值
- Template Parameters:
Point – 任意类型的点
- Parameters:
lhs – 被改变的点
rhs – 点对应的同类型值
-
template<typename PointLike>
Radian aidi::geometry::azimuth(const PointLike &lhs, const PointLike &rhs)# 线段的方位角
- Template Parameters:
PointLike – 任意类型的点或向量
- Parameters:
lhs – 点或向量
rhs – 同类型的点或向量
- Returns:
NO_DISCARD 两点形成线段从x轴正方向向y轴正方向旋转的弧度(±𝝅)
-
template<typename Vector>
Radian aidi::geometry::azimuth(const Vector &rhs)# 向量的方位角
- Template Parameters:
Vector – 任意类型的向量
- Parameters:
rhs – 向量
- Returns:
NO_DISCARD 原点(0,0)到向量所形成线段的方位角弧度(±𝝅)
-
template<typename Areal>
Point2f aidi::geometry::center(const Areal &rhs)# 多边形中心,即外接平行矩形的中心
- Template Parameters:
Areal – 多边形,矩形和圆.
- Parameters:
rhs –
Areal
Ring
Polygon
Rect
RotateRect
Circle
- Returns:
NO_DISCARD 浮点型点
-
Point2i aidi::geometry::center(const Circle2i &rhs)#
整型圆的中心
- Parameters:
rhs – 整型圆
- Returns:
NO_DISCARD 整型点,即圆心.
-
template<typename Areal>
Point2f aidi::geometry::centroid(const Areal &rhs)# 多边形质心
- Template Parameters:
Areal – 多边形,矩形和圆
- Parameters:
rhs –
Areal
Ring
Polygon
Rect
RotateRect
Circle
- Returns:
NO_DISCARD 浮点型点
-
Point2i aidi::geometry::centroid(const Circle2i &rhs)#
整型圆质心
- Parameters:
rhs – 整型圆
- Returns:
NO_DISCARD 整形点,即圆心
-
template<typename LinearOrAreal>
void aidi::geometry::clear(LinearOrAreal &rhs)# 清空几何图形数据
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
rhs –
LinearOrAreal
LineString
Ring
Polygon
MultiPoint
MultiPolygon
-
template<typename Geometry1, typename Geometry2>
void aidi::geometry::convert(const Geometry1 &lhs, Geometry2 &rhs)# 几何图形之间的转换
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
×
×
×
×
×
×
×
√
LineString
×
√
√
√
×
×
×
×
×
Ring
×
√
√
√
×
×
×
×
×
Polygon
×
×
×
√
×
×
×
×
×
Rect
×
×
√
√
√
×
×
×
×
RotateRect
×
×
√
√
×
×
×
×
×
Arc
×
×
×
×
×
×
×
√
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
-
template<typename Areal>
void aidi::geometry::convex_hull(const Areal &lhs, typename Areal::Ring &rhs)# 多边形的凸包
Note
新的凸包将以x最小的点为起点,从x轴正方向向y轴正方向顺序排列.
- Template Parameters:
Areal – 多边形
- Parameters:
lhs, rhs –
Areal
Ring
Polygon
-
template<typename Areal>
Areal::Ring aidi::geometry::return_convex_hull(const Areal &lhs)# 多边形的凸包
See also
-
template<typename Areal>
void aidi::geometry::correct(Areal &rhs)# 修正多边形的约定顺序和约定开闭包形式.
- Template Parameters:
Areal – 多边形
- Parameters:
rhs –
Areal
Ring
Polygon
-
template<typename Areal>
Areal aidi::geometry::return_correct(const Areal &rhs)# 修正多边形的约定顺序和约定开闭包形式.
See also
-
template<typename Geometry1, typename Geometry2>
bool aidi::geometry::covered_by(const Geometry1 &lhs, const Geometry2 &rhs)# 第一个几何图形是否被第二个几何图形覆盖
The difference with the within algorithm is that this algorithm checks the border by default.
See also
Note
边界有交集仍然会被认为是覆盖.
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
√
√
√
√
√
×
√
×
LineString
×
√
√
√
√
√
×
×
×
Ring
×
×
√
√
√
√
×
×
×
Polygon
×
×
√
√
√
√
×
×
×
Rect
×
×
√
√
√
√
×
×
×
RotateRect
×
×
√
√
√
√
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
√
×
Vector
×
×
×
×
×
×
×
×
×
- Returns:
NO_DISCARD bool
-
template<typename Linear, typename Geometry>
bool aidi::geometry::crosses(const Linear &lhs, const Geometry &rhs)# 第一个线是否穿过第二个几何图形
See also
Note
如果没能穿过边界,则会被视为覆盖.
- Template Parameters:
Linear – 线
Geometry – 几何图形
- Parameters:
lhs, rhs –
Geometry
Point
LineString
Ring
Polygon
Rect
RotateRect
Circle
- Returns:
NO_DISCARD bool
-
template<typename Areal1, typename Areal2, typename MultiPolygon>
void aidi::geometry::difference(const Areal1 &lhs, const Areal2 &rhs, MultiPolygon &result)# 多边形之间的差集
Note
算法并不会清空MultiPolygon中已有的数据,而是将结果添加进MultiPolygon.
Warning
对于整型几何图形的差集结果存在交点为浮点型时,会产生一定的问题.
- Template Parameters:
Areal1 – 多边形,矩形
Areal2 – 多边形,矩形
MultiPolygon – 多多边形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
×
×
×
×
×
×
×
×
×
LineString
×
×
×
×
×
×
×
×
×
Ring
×
×
√
√
√
√
×
×
×
Polygon
×
×
√
√
√
√
×
×
×
Rect
×
×
√
√
√
√
×
×
×
RotateRect
×
×
√
√
√
√
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
result – 多多边形,多边形之间的差集.
-
template<typename Linear1, typename Linear2>
float aidi::geometry::discrete_frechet_distance(const Linear1 &lhs, const Linear2 &rhs)# 线之间的frechet距离
几何图形之间最大的最短距离,用于描述相似度.
- Template Parameters:
Linear1 – 线
Linear2 – 同类型的线
- Returns:
NO_DISCARD float
-
template<typename Geometry1, typename Geometry2>
bool aidi::geometry::disjoint(const Geometry1 &lhs, const Geometry2 &rhs)# 几何图形是否相离
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
√
√
√
√
√
×
√
×
LineString
√
√
√
√
√
√
×
√
×
Ring
√
√
√
√
√
√
×
√
×
Polygon
√
√
√
√
√
√
×
√
×
Rect
√
√
√
√
√
√
×
√
×
RotateRect
√
√
√
√
√
√
×
√
×
Arc
×
×
×
×
×
×
×
×
×
Circle
√
√
√
√
√
√
×
√
×
Vector
×
×
×
×
×
×
×
×
×
- Returns:
NO_DISCARD bool
-
template<typename Geometry1, typename Geometry2>
float aidi::geometry::distance(const Geometry1 &lhs, const Geometry2 &rhs)# 几何图形之间的距离
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
√
√
√
√
√
×
√
×
LineString
√
√
√
√
√
√
×
√
×
Ring
√
√
√
√
√
√
×
√
×
Polygon
√
√
√
√
√
√
×
√
×
Rect
√
√
√
√
√
√
×
√
×
RotateRect
√
√
√
√
√
√
×
√
×
Arc
×
×
×
×
×
×
×
×
×
Circle
√
√
√
√
√
√
×
√
×
Vector
×
×
×
×
×
×
×
×
×
- Returns:
NO_DISCARD float
-
template<typename LinearOrAreal>
void aidi::geometry::envelope(const LinearOrAreal &lhs, typename LinearOrAreal::Rect &rhs)# 最小外接矩形
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
lhs, rhs –
LinearOrAreal
LineString
Ring
Polygon
RotateRect
-
template<typename LinearOrAreal>
LinearOrAreal::Rect aidi::geometry::return_envelope(const LinearOrAreal &rhs)# 最小外接矩形
See also
-
template<typename Geometry1, typename Geometry2>
bool aidi::geometry::equals(const Geometry1 &lhs, const Geometry2 &rhs)# 几何图形是否相等
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
×
×
×
×
×
×
×
√
LineString
×
√
×
×
×
×
×
×
×
Ring
×
×
√
√
√
√
×
×
×
Polygon
×
×
√
√
√
√
×
×
×
Rect
×
×
√
√
√
√
×
×
×
RotateRect
×
×
√
√
√
√
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
√
×
Vector
√
×
×
×
×
×
×
×
√
- Returns:
NO_DISCARD bool
-
template<typename Geometry1, typename Geometry2, typename GeometryOut>
void aidi::geometry::intersection(const Geometry1 &lhs, const Geometry2 &rhs, GeometryOut &result)# 几何图形之间的交集
Warning
对于整型几何图形的交集结果存在交点为浮点型时,会产生一定的问题.
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
GeometryOut – 点集或多多边形
- Parameters:
lhs, rhs – [in]
result – [out] The intersection of geo1 and geo2
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
√
√
√
√
√
×
×
×
LineString
√
√
√
√
×
√
×
×
×
Ring
√
√
√
√
×
√
×
×
×
Polygon
√
√
√
√
×
√
×
×
×
Rect
×
×
×
×
×
×
×
×
×
RotateRect
×
×
×
×
×
×
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
-
template<typename Geometry1, typename Geometry2>
bool aidi::geometry::intersects(const Geometry1 &lhs, const Geometry2 &rhs)# 几何图形是否相交(存在至少一个交点)
- Template Parameters:
Geometry1 – 几何图形
Geometry2 – 同类型的几何图形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
√
√
√
√
√
×
√
×
LineString
√
√
√
√
√
√
×
√
×
Ring
√
√
√
√
√
√
×
√
×
Polygon
√
√
√
√
√
√
×
√
×
Rect
√
√
√
√
√
√
×
√
×
RotateRect
√
√
√
√
√
√
×
√
×
Arc
×
×
×
×
×
×
×
×
×
Circle
√
√
√
√
√
√
×
√
×
Vector
×
×
×
×
×
×
×
×
×
-
template<typename LinearOrAreal>
bool aidi::geometry::is_empty(const LinearOrAreal &rhs)# 判断几何图形是否为空
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
rhs –
LinearOrAreal
LineString
Ring
Polygon
MultiPoint
MultiPolygon
-
template<typename LinearOrAreal>
bool aidi::geometry::is_simple(const LinearOrAreal &rhs)# 判断几何图形是否是简单几何图形
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
rhs –
LinearOrAreal
LineString
Ring
Polygon
- Returns:
Linear:非空,没有重复点,不自交,没有尖峰.
- Returns:
Areal:非空,没有重复点.
-
template<typename LinearOrAreal>
GeoIsSampleFailType aidi::geometry::return_is_simple(const LinearOrAreal &rhs)# 判断几何图形是否是简单几何图形
See also
See also
- Template Parameters:
LinearOrAreal – 线或多边形
- Returns:
NO_DISCARD GeoIsSampleFailType 几何图形不为简单几何图形的错误信息
-
template<typename LinearOrAreal>
bool aidi::geometry::is_valid(const LinearOrAreal &rhs)# 判断几何图形数据是否有效
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
rhs –
LinearOrAreal
LineString
Ring
Polygon
- Returns:
Linear:没有无效点,至少有两个点,满足拓扑维数(存在至少两个不相同点),可以有尖峰.
- Returns:
Ring:没有无效点,至少有三个点(闭包四个点),满足拓扑维数(存在至少三个不相同点), 可以有重复点,没有尖峰,没有自交,满足数据顺序定义.
- Returns:
Polygon:外环内环都是有效的,多边形不自交,内环在外环内,内环不存在嵌套.
-
template<typename LinearOrAreal>
int32_t aidi::geometry::return_is_valid(const LinearOrAreal &rhs)# 判断几何图形数据是否有效
See also
See also
failure_type
- Template Parameters:
LinearOrAreal – 线或多边形
- Returns:
NO_DISCARD int32_t 几何图形数据失效的错误信息
-
template<typename LinearOrVector>
float aidi::geometry::length(const LinearOrVector &rhs)# 几何图形的长度
- Template Parameters:
LinearOrVector – 线或向量
- Parameters:
rhs –
LinearOrVector
LineString
Vector
- Returns:
NO_DISCARD float
-
template<typename Linear, typename MultiPointOrPoint>
void aidi::geometry::line_interpolate(const Linear &lhs, const float &rhs, MultiPointOrPoint &result)# 线上的线性插值
Warning
对于整型线的插值结果存在浮点型时,会产生一定的问题.
- Template Parameters:
Linear – 线
MultiPointOrPoint – 点集或单点
- Parameters:
lhs – 线
rhs – 插值点之间的距离
result – 单点则为起点起插值的第一个点,点集则是全部点.
-
template<typename Areal>
void aidi::geometry::min_area_rect(const Areal &lhs, RotateRect2f &rhs)# 最小面积外接矩形
- Template Parameters:
Areal – 多边形
RotateRect – 同类型的旋转矩形
- Parameters:
lhs, rhs –
Areal
Ring
Polygon
-
template<typename Areal>
RotateRect2f aidi::geometry::return_min_area_rect(const Areal &rhs)# 最小面积外接矩形
See also
-
template<typename Areal1, typename Areal2>
bool aidi::geometry::overlaps(const Areal1 &lhs, const Areal2 &rhs)# 多边形是否有重叠部分
- Template Parameters:
Areal1 – 多边形
Areal2 – 同类型的多边形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
×
×
×
×
×
×
×
×
×
LineString
×
×
×
×
×
×
×
×
×
Ring
×
×
√
√
×
×
×
×
×
Polygon
×
×
√
√
×
×
×
×
×
Rect
×
×
×
×
√
×
×
×
×
RotateRect
×
×
×
×
×
×
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
- Returns:
NO_DISCARD bool
-
template<typename Areal>
float aidi::geometry::perimeter(const Areal &rhs)# 几何图形的周长
- Template Parameters:
Areal – 多边形的周长
- Parameters:
rhs –
Areal
Ring
Polygon
Rect
RotateRect
Circle
-
int32_t aidi::geometry::perimeter(const Rect2i &rhs)#
整型矩形的周长
- Parameters:
rhs – 整型矩形
- Returns:
NO_DISCARD int32_t 整型周长
-
template<typename LinearOrAreal>
void aidi::geometry::reverse(LinearOrAreal &rhs)# 翻转几何图形数据顺序
Note
The reverse of a (multi)polygon or ring might make a valid geometry invalid because the (counter)clockwise orientation reverses.
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
rhs –
LinearOrAreal
LineString
Ring
Polygon
-
template<typename LinearOrAreal>
LinearOrAreal aidi::geometry::return_reverse(const LinearOrAreal &rhs)# 翻转几何图形数据顺序
See also
-
template<typename LinearOrAreal>
void aidi::geometry::simplify(LinearOrAreal &lhs, const float &rhs)# 简化几何图形
采用Douglas-Peucker算法进行多边形逼近,小于阈值则被删除.
Warning
结果会被强制改为闭包.
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
lhs – 线或多边形
rhs – 阈值
-
template<typename LinearOrAreal>
LinearOrAreal aidi::geometry::return_simplify(const LinearOrAreal &lhs, const float &rhs)# 简化几何图形
See also
-
template<typename Areal1, typename Areal2, typename ArealOut>
void aidi::geometry::sym_difference(const Areal1 &lhs, const Areal2 &rhs, ArealOut &result)# 几何图形之间的对称差
Warning
对于整型几何图形的对称差结果存在交点为浮点型时,会产生一定的问题.
Warning
几何结构不遵守约定顺序可能会产生一定的问题.
- Template Parameters:
Areal1 – 多边形
Areal2 – 同类型的多边形
ArealOut – 多多边形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
×
×
×
×
×
×
×
×
×
LineString
×
×
×
×
×
×
×
×
×
Ring
×
×
√
√
×
×
×
×
×
Polygon
×
×
√
√
×
×
×
×
×
Rect
×
×
×
×
×
×
×
×
×
RotateRect
×
×
×
×
×
×
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
result – 同类型的多多边形
-
template<typename Areal1, typename Areal2>
bool aidi::geometry::touches(const Areal1 &lhs, const Areal2 &rhs)# 几何图形之间是否触及(相切,不重叠)
- Template Parameters:
Areal1 – 多边形
Areal2 – 同类型的多边形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
×
×
×
×
×
×
×
×
×
LineString
×
×
×
×
×
×
×
×
×
Ring
×
×
√
√
×
×
×
×
×
Polygon
×
×
√
√
×
×
×
×
×
Rect
×
×
×
×
×
×
×
×
×
RotateRect
×
×
×
×
×
×
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
- Returns:
NO_DISCARD bool
-
template<typename Areal1, typename Areal2, typename ArealOut>
void aidi::geometry::union_areal(const Areal1 &lhs, const Areal2 &rhs, ArealOut &result)# 多边形之间的并集
Warning
对于整型几何图形的并集结果存在交点为浮点型时,会产生一定的问题.
- Template Parameters:
Areal1 – 多边形
Areal2 – 同类型的多边形
ArealOut – 多多边形
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
×
×
×
×
×
×
×
×
×
LineString
×
×
×
×
×
×
×
×
×
Ring
×
×
√
√
×
×
×
×
×
Polygon
×
×
√
√
×
×
×
×
×
Rect
×
×
×
×
×
×
×
×
×
RotateRect
×
×
×
×
×
×
×
×
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
×
×
×
×
×
×
×
Vector
×
×
×
×
×
×
×
×
×
result – 同类型的多多边形
-
template<typename LinearOrAreal>
void aidi::geometry::unique(LinearOrAreal &rhs)# 去除几何图形中重复节点
- Template Parameters:
LinearOrAreal – 线或多边形
- Parameters:
rhs –
LinearOrAreal
LineString
Ring
Polygon
-
template<typename LinearOrAreal>
LinearOrAreal aidi::geometry::return_unique(const LinearOrAreal &rhs)# 去除几何图形中重复节点
See also
-
template<typename Geometry1, typename Geometry2>
bool aidi::geometry::within(const Geometry1 &lhs, const Geometry2 &rhs)# 第一个几何图形是否在第二个几何图形内部
- Template Parameters:
Geometry1 – 几何图形
Geometry2 –
- Parameters:
lhs, rhs –
lhs/rhs
Point
LineString
Ring
Polygon
Rect
RotateRect
Arc
Circle
Vector
Point
√
√
√
√
√
√
×
√
×
LineString
×
√
√
√
√
√
×
√
×
Ring
×
×
√
√
√
√
×
√
×
Polygon
×
×
√
√
√
√
×
√
×
Rect
×
×
√
√
√
√
×
√
×
RotateRect
×
×
√
√
√
√
×
√
×
Arc
×
×
×
×
×
×
×
×
×
Circle
×
×
√
√
√
√
×
√
×
Vector
×
×
×
×
×
×
×
×
×
- Returns:
NO_DISCARD bool
-
template<typename Geometry>
Geometry aidi::geometry::transform_rotate(const Geometry &geometry, Radian radian)# Geometry rotate transform.
Cartesian coordinate system(the origin of the first quadrant is in
the lower left corner), the matrix is rotated clockwise in radians.
- Parameters:
geometry – Geometry.
Geometry
Point
LineString
Ring
Polygon
RotateRect
Vector
Segment
MultiPoint
MultiPolygon
radian – Rotation radian.
- Returns:
NO_DISCARD the result is consistent with the input geometry.
-
RotateRect2f aidi::geometry::transform_rotate(const Rect2f &rect, Radian radian)#
Geometry rotate transform.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
rect – Rect.
radian – Rotation radian.
- Returns:
NO_DISCARD the result is RotateRect.
-
template<typename Geometry>
Geometry aidi::geometry::transform_scale(const Geometry &geometry, float ratiox, float ratioy)# Geometry scale transform.
- Parameters:
geometry – Geometry.
Geometry
Point
LineString
Ring
Polygon
Rect
Vector
Segment
MultiPoint
MultiPolygon
ratiox – Scaling ratio direction-x.
ratioy – Scaling ratio direction-y.
- Returns:
NO_DISCARD the result is consistent with the input geometry.
-
Ring2f aidi::geometry::transform_scale(const RotateRect2f &rotate_rect, float ratiox, float ratioy)#
Geometry scale transform.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
rotate_rect – RotateRect.
ratiox – Scaling ratio direction-x.
ratioy – Scaling ratio direction-y.
- Returns:
NO_DISCARD the result is Ring.
-
template<typename Geometry>
Geometry aidi::geometry::transform_translate(const Geometry &geometry, float directx, float directy)# Geometry translate transform.
- Parameters:
geometry – Geometry.
Geometry
Point
LineString
Ring
Polygon
Rect
RotateRect
Vector
Segment
MultiPoint
MultiPolygon
directx – Translation transform direction-x.
directy – Translation transform direction-y.
- Returns:
NO_DISCARD the result is consistent with the input geometry.
-
template<typename Geometry>
Geometry aidi::geometry::transform(const Geometry &geometry, const Matrix3f &mat)# Geometry transform.
transform(geometry, step1), transform(geometry, step2) -> transform(geometry, step2 * step1).
- Parameters:
geometry – Geometry.
Geometry
Point
LineString
Ring
Polygon
Vector
Segment
MultiPoint
MultiPolygon
mat – Transformation matrix.
- Returns:
NO_DISCARD the result is consistent with the input geometry.
-
Ring2f aidi::geometry::transform(const Rect2f &rect, const Matrix3f &mat)#
Geometry transform.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
rect – Rect.
mat – Transformation matrix.
- Returns:
NO_DISCARD the result is Ring.
-
Ring2f aidi::geometry::transform(const RotateRect2f &rotate_rect, const Matrix3f &mat)#
Geometry transform.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
rotate_rect – RotateRect.
mat – Transformation matrix.
- Returns:
NO_DISCARD the result is Ring.
-
Matrix3f aidi::geometry::get_affine_transform(const std::vector<Point2f> &src, const std::vector<Point2f> &dst)#
Calculate an affine transform from three pairs of the corresponding points.
If the number of point pairs is less than 3, an aidi::excepts::InvalidArgument will be thrown.
- Parameters:
src – Coordinate of triangle vertices in the source image.
dst – Coordinate of the corresponding triangle vertices in the destination image.
- Throws:
aidi::excepts::InvalidArgument – if the number of point pairs is less than requirement.
- Returns:
NO_DISCARD transformation matrix.
-
Matrix3f aidi::geometry::get_perspective_transform(const std::vector<Point2f> &src, const std::vector<Point2f> &dst)#
Calculate a perspective transform from four pairs of the corresponding points.
If the number of point pairs is less than 4, an aidi::excepts::InvalidArgument will be thrown.
- Parameters:
src – Coordinate of quadrangle vertices in the source image.
dst – Coordinate of the corresponding quadrangle vertices in the destination image.
- Throws:
aidi::excepts::InvalidArgument – if the number of point pairs is less than requirement.
- Returns:
NO_DISCARD transformation matrix.
-
Matrix3f aidi::geometry::get_inverse_transform(const Matrix3f &mat)#
Get inverse transform matrix.
- Parameters:
mat – Source matrix.
- Returns:
NO_DISCARD inverse transform matrix.
-
Matrix3f aidi::geometry::get_rotate_transform(Radian radian)#
Get rotate transform matrix.
- Parameters:
radian – Rotation radian.
- Returns:
NO_DISCARD rotate transform matrix.
-
Matrix3f aidi::geometry::get_scale_transform(float ratiox, float ratioy)#
Get scale transform matrix.
- Parameters:
ratiox – Scaling ratio direction-x.
ratioy – Scaling ratio direction-y.
- Returns:
NO_DISCARD scale transform matrix.
-
Matrix3f aidi::geometry::get_translate_transform(float directx, float directy)#
Get translate transform matrix.
- Parameters:
directx – Translation transform direction-x.
directy – Translation transform direction-y.
- Returns:
NO_DISCARD translate transform matrix
-
using aidi::geometry::MultiPoint2f::Point = Point2f#
-
using aidi::geometry::MultiPoint2i::Point = Point2i#
-
using aidi::geometry::MultiPolygon2f::Polygon = Polygon2f#
-
using aidi::geometry::MultiPolygon2i::Polygon = Polygon2i#