144 Point::operator=(vertex);
152 return static_cast<const Point>(*this);
161 return static_cast<Vertex *
>(link);
169 return static_cast<const Vertex *
>(link);
202 class Regular_Polygon;
352 return dit_ ==
o.dit_;
357 return dit_ !=
o.dit_;
391 std::swap(
lowest_, poly.lowest_);
436 std::swap(
lowest_, poly.lowest_);
531 <<
"Polygon has less than two vertex";
551 <<
"Segment iterator is in the last point and it is not closed";
569 if (&it.get_current_vertex() == &v)
629 <<
"polygon has less than two vertex";
642 <<
"polygon has less than two vertex";
686 <<
"new vertex is inside of last polygon's segment";
705 const Point p = it.get_current_vertex().to_point();
781 if (&it.get_current_vertex() == &v)
783 victim = &
const_cast<Vertex &
>(it.get_current_vertex());
812 const Point point = it.get_current_vertex().to_point();
844 <<
"Polygon needs at least 3 vertices to close (has " <<
num_vertex_ <<
")";
862 <<
"closing causes an intersection";
892 const Segment edge = it.get_current_segment();
932 [[deprecated(
"Use contains() instead")]]
950 const Segment seg = it.get_current_segment();
982 sum += it.get_current_segment().length();
1000 const Segment seg = it.get_current_segment();
1010 return {cx / (3 *
a6), cy / (3 *
a6)};
1041 const int curr_sign = turn > 0 ? 1 : -1;
1157 const double &
ang = 0)
1164 const double alpha = (
PI -
beta_) / 2;
1200 <<
"vertex " << i <<
" is greater than " <<
num_vertex_;
1383 for (
size_t i = 0; i < poly.
size(); ++i)
1401 o <<
"Polygon(n=" << p.
size() <<
", "
1402 << (p.
is_closed() ?
"closed" :
"open") <<
", [";
1406 if (
count > 0)
o <<
", ";
1407 o << it.get_current_vertex();
1423 <<
", n=" << p.
size()
1424 <<
", radius=" << p.
radius() <<
")";
Container traversal and functional operation mixins.
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
STL-compatible iterator adapters for Aleph containers.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
void next_ne() noexcept
Move the iterator one position backward guaranteeing no exception.
bool is_in_last() const noexcept
Return true if the iterator is positiones on the last item.
bool has_curr() const noexcept
Return true if the iterator has current item.
Dlink * get_curr() const
Return the current node of iterator.
void next()
Move the iterator one position forward.
void prev()
Move the iterator one position backward.
Dlink * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
void prev_ne() noexcept
Move the iterator one position backward guaranteeing no exception.
void end() noexcept
Put the iterator out of range.
void reset_first() noexcept
Reset the iterator to the first item of list.
Doubly linked circular list node.
Dlink *& get_next() const noexcept
Return the link that is after this
Dlink * remove_next() noexcept
Remove the item that is after this
constexpr bool is_unitarian_or_empty() const noexcept
Return true if this (as header node) has zero or one element.
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
void append(Dlink *node) noexcept
Insert node before this.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
constexpr bool is_unitarian() const noexcept
Return true if this (as header node) has exactly one element.
Dlink *& get_prev() const noexcept
Return the link that is before this
Represents a point with rectangular coordinates in a 2D plane.
bool is_inside(const Segment &s) const
Checks if this point is contained within a segment.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
bool is_colinear_with(const Point &p1, const Point &p2) const
Checks if this point is collinear with two other points.
STL/Aleph-compatible iterator over polygon vertices as Points.
const Point & get_curr() const
bool operator==(const Iterator &o) const noexcept
Iterator() noexcept=default
Dlink * get_pos() const noexcept
bool operator!=(const Iterator &o) const noexcept
bool has_curr() const noexcept
void reset_first() noexcept
Iterator over the edges (segments) of a polygon.
Polygon & poly_
Reference to the polygon being iterated.
Segment get_current_segment() const
Get the current segment (edge).
bool has_curr() const
Check if there is a current segment.
Segment_Iterator(const Polygon &poly)
Construct a segment iterator from a polygon.
A general (irregular) 2D polygon defined by a sequence of vertices.
const Point & rightmost_point() const
Get the vertex with the maximum x-coordinate.
void copy_points(const Polygon &poly)
Copy all vertices from another polygon.
void delete_points()
Delete all vertices and reset the polygon state.
Polygon(Polygon &&poly) noexcept
Move constructor.
bool contains_to(const Point &p) const
Point lowest_
Vertex with minimum y-coordinate.
void copy_regular_polygon(const Regular_Polygon &poly)
Copy vertices from a regular polygon.
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.
bool is_closed_
True if the polygon has been closed.
Geom_Number perimeter() const
Compute the perimeter of the polygon.
void update_extreme_points(const Point &point)
Update extreme points after adding a new vertex.
const Point & highest_point() const
Get the vertex with the maximum y-coordinate.
const Vertex & get_next_vertex(const Vertex &v) const
Get the vertex following v in the polygon.
Polygon & operator=(const Polygon &poly)
Copy assignment operator.
const Vertex & get_prev_vertex(const Vertex &v) const
Get the vertex preceding v in the polygon.
Geom_Number area() const
Compute the absolute area of the polygon.
void remove_vertex(const Vertex &v)
Remove a vertex from the polygon.
void append(const Point &point)
Append a vertex (Aleph container protocol).
size_t num_vertex_
Number of vertices in the polygon.
PointLocation locate_point(const Point &p) const
Classify a point against this closed polygon.
Point rightmost_
Vertex with maximum x-coordinate.
const Vertex & get_first_vertex() const
Get the first vertex of the polygon.
Polygon(const Regular_Polygon &poly)
Construct from a Regular_Polygon.
const Vertex & get_last_vertex() const
Get the last vertex of the polygon.
Segment get_last_segment() const
Get the last edge (segment) of the polygon.
bool is_convex() const
Check if the polygon is convex.
~Polygon()
Destructor. Frees all vertices.
void add_vertex(const Geom_Number &x, const Geom_Number &y)
Add a vertex using coordinates.
void add_vertex(const Point &point)
Add a vertex to the polygon.
Point leftmost_
Vertex with minimum x-coordinate.
Segment get_first_segment() const
Get the first edge (segment) of the polygon.
Polygon(const Polygon &poly)
Copy constructor.
Point highest_
Vertex with maximum y-coordinate.
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.
bool vertex_belong_polygon(const Vertex &v) const
Check if a vertex belongs to this polygon.
Dlink vertex_list_
Doubly linked list of vertices.
const size_t & size() const
Get the number of vertices.
bool intersects_with(const Segment &sg) const
Check if a segment intersects with any edge of the polygon.
Polygon(const Triangle &tr)
Construct a polygon from a Triangle.
const Point & lowest_point() const
Get the vertex with the minimum y-coordinate.
Polygon()
Default constructor. Creates an empty, open polygon.
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 prev()
Move to the previous segment.
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.
const Regular_Polygon & poly_
Reference to the polygon.
Segment_Iterator(const Regular_Polygon &poly)
Construct segment iterator from a regular polygon.
size_t curr_
Current segment index.
void next_ne() noexcept
Advance to the next segment (no exception on overflow).
Iterator over the vertices of a regular polygon.
const Regular_Polygon & poly_
Reference to the polygon.
Vertex & get_current_vertex()
Get the current vertex.
size_t curr_
Current vertex index.
bool has_curr() const
Check if there is a current vertex.
void next()
Advance to the next vertex.
void prev()
Move to previous vertex.
void next_ne() noexcept
Advance to the next vertex (no exception on overflow).
Vertex vertex_
Cache for compatibility with Polygon::Vertex_Iterator.
Vertex_Iterator(const Regular_Polygon &poly)
Construct iterator from a regular polygon.
A regular polygon defined by center, side length, and vertex count.
Point get_last_vertex() const
Get the last vertex (index size()-1).
Point get_vertex(const size_t &i) const
Get the i-th vertex of the polygon.
Point get_first_vertex() const
Get the first vertex (index 0).
double r_
Circumradius (distance from center to vertices)
const size_t & size() const
Get the number of vertices.
const double & get_side_size() const
Get the side length.
double angle_
Rotation angle in radians.
Point lowest_point() const
Get the lowest point of the bounding circle.
Regular_Polygon(Point c, const double &side_sz, const size_t &n, const double &ang=0)
Construct a regular polygon.
Point highest_point() const
Get the highest point of the bounding circle.
const Point & get_center() const
Get the center point.
double side_size_
Length of each side (double due to trig limitations)
Regular_Polygon()
Default constructor. Creates an invalid empty polygon.
Segment get_first_segment() const
Get the first segment (edge).
Segment get_last_segment() const
Get the last segment (closing edge).
Point center_
Center point of the polygon.
size_t num_vertex_
Number of vertices (sides)
double beta_
Central angle between adjacent vertices (2π/n)
Point leftmost_point() const
Get the leftmost point of the bounding circle.
const double & radius() const
Get the circumradius.
Point rightmost_point() const
Get the rightmost point of the bounding circle.
static bool is_closed()
Check if the polygon is closed.
Represents a line segment between two points.
void rotate(const Geom_Number &angle)
Rotates the segment by a given angle around its source point.
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.
A non-degenerate triangle defined by three points.
A vertex in a polygon's doubly linked vertex list.
Vertex(const Vertex &vertex)
Copy constructor.
Vertex(const Point &point)
Construct a vertex from a Point.
const Vertex & prev_vertex() const
Get the previous vertex in the polygon.
Vertex()=default
Default constructor. Creates a vertex at origin (0, 0).
static const Vertex * dlink_to_vertex(const Dlink *link)
Convert a const Dlink pointer to a const Vertex pointer.
static Vertex * dlink_to_vertex(Dlink *link)
Convert a Dlink pointer to a Vertex pointer.
Vertex & operator=(const Vertex &vertex)
Copy assignment operator.
const Vertex & next_vertex() const
Get the next vertex in the polygon.
Point to_point() const
Return this vertex as a plain Point value.
Common methods to the Aleph-w ( ) containers.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
Doubly linked circular list implementation.
__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.
and
Check uniqueness with explicit hash + equality functors.
Geom_Number area_of_parallelogram(const Point &a, const Point &b, const Point &c)
Compute the signed area of the parallelogram defined by vectors a->b and a->c.
bool on_segment(const Segment &s, const Point &p)
Return true if p lies on segment s (exact).
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.
Orientation orientation(const Point &a, const Point &b, const Point &c)
Return the orientation of the triple (a, b, c).
mpq_class Geom_Number
Numeric type used by the geometry module.
std::ostream & operator<<(std::ostream &osObject, const Field< T > &rightOp)
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
2D point and geometric utilities.
Base class for all geometric objects.
Iterator over the vertices of a polygon.
Vertex_Iterator(const Polygon &poly)
Construct iterator from a polygon.
Vertex & get_current_vertex() const
Get the current vertex.
Generic traversal of the container through its iterator.