42#include <gtest/gtest.h>
64 double epsilon = 1e-9)
69 static bool near_equal(
double a,
double b,
double epsilon = 1e-9)
71 return std::abs(a - b) < epsilon;
164 Segment horizontal(origin, p1);
165 EXPECT_TRUE(near_equal(horizontal.
size(), 10));
168 EXPECT_TRUE(near_equal(vertical.size(), 10));
171 EXPECT_TRUE(near_equal(diagonal.
size(), std::sqrt(200.0), 0.01));
178 EXPECT_TRUE(near_equal(mid.
get_x(), 5));
179 EXPECT_TRUE(near_equal(mid.
get_y(), 5));
188 EXPECT_TRUE(near_equal(mid.
get_x(), 0));
189 EXPECT_TRUE(near_equal(mid.
get_y(), 0));
195 EXPECT_TRUE(near_equal(s45.
slope(), 1.0));
197 Segment horizontal(origin, p1);
198 EXPECT_TRUE(near_equal(horizontal.
slope(), 0.0));
202 EXPECT_TRUE(near_equal(negative.
slope(), -1.0));
209 double s = vertical.slope();
210 EXPECT_TRUE(s > 1e10 || s < -1e10);
221 EXPECT_TRUE(s1 == s2);
222 EXPECT_FALSE(s1 != s2);
230 EXPECT_FALSE(s1 == s2);
237 EXPECT_FALSE(s1 == s2);
238 EXPECT_TRUE(s1 != s2);
282 EXPECT_TRUE(near_equal(angle, 0.0, 0.1) || near_equal(angle, 2*
PI, 0.1));
292 EXPECT_TRUE(near_equal(angle,
PI_2, 0.1) ||
293 near_equal(angle, 2*
PI -
PI_2, 0.1));
306 EXPECT_TRUE(near_equal(parallel.
size(), original.
size(), 0.01));
322 EXPECT_TRUE(near_equal(s.
size(), std::sqrt(50.0), 0.01));
324 EXPECT_TRUE(near_equal(mid.
get_x(), -7.5, 0.1));
325 EXPECT_TRUE(near_equal(mid.
get_y(), -7.5, 0.1));
332 EXPECT_TRUE(near_equal(s.
size(), 0));
337 Point a(1000000, 1000000);
338 Point b(1000010, 1000010);
341 EXPECT_TRUE(near_equal(s.
size(), std::sqrt(200.0), 0.01));
346 ::testing::InitGoogleTest(&argc, argv);
347 return RUN_ALL_TESTS();
Rectangular point in the plane.
const Geom_Number & get_y() const
Returns y value.
const Geom_Number & get_x() const
Returns x value.
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)
Fundamental segment defined by two points.
const Point & get_tgt_point() const
bool is_colinear_with(const Point &p) const
Return true if p is colinear with this segment.
double counterclockwise_angle_with(const Segment &s) const
Compute the counterclockwise wise angle respect another segment s.
double counterclockwise_angle() const
Compute the counterclockwise angle of this respect x-axis.
const Point & rightmost_point() const
Geom_Number size() const
Return the Euclidean length of the segment (distance between endpoints).
const Point & lowest_point() const
bool is_to_left_from(const Point &p) const
Return true if this segment is to the left of point p.
Point mid_point() const
Return the midpoint of this segment.
const Point & highest_point() const
bool is_to_right_from(const Point &p) const
Return true if this segment is to the right of point p.
const Point & leftmost_point() const
const Point & get_src_point() const
2D point and geometric utilities.
mpq_class Geom_Number
Numeric type used by the geometry module.
double geom_number_to_double(const Geom_Number &n)
TEST_F(SegmentTest, DefaultConstructor)