42#include <gtest/gtest.h>
65 double epsilon = 1e-9)
70 static bool near_equal(
double a,
double b,
double epsilon = 1e-9)
72 return std::abs(a - b) < epsilon;
165 Segment horizontal(origin, p1);
166 EXPECT_TRUE(near_equal(horizontal.
length(), 10));
169 EXPECT_TRUE(near_equal(
vertical.length(), 10));
172 EXPECT_TRUE(near_equal(diagonal.
length(), std::sqrt(200.0), 0.01));
179 EXPECT_TRUE(near_equal(mid.
get_x(), 5));
180 EXPECT_TRUE(near_equal(mid.
get_y(), 5));
189 EXPECT_TRUE(near_equal(mid.
get_x(), 0));
190 EXPECT_TRUE(near_equal(mid.
get_y(), 0));
196 EXPECT_TRUE(near_equal(s45.
slope(), 1.0));
198 Segment horizontal(origin, p1);
199 EXPECT_TRUE(near_equal(horizontal.
slope(), 0.0));
203 EXPECT_TRUE(near_equal(negative.
slope(), -1.0));
211 EXPECT_TRUE(s > 1e10 || s < -1e10);
222 EXPECT_TRUE(s1 == s2);
223 EXPECT_FALSE(s1 != s2);
241 EXPECT_TRUE(s1 == s2);
248 EXPECT_FALSE(s1 == s2);
249 EXPECT_TRUE(s1 != s2);
293 EXPECT_TRUE(near_equal(angle, 0.0, 0.1) || near_equal(angle, 2*
PI, 0.1));
303 EXPECT_TRUE(near_equal(angle,
PI_2, 0.1));
310 EXPECT_EQ(
r.get_src_point(), p3);
311 EXPECT_EQ(
r.get_tgt_point(), origin);
318 EXPECT_TRUE(near_equal(proj.
get_x(), 3));
319 EXPECT_TRUE(near_equal(proj.
get_y(), 0));
322 EXPECT_EQ(clamped,
Point(0, 0));
341 EXPECT_TRUE(near_equal(parallel.
length(), original.
length(), 0.01));
357 EXPECT_TRUE(near_equal(s.
length(), std::sqrt(50.0), 0.01));
359 EXPECT_TRUE(near_equal(mid.
get_x(), -7.5, 0.1));
360 EXPECT_TRUE(near_equal(mid.
get_y(), -7.5, 0.1));
367 EXPECT_TRUE(near_equal(s.
length(), 0));
372 Point a(1000000, 1000000);
373 Point b(1000010, 1000010);
376 EXPECT_TRUE(near_equal(s.
length(), std::sqrt(200.0), 0.01));
381 ::testing::InitGoogleTest(&argc, argv);
382 return RUN_ALL_TESTS();
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Represents a line segment between two points.
const Point & rightmost_point() const noexcept
Gets the endpoint with the largest x-coordinate.
Point mid_point() const
Returns the midpoint of this segment.
double slope() const
Returns the slope of the segment.
double counterclockwise_angle() const
Computes the counter-clockwise angle of this segment with respect to the x-axis.
bool is_left_of(const Point &p) const
Checks if this segment is to the left of a given point.
const Point & highest_point() const noexcept
Gets the endpoint with the largest y-coordinate.
const Point & lowest_point() const noexcept
Gets the endpoint with the smallest y-coordinate.
Point project(const Point &p) const
Orthogonal projection of a point onto this segment's infinite line, clamped to the segment's endpoint...
const Point & leftmost_point() const noexcept
Gets the endpoint with the smallest x-coordinate.
double counterclockwise_angle_with(const Segment &s) const
Computes the counter-clockwise rotation angle FROM this segment TO another.
Segment reversed() const
Returns a new segment with the endpoints swapped.
bool is_right_of(const Point &p) const
Checks if this segment is to the right of a given point.
Geom_Number distance_to(const Point &p) const
Calculates the Euclidean distance from a point to this segment.
bool is_colinear_with(const Point &p) const
Checks if a point is collinear with this segment.
const Point & get_tgt_point() const noexcept
Gets the target point of the segment.
const Point & get_src_point() const noexcept
Gets the source point of the segment.
Geom_Number length() const
Returns the Euclidean length of the segment.
static bool near_equal(double a, double b, double epsilon=1e-9)
static bool near_equal(const Geom_Number &a, const Geom_Number &b, double epsilon=1e-9)
bool vertical
If true, use vertical layout (default).
Main namespace for Aleph-w library functions.
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
mpq_class Geom_Number
Numeric type used by the geometry module.
2D point and geometric utilities.
TEST_F(SegmentTest, DefaultConstructor)