Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::MonotonePolygonTriangulation Class Reference

O(n log n) triangulation of simple polygons via y-monotone partition + linear-time monotone triangulation. More...

#include <geom_algorithms.H>

Classes

class  EdgeStatusTree
 

Public Member Functions

DynList< Triangleoperator() (Polygon p) const
 Triangulate a simple polygon.
 

Private Types

enum class  VertexType {
  START , END , SPLIT , MERGE ,
  REGULAR
}
 Classification of vertices for y-monotone decomposition. More...
 

Static Private Member Functions

static Array< Pointextract_vertices (const Polygon &p)
 
static Geom_Number signed_double_area (const Array< Point > &v)
 
static void ensure_ccw (Array< Point > &v)
 
static bool is_above (const Point &a, const Point &b)
 Lexicographical "above" comparison (y primary, x secondary).
 
static bool is_below (const Point &a, const Point &b)
 Lexicographical "below" comparison.
 
static bool edge_goes_down (const Array< Point > &verts, const size_t edge)
 Check if the edge starting at edge points downwards.
 
static Geom_Number edge_x_at_y (const Array< Point > &verts, const size_t edge, const Geom_Number &y)
 
static bool edge_status_less (const size_t lhs, const size_t rhs, const Geom_Number &sweep_y, const Array< Point > &verts)
 
static DynList< Triangletriangulate_monotone (const Array< Point > &verts)
 Triangulate a y-monotone polygon given as a vertex array.
 
static VertexType classify_vertex (const Array< Point > &v, const size_t i)
 
static bool regular_interior_right (const Array< Point > &v, const size_t i)
 
static Array< Array< size_t > > build_faces_from_diagonals (const Array< Point > &verts, const DynSetTree< std::pair< size_t, size_t > > &diagonals)
 
static Array< Array< size_t > > decompose_to_monotone_faces (const Array< Point > &verts)
 
static bool is_y_monotone (const Array< Point > &v)
 Check if a CCW polygon vertex array is y-monotone.
 

Detailed Description

O(n log n) triangulation of simple polygons via y-monotone partition + linear-time monotone triangulation.

Algorithm

  1. Decompose the simple polygon into y-monotone sub-polygons by adding diagonals at split and merge vertices (sweep-line, O(n log n)).
  2. Triangulate each y-monotone polygon in O(n) with a stack-based scan.

Requirements

  • Input must be a closed simple polygon with ≥ 3 vertices.
  • Vertices may be CW or CCW (normalized internally).

Complexity

  • Time: O(n log n) for general simple polygons.
  • Time: O(n) when the input polygon is already y-monotone.
  • Space: O(n)

Definition at line 6522 of file geom_algorithms.H.

Member Enumeration Documentation

◆ VertexType

Classification of vertices for y-monotone decomposition.

Enumerator
START 
END 
SPLIT 
MERGE 
REGULAR 

Definition at line 6543 of file geom_algorithms.H.

Member Function Documentation

◆ build_faces_from_diagonals()

◆ classify_vertex()

static VertexType Aleph::MonotonePolygonTriangulation::classify_vertex ( const Array< Point > &  v,
const size_t  i 
)
inlinestaticprivate

◆ decompose_to_monotone_faces()

◆ edge_goes_down()

static bool Aleph::MonotonePolygonTriangulation::edge_goes_down ( const Array< Point > &  verts,
const size_t  edge 
)
inlinestaticprivate

Check if the edge starting at edge points downwards.

Definition at line 6565 of file geom_algorithms.H.

References Aleph::divide_and_conquer_partition_dp(), and is_below().

Referenced by decompose_to_monotone_faces().

◆ edge_status_less()

static bool Aleph::MonotonePolygonTriangulation::edge_status_less ( const size_t  lhs,
const size_t  rhs,
const Geom_Number sweep_y,
const Array< Point > &  verts 
)
inlinestaticprivate

◆ edge_x_at_y()

static Geom_Number Aleph::MonotonePolygonTriangulation::edge_x_at_y ( const Array< Point > &  verts,
const size_t  edge,
const Geom_Number y 
)
inlinestaticprivate

◆ ensure_ccw()

static void Aleph::MonotonePolygonTriangulation::ensure_ccw ( Array< Point > &  v)
inlinestaticprivate

Definition at line 6535 of file geom_algorithms.H.

References Aleph::GeomPolygonUtils::ensure_ccw().

Referenced by operator()().

◆ extract_vertices()

static Array< Point > Aleph::MonotonePolygonTriangulation::extract_vertices ( const Polygon p)
inlinestaticprivate

Definition at line 6525 of file geom_algorithms.H.

References Aleph::GeomPolygonUtils::extract_vertices().

Referenced by operator()().

◆ is_above()

static bool Aleph::MonotonePolygonTriangulation::is_above ( const Point a,
const Point b 
)
inlinestaticprivate

Lexicographical "above" comparison (y primary, x secondary).

Definition at line 6548 of file geom_algorithms.H.

References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), and Aleph::Point::get_y().

Referenced by classify_vertex(), and is_below().

◆ is_below()

static bool Aleph::MonotonePolygonTriangulation::is_below ( const Point a,
const Point b 
)
inlinestaticprivate

Lexicographical "below" comparison.

Definition at line 6557 of file geom_algorithms.H.

References is_above().

Referenced by classify_vertex(), edge_goes_down(), and regular_interior_right().

◆ is_y_monotone()

static bool Aleph::MonotonePolygonTriangulation::is_y_monotone ( const Array< Point > &  v)
inlinestaticprivate

Check if a CCW polygon vertex array is y-monotone.

Definition at line 7305 of file geom_algorithms.H.

References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::next(), and Aleph::Array< T >::size().

Referenced by decompose_to_monotone_faces(), and operator()().

◆ operator()()

DynList< Triangle > Aleph::MonotonePolygonTriangulation::operator() ( Polygon  p) const
inline

Triangulate a simple polygon.

For convex and y-monotone polygons, the result is computed directly in O(n). For general simple polygons, the polygon is partitioned into y-monotone sub-polygons in O(n log n), then each sub-polygon is triangulated in linear time.

Parameters
pThe polygon (will not be modified; a copy is used).
Returns
List of triangles forming the triangulation.
Exceptions
domain_errorif polygon is not closed or has < 3 vertices.
domain_errorif polygon is degenerate (zero area).
Note
The algorithm follows the standard sweep-line monotone partition pipeline and runs in O(n log n) for simple polygons.

Definition at line 7239 of file geom_algorithms.H.

References Aleph::Polygon::add_vertex(), ah_domain_error_if, Aleph::DynList< T >::append(), decompose_to_monotone_faces(), Aleph::divide_and_conquer_partition_dp(), ensure_ccw(), extract_vertices(), Aleph::HTList::Iterator::has_curr(), Aleph::Polygon::is_closed(), is_y_monotone(), Aleph::Array< T >::reserve(), signed_double_area(), Aleph::Polygon::size(), Aleph::Array< T >::size(), Aleph::size(), and triangulate_monotone().

◆ regular_interior_right()

static bool Aleph::MonotonePolygonTriangulation::regular_interior_right ( const Array< Point > &  v,
const size_t  i 
)
inlinestaticprivate

Definition at line 6942 of file geom_algorithms.H.

References is_below(), and Aleph::Array< T >::size().

Referenced by decompose_to_monotone_faces().

◆ signed_double_area()

static Geom_Number Aleph::MonotonePolygonTriangulation::signed_double_area ( const Array< Point > &  v)
inlinestaticprivate

Definition at line 6530 of file geom_algorithms.H.

References Aleph::GeomPolygonUtils::signed_double_area().

Referenced by operator()().

◆ triangulate_monotone()


The documentation for this class was generated from the following file: