46#include <gtest/gtest.h>
151 const Dlink * link = &v;
298 Polygon poly = create_square();
381 const Vertex & first = poly.get_first_vertex();
388 const Vertex & last = poly.get_last_vertex();
407 const Vertex & first = poly.get_first_vertex();
419 const Vertex & first = poly.get_first_vertex();
420 const Vertex &
next = poly.get_next_vertex(first);
428 const Vertex & last = poly.get_last_vertex();
429 const Vertex & prev = poly.get_prev_vertex(last);
454 Segment first = poly.get_first_segment();
462 Segment last = poly.get_last_segment();
724 Point outside(200, 200);
764 const Vertex & v = poly.get_first_vertex();
765 poly.remove_vertex(v);
801 Point centroid(50, 29);
867 hex = std::make_unique<Regular_Polygon>(
Point(0, 0), 100.0, 6);
870 std::unique_ptr<Regular_Polygon>
hex;
875 for (
size_t i = 0; i < hex->size(); ++i)
887 Point first = hex->get_first_vertex();
895 Point last = hex->get_last_vertex();
903 double r = hex->radius();
905 for (
size_t i = 0; i < hex->size(); ++i)
907 Point v = hex->get_vertex(i);
908 Point center = hex->get_center();
909 double dist = std::sqrt(
927 sq = std::make_unique<Regular_Polygon>(
Point(0, 0), 100.0, 4);
930 std::unique_ptr<Regular_Polygon>
sq;
935 Segment first = sq->get_first_segment();
945 Segment last = sq->get_last_segment();
955 double expected = sq->get_side_size();
957 for (
size_t i = 0; i < sq->size(); ++i)
959 Point v1 = sq->get_vertex(i);
960 Point v2 = sq->get_vertex((i + 1) % sq->size());
976 pentagon = std::make_unique<Regular_Polygon>(
Point(0, 0), 50.0, 5);
1003 for (
size_t i = 0; i < 5; ++i)
1013 for (
size_t i = 0; i < 5; ++i)
1028 triangle = std::make_unique<Regular_Polygon>(
Point(0, 0), 100.0, 3);
1048 Point v0 = triangle->get_vertex(0);
1049 Point v1 = triangle->get_vertex(1);
1058 for (
size_t i = 0; i < 3; ++i)
1068 for (
size_t i = 0; i < 3; ++i)
1084 hex = std::make_unique<Regular_Polygon>(
Point(100, 100), 100.0, 6);
1087 std::unique_ptr<Regular_Polygon>
hex;
1093 Point center = hex->get_center();
1094 double r = hex->radius();
1102 Point center = hex->get_center();
1103 double r = hex->radius();
1111 Point center = hex->get_center();
1112 double r = hex->radius();
1120 Point center = hex->get_center();
1121 double r = hex->radius();
1161 for (
size_t i = 0; i < hex.
size(); ++i)
1164 double dist = std::sqrt(
1221 EXPECT_TRUE(std::is_nothrow_move_constructible<Polygon>::value);
1226 EXPECT_TRUE(std::is_nothrow_move_assignable<Polygon>::value);
1236 const size_t N = 1000;
1239 for (
size_t i = 0; i <
N; ++i)
1264 for (
size_t i = 0; i < poly.
size(); ++i)
1267 double dist = std::sqrt(
1470 ::testing::InitGoogleTest(&
argc,
argv);
Graph create_triangle()
Creates a triangle (K_3) - the simplest non-bipartite graph.
bool has_curr() const noexcept
Return true if the iterator has current item.
Doubly linked circular list node.
Represents a point with rectangular coordinates in a 2D plane.
const Point & rightmost_point() const
Returns the rightmost point (largest x-coordinate).
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Point & leftmost_point() const
Returns the leftmost point (smallest x-coordinate).
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
const Point & highest_point() const
Returns the highest point (largest y-coordinate).
const Point & lowest_point() const
Returns the lowest point (smallest y-coordinate).
Iterator over the edges (segments) of a polygon.
Segment get_current_segment() const
Get the current segment (edge).
bool has_curr() const
Check if there is a current segment.
A general (irregular) 2D polygon defined by a sequence of vertices.
const Point & rightmost_point() const
Get the vertex with the maximum x-coordinate.
Geom_Number signed_area() const
Compute the signed area of the polygon using the shoelace formula.
Point centroid() const
Compute the centroid (center of mass) of the polygon.
Geom_Number perimeter() const
Compute the perimeter of the polygon.
const Point & highest_point() const
Get the vertex with the maximum y-coordinate.
Geom_Number area() const
Compute the absolute area of the polygon.
const Vertex & get_first_vertex() const
Get the first vertex of the polygon.
const Vertex & get_last_vertex() const
Get the last vertex of the polygon.
bool is_convex() const
Check if the polygon is convex.
void add_vertex(const Point &point)
Add a vertex to the polygon.
Segment get_first_segment() const
Get the first edge (segment) of the polygon.
void close()
Close the polygon.
const Point & leftmost_point() const
Get the vertex with the minimum x-coordinate.
const bool & is_closed() const
Check if the polygon is closed.
const size_t & size() const
Get the number of vertices.
const Point & lowest_point() const
Get the vertex with the minimum y-coordinate.
bool contains(const Point &p) const
Check if a point is inside the polygon (or on its boundary).
Iterator over the edges (segments) of a regular polygon.
void next()
Advance to the next segment.
Segment get_current_segment() const
Get the current segment (edge).
bool has_curr() const
Check if there is a current segment.
void next_ne() noexcept
Advance to the next segment (no exception on overflow).
Iterator over the vertices of a regular polygon.
Vertex & get_current_vertex()
Get the current vertex.
bool has_curr() const
Check if there is a current vertex.
void next()
Advance to the next vertex.
void next_ne() noexcept
Advance to the next vertex (no exception on overflow).
A regular polygon defined by center, side length, and vertex count.
Point get_vertex(const size_t &i) const
Get the i-th vertex of the polygon.
const size_t & size() const
Get the number of vertices.
const double & get_side_size() const
Get the side length.
const Point & get_center() const
Get the center point.
const double & radius() const
Get the circumradius.
static bool is_closed()
Check if the polygon is closed.
Represents a line segment between two points.
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.
A non-degenerate triangle defined by three points.
A vertex in a polygon's doubly linked vertex list.
static Vertex * dlink_to_vertex(Dlink *link)
Convert a Dlink pointer to a Vertex pointer.
Point to_point() const
Return this vertex as a plain Point value.
Polygon create_triangle()
std::unique_ptr< Regular_Polygon > hex
std::unique_ptr< Regular_Polygon > triangle
std::unique_ptr< Regular_Polygon > sq
std::unique_ptr< Regular_Polygon > pentagon
std::unique_ptr< Regular_Polygon > hex
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
mpq_class Geom_Number
Numeric type used by the geometry module.
void next()
Advance all underlying iterators (bounds-checked).
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
2D polygon representation and geometric operations.
bool points_equal(const Point &a, const Point &b, double tol=EPSILON)
TEST_F(VertexTest, DefaultConstruction)
bool approx_equal(const Geom_Number &a, const Geom_Number &b, double tol=EPSILON)
Iterator over the vertices of a polygon.
Vertex & get_current_vertex() const
Get the current vertex.