10 #include <gtest/gtest.h> 22 TEST(Geometry, Line2DIntersect)
31 EXPECT_TRUE(do_inter);
36 EXPECT_NEAR(i.x, 0.5, 1e-9);
37 EXPECT_NEAR(i.y, 0.5, 1e-9);
40 TEST(Geometry, Line2DAngle)
57 TEST(Geometry, Line3DAngle)
79 TEST(Geometry, Segment2DIntersect)
89 EXPECT_TRUE(do_inter);
94 EXPECT_NEAR(i.x, 0.5, 1e-9);
95 EXPECT_NEAR(i.y, 0.5, 1e-9);
104 bool do_inter =
intersect(s1, s2, inter);
106 EXPECT_FALSE(do_inter);
115 bool do_inter =
intersect(s1, s2, inter);
118 EXPECT_FALSE(do_inter);
125 TPolygon3D p3d({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}});
135 inter.getSegment(test);
139 TPolygon3D p3d({{1, 0, 0}, {0, 1, 0}, {0, 0, 1}});
160 EXPECT_TRUE(
intersect(s3d1, s3d2, inter));
174 EXPECT_TRUE(
intersect(s3d1, s3d2, inter));
179 inter.getPoint(test);
180 EXPECT_EQ(expect, test);
184 TEST(Geometry, IntersectionPlanePlane)
200 EXPECT_FALSE(
intersect(plane1, plane2, inter));
216 EXPECT_TRUE(
intersect(plane1, plane2, inter));
233 EXPECT_TRUE(
intersect(plane1, plane2, inter));
256 TEST(Geometry, PolygonConvexContainsPoint)
259 std::vector<TPoint2D> vs;
260 vs.emplace_back(-1.0, -1.0);
261 vs.emplace_back(0.0, 1.0);
262 vs.emplace_back(1.0, -1.0);
266 std::reverse(vs.begin(), vs.end());
271 p.AddVertex(0, -0.322);
272 p.AddVertex(-0.644, -0.322);
273 p.AddVertex(-0.210377, -0.324673);
274 p.AddVertex(0.433623, -0.324673);
276 EXPECT_FALSE(
p.contains(
TPoint2D(0.73175, -0.325796)));
280 TEST(Geometry, PolygonConcaveContainsPoint)
283 std::vector<TPoint2D> vs;
284 vs.emplace_back(-2.0, 3.0);
285 vs.emplace_back(2.0, 2.0);
286 vs.emplace_back(3.0, -4.0);
287 vs.emplace_back(0.1, -3.0);
288 vs.emplace_back(0.1, -0.1);
289 vs.emplace_back(-0.1, -0.1);
290 vs.emplace_back(-0.1, -3.0);
291 vs.emplace_back(-2.0, -2.0);
296 std::reverse(vs.begin(), vs.end());
bool getPoint(TPoint2D &p) const
Gets the content as a point, returning false if the type is inadequate.
void myTestPolygonContainsPoint(std::vector< TPoint2D > &vs, bool convex)
double RAD2DEG(const double x)
Radians to degrees.
unsigned char getType() const
Gets content type.
double DEG2RAD(const double x)
Degrees to radians.
Standard type for storing any lightweight 2D type.
A wrapper of a TPolygon2D class, implementing CSerializable.
static constexpr unsigned char GEOMETRIC_TYPE_POINT
Object type identifier for TPoint2D or TPoint3D.
Standard object for storing any 3D lightweight object.
static constexpr unsigned char GEOMETRIC_TYPE_PLANE
Object type identifier for TPlane.
TEST(Geometry, Line2DIntersect)
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
3D segment, consisting of two points.
3D Plane, represented by its equation
double getAngle(const TPlane &p1, const TPlane &p2)
Computes the angle between two planes.
bool isConvex() const
Checks whether is convex.
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static constexpr unsigned char GEOMETRIC_TYPE_SEGMENT
Object type identifier for TSegment2D or TSegment3D.
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
static constexpr unsigned char GEOMETRIC_TYPE_LINE
Object type identifier for TLine2D or TLine3D.
2D polygon, inheriting from std::vector<TPoint2D>.
3D polygon, inheriting from std::vector<TPoint3D>
3D line, represented by a base point and a director vector.
2D line without bounds, represented by its equation .