ZLayout EDA Library v1.0.0
Advanced Electronic Design Automation Layout Library with Bilingual Documentation
|
Polygon class supporting both convex and concave polygons. More...
#include <polygon.hpp>
Public Member Functions | |
Polygon ()=default | |
Default constructor - creates empty polygon. | |
Polygon (const std::vector< Point > &vertices) | |
Constructor from vertex list. | |
Polygon (std::initializer_list< Point > vertices) | |
Constructor from initializer list. | |
Polygon (const Polygon &other)=default | |
Copy constructor. | |
Polygon (Polygon &&other) noexcept=default | |
Move constructor. | |
Polygon & | operator= (const Polygon &other)=default |
Assignment operator. | |
Polygon & | operator= (Polygon &&other) noexcept=default |
Move assignment operator. | |
bool | operator== (const Polygon &other) const |
Equality operator. | |
bool | operator!= (const Polygon &other) const |
Inequality operator. | |
size_t | vertex_count () const |
Get number of vertices. | |
bool | is_empty () const |
Check if polygon is empty. | |
bool | is_valid () const |
Check if polygon is valid (at least 3 vertices) | |
std::vector< std::pair< Point, Point > > | edges () const |
Get polygon edges as pairs of consecutive vertices. | |
double | area () const |
Calculate polygon area using shoelace formula. | |
double | signed_area () const |
Calculate signed area (preserves orientation) | |
double | perimeter () const |
Calculate polygon perimeter. | |
Point | centroid () const |
Calculate polygon centroid. | |
Rectangle | bounding_box () const |
Calculate axis-aligned bounding box. | |
bool | is_convex () const |
Check if polygon is convex. | |
bool | is_clockwise () const |
Check if polygon is clockwise oriented. | |
bool | is_counterclockwise () const |
Check if polygon is counterclockwise oriented. | |
bool | is_simple () const |
Check if polygon is simple (no self-intersections) | |
bool | contains_point (const Point &point) const |
Check if point is inside polygon (ray casting algorithm) | |
bool | point_on_boundary (const Point &point, double tolerance=Point::TOLERANCE) const |
Check if point is on polygon boundary. | |
std::vector< size_t > | get_sharp_angles (double threshold_degrees=30.0) const |
Find vertices with sharp angles. | |
double | vertex_angle (size_t vertex_index) const |
Calculate angle at a specific vertex. | |
std::vector< double > | all_vertex_angles () const |
Get all vertex angles. | |
double | distance_to (const Polygon &other) const |
Calculate minimum distance to another polygon. | |
double | distance_to (const Point &point) const |
Calculate minimum distance to a point. | |
double | distance_to_line (const Point &line_start, const Point &line_end) const |
Calculate minimum distance to a line segment. | |
Point | closest_point_to (const Point &point) const |
Find closest point on polygon boundary to given point. | |
double | min_edge_distance_to (const Polygon &other) const |
Calculate minimum distance between this polygon's edges and another polygon's edges. | |
std::vector< std::tuple< Point, Point, double > > | find_narrow_regions (const Polygon &other, double threshold_distance) const |
Find narrow regions where edges are too close. | |
bool | intersects (const Polygon &other) const |
Check if this polygon intersects with another polygon. | |
std::vector< Point > | intersection_points (const Polygon &other) const |
Find intersection points between polygon edges. | |
bool | has_self_intersections () const |
Check if polygon edges intersect (for self-intersection detection) | |
Polygon | translate (const Point &offset) const |
Translate polygon by given offset. | |
Polygon | rotate (double angle) const |
Rotate polygon around origin by given angle. | |
Polygon | rotate_around (const Point ¢er, double angle) const |
Rotate polygon around a specific center point. | |
Polygon | scale (double factor) const |
Scale polygon by given factor around its centroid. | |
Polygon | scale (double x_factor, double y_factor) const |
Scale polygon by different factors in X and Y. | |
Polygon | reverse () const |
Reverse vertex order (change orientation) | |
Polygon | simplify (double tolerance=Point::TOLERANCE) const |
Simplify polygon by removing collinear vertices. | |
Polygon | ensure_counterclockwise () const |
Ensure polygon has counterclockwise orientation. | |
Polygon | ensure_clockwise () const |
Ensure polygon has clockwise orientation. | |
void | add_vertex (const Point &vertex) |
Add vertex to polygon. | |
void | insert_vertex (size_t index, const Point &vertex) |
Insert vertex at specific index. | |
void | remove_vertex (size_t index) |
Remove vertex at specific index. | |
void | clear () |
Clear all vertices. | |
std::string | to_string () const |
Get string representation. | |
__init__ (self, List[Point] vertices) | |
str | __repr__ (self) |
List[Tuple[Point, Point]] | edges (self) |
Rectangle | bounding_box (self) |
float | area (self) |
bool | is_convex (self) |
bool | contains_point (self, Point point) |
List[int] | get_sharp_angles (self, float threshold_degrees=30.0) |
Static Public Member Functions | |
static Polygon | regular_polygon (const Point ¢er, double radius, size_t vertex_count) |
Create regular polygon with given center, radius, and vertex count. | |
static Polygon | from_rectangle (const Rectangle &rect) |
Create polygon from rectangle. | |
static double | segment_to_segment_distance (const Point &seg1_start, const Point &seg1_end, const Point &seg2_start, const Point &seg2_end) |
Helper function to calculate distance between two line segments. | |
static Point | line_segment_intersection (const Point &seg1_start, const Point &seg1_end, const Point &seg2_start, const Point &seg2_end, bool &intersects) |
Helper function to find intersection point of two line segments. | |
static bool | segments_intersect (const Point &seg1_start, const Point &seg1_end, const Point &seg2_start, const Point &seg2_end) |
Helper function to check if two line segments intersect. |
Public Attributes | |
std::vector< Point > | vertices |
Polygon vertices in order. | |
vertices = vertices.copy() |
Protected Member Functions | |
bool | _point_on_edge (self, Point point, Point edge_start, Point edge_end) |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Polygon &polygon) |
Stream output operator. |
Polygon class supporting both convex and concave polygons.
Polygon class supporting both convex and concave polygons.
Represents a polygon in 2D space with arbitrary vertex count. Supports complex geometric operations, sharp angle detection, and various polygon analysis functions essential for EDA applications.
Definition at line 25 of file polygon.hpp.
|
default |
Default constructor - creates empty polygon.
|
explicit |
Constructor from vertex list.
vertices | Vector of polygon vertices |
Definition at line 22 of file polygon.cpp.
zlayout::geometry::Polygon::Polygon | ( | std::initializer_list< Point > | vertices | ) |
Constructor from initializer list.
vertices | Initializer list of vertices |
Definition at line 24 of file polygon.cpp.
|
default |
Copy constructor.
|
defaultnoexcept |
Move constructor.
zlayout.geometry.Polygon.__init__ | ( | self, | |
List[Point] | vertices ) |
Definition at line 125 of file geometry.py.
str zlayout.geometry.Polygon.__repr__ | ( | self | ) |
Definition at line 130 of file geometry.py.
|
protected |
Check if a point lies on an edge.
Definition at line 223 of file geometry.py.
void zlayout::geometry::Polygon::add_vertex | ( | const Point & | vertex | ) |
std::vector< double > zlayout::geometry::Polygon::all_vertex_angles | ( | ) | const |
Get all vertex angles.
Definition at line 210 of file polygon.cpp.
float zlayout.geometry.Polygon.area | ( | self | ) |
Calculate polygon area using shoelace formula.
Definition at line 154 of file geometry.py.
double zlayout::geometry::Polygon::area | ( | ) | const |
Calculate polygon area using shoelace formula.
Definition at line 47 of file polygon.cpp.
Rectangle zlayout.geometry.Polygon.bounding_box | ( | self | ) |
Calculate axis-aligned bounding box.
Definition at line 142 of file geometry.py.
Rectangle zlayout::geometry::Polygon::bounding_box | ( | ) | const |
Calculate axis-aligned bounding box.
Definition at line 84 of file polygon.cpp.
Point zlayout::geometry::Polygon::centroid | ( | ) | const |
Calculate polygon centroid.
Definition at line 73 of file polygon.cpp.
|
inline |
Clear all vertices.
Definition at line 350 of file polygon.hpp.
Find closest point on polygon boundary to given point.
point | Target point |
Definition at line 266 of file polygon.cpp.
bool zlayout.geometry.Polygon.contains_point | ( | self, | |
Point | point ) |
Check if point is inside polygon using ray casting.
Definition at line 193 of file geometry.py.
bool zlayout::geometry::Polygon::contains_point | ( | const Point & | point | ) | const |
Check if point is inside polygon (ray casting algorithm)
point | Point to test |
Definition at line 146 of file polygon.cpp.
double zlayout::geometry::Polygon::distance_to | ( | const Point & | point | ) | const |
Calculate minimum distance to a point.
point | Target point |
Definition at line 239 of file polygon.cpp.
double zlayout::geometry::Polygon::distance_to | ( | const Polygon & | other | ) | const |
Calculate minimum distance to another polygon.
other | Target polygon |
Definition at line 219 of file polygon.cpp.
double zlayout::geometry::Polygon::distance_to_line | ( | const Point & | line_start, |
const Point & | line_end ) const |
Calculate minimum distance to a line segment.
line_start | Start point of line segment |
line_end | End point of line segment |
Definition at line 255 of file polygon.cpp.
Get all edges as (start, end) point pairs.
Definition at line 134 of file geometry.py.
Get polygon edges as pairs of consecutive vertices.
Definition at line 36 of file polygon.cpp.
Polygon zlayout::geometry::Polygon::ensure_clockwise | ( | ) | const |
Ensure polygon has clockwise orientation.
Polygon zlayout::geometry::Polygon::ensure_counterclockwise | ( | ) | const |
Ensure polygon has counterclockwise orientation.
std::vector< std::tuple< Point, Point, double > > zlayout::geometry::Polygon::find_narrow_regions | ( | const Polygon & | other, |
double | threshold_distance ) const |
Find narrow regions where edges are too close.
other | Target polygon |
threshold_distance | Maximum allowed distance |
Definition at line 301 of file polygon.cpp.
List[int] zlayout.geometry.Polygon.get_sharp_angles | ( | self, | |
float | threshold_degrees = 30.0 ) |
Find vertices with sharp angles or boundary angles. For traditional sharp angle detection (small thresholds < 60°): finds acute angles smaller than threshold. For boundary angle detection (large thresholds ≥ 60°): finds angles larger than threshold.
Definition at line 229 of file geometry.py.
std::vector< size_t > zlayout::geometry::Polygon::get_sharp_angles | ( | double | threshold_degrees = 30.0 | ) | const |
Find vertices with sharp angles.
threshold_degrees | Angle threshold in degrees (angles less than this are considered sharp) |
Definition at line 175 of file polygon.cpp.
bool zlayout::geometry::Polygon::has_self_intersections | ( | ) | const |
Check if polygon edges intersect (for self-intersection detection)
Definition at line 361 of file polygon.cpp.
void zlayout::geometry::Polygon::insert_vertex | ( | size_t | index, |
const Point & | vertex ) |
Insert vertex at specific index.
index | Index to insert at |
vertex | Vertex to insert |
Definition at line 383 of file polygon.cpp.
Find intersection points between polygon edges.
other | Target polygon |
Definition at line 341 of file polygon.cpp.
bool zlayout::geometry::Polygon::intersects | ( | const Polygon & | other | ) | const |
Check if this polygon intersects with another polygon.
other | Target polygon |
Definition at line 325 of file polygon.cpp.
bool zlayout::geometry::Polygon::is_clockwise | ( | ) | const |
Check if polygon is clockwise oriented.
Definition at line 124 of file polygon.cpp.
bool zlayout.geometry.Polygon.is_convex | ( | self | ) |
Check if polygon is convex.
Definition at line 167 of file geometry.py.
bool zlayout::geometry::Polygon::is_convex | ( | ) | const |
Check if polygon is convex.
Definition at line 101 of file polygon.cpp.
|
inline |
Check if polygon is counterclockwise oriented.
Definition at line 142 of file polygon.hpp.
|
inline |
Check if polygon is empty.
Definition at line 86 of file polygon.hpp.
bool zlayout::geometry::Polygon::is_simple | ( | ) | const |
Check if polygon is simple (no self-intersections)
Definition at line 128 of file polygon.cpp.
|
inline |
Check if polygon is valid (at least 3 vertices)
Definition at line 91 of file polygon.hpp.
|
static |
Helper function to find intersection point of two line segments.
Definition at line 421 of file polygon.cpp.
double zlayout::geometry::Polygon::min_edge_distance_to | ( | const Polygon & | other | ) | const |
Calculate minimum distance between this polygon's edges and another polygon's edges.
other | Target polygon |
Definition at line 284 of file polygon.cpp.
bool zlayout::geometry::Polygon::operator!= | ( | const Polygon & | other | ) | const |
Inequality operator.
Definition at line 31 of file polygon.cpp.
Assignment operator.
Move assignment operator.
bool zlayout::geometry::Polygon::operator== | ( | const Polygon & | other | ) | const |
Equality operator.
Definition at line 27 of file polygon.cpp.
double zlayout::geometry::Polygon::perimeter | ( | ) | const |
Calculate polygon perimeter.
Definition at line 62 of file polygon.cpp.
bool zlayout::geometry::Polygon::point_on_boundary | ( | const Point & | point, |
double | tolerance = Point::TOLERANCE ) const |
Check if point is on polygon boundary.
point | Point to test |
tolerance | Distance tolerance for boundary check |
Definition at line 164 of file polygon.cpp.
|
static |
Create regular polygon with given center, radius, and vertex count.
center | Center point |
radius | Radius from center to vertices |
vertex_count | Number of vertices |
void zlayout::geometry::Polygon::remove_vertex | ( | size_t | index | ) |
Remove vertex at specific index.
index | Index of vertex to remove |
Definition at line 389 of file polygon.cpp.
Polygon zlayout::geometry::Polygon::reverse | ( | ) | const |
Reverse vertex order (change orientation)
Polygon zlayout::geometry::Polygon::rotate | ( | double | angle | ) | const |
Rotate polygon around origin by given angle.
angle | Rotation angle in radians |
Rotate polygon around a specific center point.
center | Center of rotation |
angle | Rotation angle in radians |
Polygon zlayout::geometry::Polygon::scale | ( | double | factor | ) | const |
Scale polygon by given factor around its centroid.
factor | Scale factor |
Polygon zlayout::geometry::Polygon::scale | ( | double | x_factor, |
double | y_factor ) const |
Scale polygon by different factors in X and Y.
x_factor | X scale factor |
y_factor | Y scale factor |
|
static |
Helper function to calculate distance between two line segments.
Definition at line 411 of file polygon.cpp.
|
static |
Helper function to check if two line segments intersect.
Definition at line 449 of file polygon.cpp.
double zlayout::geometry::Polygon::signed_area | ( | ) | const |
Calculate signed area (preserves orientation)
Definition at line 51 of file polygon.cpp.
Polygon zlayout::geometry::Polygon::simplify | ( | double | tolerance = Point::TOLERANCE | ) | const |
Simplify polygon by removing collinear vertices.
tolerance | Tolerance for collinearity check |
std::string zlayout::geometry::Polygon::to_string | ( | ) | const |
Get string representation.
Definition at line 395 of file polygon.cpp.
Translate polygon by given offset.
offset | Translation vector |
double zlayout::geometry::Polygon::vertex_angle | ( | size_t | vertex_index | ) | const |
Calculate angle at a specific vertex.
vertex_index | Index of vertex to calculate angle for |
Definition at line 189 of file polygon.cpp.
|
inline |
Get number of vertices.
Definition at line 81 of file polygon.hpp.
|
friend |
Stream output operator.
Definition at line 406 of file polygon.cpp.
zlayout.geometry.Polygon.vertices = vertices.copy() |
Definition at line 128 of file geometry.py.
std::vector<Point> zlayout::geometry::Polygon::vertices |
Polygon vertices in order.
Definition at line 27 of file polygon.hpp.