97 std::vector<std::pair<Point, Point>>
edges()
const;
174 std::vector<size_t>
get_sharp_angles(
double threshold_degrees = 30.0)
const;
236 const Polygon& other,
double threshold_distance)
const;
386 const Point& seg1_start,
const Point& seg1_end,
387 const Point& seg2_start,
const Point& seg2_end);
393 const Point& seg1_start,
const Point& seg1_end,
394 const Point& seg2_start,
const Point& seg2_end,
401 const Point& seg1_start,
const Point& seg1_end,
402 const Point& seg2_start,
const Point& seg2_end);
426 const Point& line2_start,
const Point& line2_end,
427 Point& intersection);
438 const Point& seg2_start,
const Point& seg2_end);
2D point with high-precision coordinates and utility methods
static constexpr double TOLERANCE
Default precision tolerance for floating point comparisons.
Polygon class supporting both convex and concave polygons.
bool operator==(const Polygon &other) const
Equality operator.
bool is_empty() const
Check if polygon is empty.
std::vector< Point > intersection_points(const Polygon &other) const
Find intersection points between polygon edges.
void remove_vertex(size_t index)
Remove vertex at specific index.
std::vector< std::pair< Point, Point > > edges() const
Get polygon edges as pairs of consecutive vertices.
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.
bool point_on_boundary(const Point &point, double tolerance=Point::TOLERANCE) const
Check if point is on polygon boundary.
double distance_to(const Polygon &other) const
Calculate minimum distance to another polygon.
static Polygon regular_polygon(const Point ¢er, double radius, size_t vertex_count)
Create regular polygon with given center, radius, and vertex count.
Rectangle bounding_box() const
Calculate axis-aligned bounding box.
Polygon(Polygon &&other) noexcept=default
Move constructor.
Polygon scale(double factor) const
Scale polygon by given factor around its centroid.
static Polygon from_rectangle(const Rectangle &rect)
Create polygon from rectangle.
std::vector< double > all_vertex_angles() const
Get all vertex angles.
bool operator!=(const Polygon &other) const
Inequality operator.
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.
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.
Polygon simplify(double tolerance=Point::TOLERANCE) const
Simplify polygon by removing collinear vertices.
Polygon & operator=(const Polygon &other)=default
Assignment operator.
Polygon reverse() const
Reverse vertex order (change orientation)
Polygon rotate_around(const Point ¢er, double angle) const
Rotate polygon around a specific center point.
Point centroid() const
Calculate polygon centroid.
Point closest_point_to(const Point &point) const
Find closest point on polygon boundary to given point.
bool intersects(const Polygon &other) const
Check if this polygon intersects with another polygon.
std::string to_string() const
Get string representation.
bool is_simple() const
Check if polygon is simple (no self-intersections)
Polygon & operator=(Polygon &&other) noexcept=default
Move assignment operator.
void insert_vertex(size_t index, const Point &vertex)
Insert vertex at specific index.
double perimeter() const
Calculate polygon perimeter.
std::vector< Point > vertices
Polygon vertices in order.
friend std::ostream & operator<<(std::ostream &os, const Polygon &polygon)
Stream output operator.
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.
Polygon(const Polygon &other)=default
Copy constructor.
bool is_convex() const
Check if polygon is convex.
bool is_clockwise() const
Check if polygon is clockwise oriented.
bool is_valid() const
Check if polygon is valid (at least 3 vertices)
double min_edge_distance_to(const Polygon &other) const
Calculate minimum distance between this polygon's edges and another polygon's edges.
Polygon rotate(double angle) const
Rotate polygon around origin by given angle.
bool is_counterclockwise() const
Check if polygon is counterclockwise oriented.
bool has_self_intersections() const
Check if polygon edges intersect (for self-intersection detection)
Polygon ensure_counterclockwise() const
Ensure polygon has counterclockwise orientation.
Polygon translate(const Point &offset) const
Translate polygon by given offset.
double signed_area() const
Calculate signed area (preserves orientation)
Polygon()=default
Default constructor - creates empty polygon.
void clear()
Clear all vertices.
void add_vertex(const Point &vertex)
Add vertex to polygon.
Polygon ensure_clockwise() const
Ensure polygon has clockwise orientation.
double distance_to_line(const Point &line_start, const Point &line_end) const
Calculate minimum distance to a line segment.
bool contains_point(const Point &point) const
Check if point is inside polygon (ray casting algorithm)
size_t vertex_count() const
Get number of vertices.
Polygon scale(double x_factor, double y_factor) const
Scale polygon by different factors in X and Y.
double area() const
Calculate polygon area using shoelace formula.
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.
Axis-aligned rectangle for bounding boxes and simple EDA components.
bool line_intersection(const Point &line1_start, const Point &line1_end, const Point &line2_start, const Point &line2_end, Point &intersection)
Calculate intersection point of two infinite lines.
double angle_between_vectors(const Point &v1, const Point &v2)
Calculate angle between two vectors in degrees.
bool segments_intersect(const Point &seg1_start, const Point &seg1_end, const Point &seg2_start, const Point &seg2_end)
Check if two line segments intersect.
Main namespace for ZLayout library.
2D Point class for geometric calculations
Axis-aligned rectangle class for bounding boxes and simple components.
Hash function for Polygon (for use in std::unordered_map, etc.)
std::size_t operator()(const Polygon &polygon) const