From 27fc91fbe8f88b6885356e68828cfe1ce1db7601 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期三, 28 二月 2024 09:53:13 +0800 Subject: [PATCH] 坐标 --- lib/src/main/cpp/test_common/Geometry.h | 85 +++++++++++++++++++++++++++++++++++------- 1 files changed, 71 insertions(+), 14 deletions(-) diff --git a/lib/src/main/cpp/test_common/Geometry.h b/lib/src/main/cpp/test_common/Geometry.h index 08947b9..f2cf553 100644 --- a/lib/src/main/cpp/test_common/Geometry.h +++ b/lib/src/main/cpp/test_common/Geometry.h @@ -17,37 +17,94 @@ GM_Containment } relation_t; -typedef struct PointF_ { +typedef struct { double X; double Y; } PointF; -typedef struct Line_ { +/*typedef struct { double X1; double Y1; double X2; double Y2; +} Line;*/ + +typedef struct { + PointF p1; + PointF p2; } Line; -typedef struct Polygon_ { - int num; - PointF *point; +typedef struct { + int num = 0; + PointF *point = nullptr; } Polygon; -typedef struct Circle_ { +typedef struct { PointF centre; double radius; } Circle; -#define MAKE_LINE(a, b, c) { (a).X1=b.X; (a).Y1=b.Y; (a).X2=c.X; (a).Y2=c.Y; } +//#define MAKE_LINE(a, b, c) { a.X1=b.X; a.Y1=b.Y; a.X2=c.X; a.Y2=c.Y; } +void MAKE_LINE(Line &a, PointF &b, PointF &c); - double toRadians(double degree); - double toDegree(double radians); - bool isEqual(double a, double b); - bool isEqual2(double a, double b); +double toRadians(double degree); +double toDegree(double radians); +bool isEqual(double a, double b); +bool isEqual2(double a, double b); -void MakeLine(Line *line, const PointF *p1, const PointF *p2); -void MakePolygon(Polygon *polygon, std::initializer_list<PointF> point_set); +class MakePolygon { +public: + MakePolygon(std::initializer_list<PointF> points) { + polygon.num = 0; + if (points.size() > 0) { + polygon.point = new PointF[points.size()]; + int n = 0; + for (auto ptr: points) { + polygon.point[n++] = ptr; + } + polygon.num = n; + } + } + MakePolygon(int pre_num) { + polygon.num = 0; + polygon.point = new PointF[pre_num]; + } + + ~MakePolygon() { + if (polygon.point != nullptr) { + delete []polygon.point; + } + } + + void AddPoints(std::initializer_list<PointF> points) { + if (polygon.point != nullptr) { + delete []polygon.point; + } + polygon.num = 0; + if (points.size() > 0) { + int n = 0; + polygon.point = new PointF[points.size()]; + for (auto p: points) { + polygon.point[n++] = p; + } + polygon.num = n; + } + } + + void AddPoint(PointF &point) { + polygon.point[polygon.num] = point; + polygon.num++; + } + + Polygon *GetPolygon(void) { + return &polygon; + } + +private: + Polygon polygon; +}; + +//void MakePolygon(Polygon *polygon, std::initializer_list<PointF> point_set); void CleanPolygon(Polygon *polygon); void MakeHidePoint(PointF *point, const PointF *bp, const Line *bl); @@ -83,7 +140,7 @@ PointF GetVerticalPoint(PointF p1, PointF p2, PointF p3); bool VerticalPointOnLine(PointF point, Line line); bool VerticalPointOnLine(PointF point, Line line, PointF &vp); -PointF Calc3Point(PointF p1, PointF p2, double L, char dir); +PointF Calc3Point(PointF p1, PointF p2, double length, char dir); PointF PointExtend(PointF ori, double length, double yaw); bool IsSamePoint(PointF p1, PointF p2); double AvgYaw(std::vector<double> &angles); -- Gitblit v1.8.0