|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Represents a line segment between two points. More...
#include <point.H>
Public Types | |
| enum | Sense { E , NE , N , NW , W , SW , S , SE } |
| Cardinal and intercardinal directions associated with a segment's vector. More... | |
Public Member Functions | |
| bool | operator== (const Segment &s) const noexcept |
| Checks for equality between two segments. | |
| bool | operator!= (const Segment &s) const noexcept |
| Checks for inequality between two segments. | |
| const Point & | highest_point () const noexcept |
| Gets the endpoint with the largest y-coordinate. | |
| const Point & | lowest_point () const noexcept |
| Gets the endpoint with the smallest y-coordinate. | |
| const Point & | leftmost_point () const noexcept |
| Gets the endpoint with the smallest x-coordinate. | |
| const Point & | rightmost_point () const noexcept |
| Gets the endpoint with the largest x-coordinate. | |
| const Point & | get_src_point () const noexcept |
| Gets the source point of the segment. | |
| const Point & | get_tgt_point () const noexcept |
| Gets the target point of the segment. | |
| Segment ()=default | |
| Default constructor. | |
| Segment (Point src, Point tgt) | |
| Constructs a segment from two endpoints. | |
| Segment (Point src, const Geom_Number &m, const Geom_Number &l) | |
| Constructs a new segment from a source point, slope, and length. | |
| Segment (const Segment &sg, const Geom_Number &dist) | |
| Constructs a new segment parallel to a given segment at a specified distance. | |
| double | slope () const |
| Returns the slope of the segment. | |
| Geom_Number | slope_exact () const |
Returns the exact slope of the segment as a Geom_Number. | |
| double | counterclockwise_angle_with (const Segment &s) const |
| Computes the counter-clockwise rotation angle FROM this segment TO another. | |
| double | counterclockwise_angle () const |
| Computes the counter-clockwise angle of this segment with respect to the x-axis. | |
| Geom_Number | length () const |
| Returns the Euclidean length of the segment. | |
| Geom_Number | size () const |
| bool | is_colinear_with (const Point &p) const |
| Checks if a point is collinear with this segment. | |
| bool | is_left_of (const Point &p) const |
| Checks if this segment is to the left of a given point. | |
| bool | is_right_of (const Point &p) const |
| Checks if this segment is to the right of a given point. | |
| bool | is_to_left_from (const Point &p) const |
| bool | is_to_right_from (const Point &p) const |
| Point | mid_point () const |
| Returns the midpoint of this segment. | |
| Segment | reversed () const |
| Returns a new segment with the endpoints swapped. | |
| Point | at (const Geom_Number &t) const |
| Evaluates a point on the segment via linear interpolation. | |
| Point | project (const Point &p) const |
| Orthogonal projection of a point onto this segment's infinite line, clamped to the segment's endpoints. | |
| Geom_Number | distance_to (const Point &p) const |
| Calculates the Euclidean distance from a point to this segment. | |
| const Point & | nearest_point (const Point &p) const |
| Returns whichever endpoint of this segment is nearer to a given point. | |
| Segment | get_perpendicular (const Point &p) const |
Constructs a segment perpendicular to this that passes through point p. | |
| Segment | mid_perpendicular (const Geom_Number &dist) const |
| Returns the perpendicular chord of a given length passing through the midpoint. | |
| bool | intersects_properly_with (const Segment &s) const |
| Checks if this segment properly intersects another segment. | |
| bool | contains (const Point &p) const |
| Checks if a point lies on this segment. | |
| bool | contains_to (const Point &p) const |
| bool | contains (const Segment &s) const |
Checks if another segment s lies entirely inside this segment. | |
| bool | contains_to (const Segment &s) const |
| bool | intersects_with (const Segment &s) const |
| Checks if this segment intersects another one (including endpoints and collinear overlap). | |
| bool | intersects_with (const Triangle &t) const |
| Checks if this segment intersects a triangle. | |
| bool | intersects_with (const Ellipse &e) const |
| Checks if this segment intersects an ellipse. | |
| bool | is_parallel_with (const Segment &s) const |
| Checks if this segment is parallel to another one. | |
| Point | intersection_with (const Segment &s) const |
| Computes the intersection point of the infinite lines defined by two segments. | |
| Sense | sense () const |
| Determines the cardinal/intercardinal direction of the segment. | |
| void | enlarge_src (const Geom_Number &dist) |
| Extends the segment by a given distance from the source endpoint. | |
| void | enlarge_tgt (const Geom_Number &dist) |
| Extends the segment by a given distance from the target endpoint. | |
| std::string | to_string () const |
| Returns a string representation of the segment, e.g., "(x1,y1)(x2,y2)". | |
| operator std::string () const | |
Cast operator to std::string. | |
| void | rotate (const Geom_Number &angle) |
| Rotates the segment by a given angle around its source point. | |
| Segment | intersection_with (const Triangle &t) const |
| Computes the intersection segment with a triangle. | |
| Segment | intersection_with (const Ellipse &e) const |
| Computes the intersection segment with an ellipse. | |
Public Member Functions inherited from Aleph::Geom_Object | |
| Geom_Object ()=default | |
| virtual | ~Geom_Object ()=default |
Private Member Functions | |
| double | compute_slope () const |
| Internal helper to compute the slope as a double. | |
Static Private Member Functions | |
| static Point | compute_tgt_point (const Point &src, const Geom_Number &m, const Geom_Number &d) |
| Computes the target point of a segment given a source, slope, and length. | |
Private Attributes | |
| Point | src_ |
| Point | tgt_ |
Friends | |
| class | Point |
| class | Triangle |
Represents a line segment between two points.
Represents an (undirected) segment in the plane, stored as source and target endpoints. Provides methods for intersection, projection, distance calculations, and other geometric queries.
|
default |
Default constructor.
Initializes a zero-length segment at the origin.
Referenced by intersection_with(), and intersects_with().
|
inline |
|
inline |
Constructs a new segment parallel to a given segment at a specified distance.
| sg | The reference segment. |
| dist | The perpendicular distance to the new segment. |
Definition at line 983 of file point.H.
References Aleph::divide_and_conquer_partition_dp(), get_src_point(), get_tgt_point(), mid_perpendicular(), mid_point(), src_, and tgt_.
|
inline |
Evaluates a point on the segment via linear interpolation.
| t | The interpolation parameter. t=0 returns the source, t=1 returns the target. |
Point at parameter t. Definition at line 1137 of file point.H.
References Aleph::Point::lerp(), src_, and tgt_.
Referenced by Aleph::Ellipse::intersection_with(), and project().
|
inlineprivate |
Internal helper to compute the slope as a double.
Definition at line 837 of file point.H.
References Aleph::divide_and_conquer_partition_dp(), __gmp_expr< mpq_t, mpq_t >::get_d(), Aleph::Point::get_x(), Aleph::Point::get_y(), src_, and tgt_.
Referenced by slope().
|
inlinestaticprivate |
Computes the target point of a segment given a source, slope, and length.
| src | The origin point. |
| m | The slope. |
| d | The length of the segment. |
Definition at line 948 of file point.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), Aleph::Point::get_y(), m, Aleph::square_root(), and y.
Checks if a point lies on this segment.
| p | The point to check. |
true if p is collinear and lies between the endpoints. Definition at line 1246 of file point.H.
References Aleph::Point::is_between(), src_, and tgt_.
Referenced by contains(), contains_to(), contains_to(), intersection_with(), intersects_with(), Aleph::Point::is_inside(), Aleph::TrapezoidalMapPointLocation::Result::locate(), Aleph::ConstrainedDelaunayTriangulation::map_constraints(), Aleph::on_segment(), Aleph::BooleanPolygonOperations::point_inside_ccw(), and TEST_F().
Checks if another segment s lies entirely inside this segment.
| s | The other segment. |
true if both endpoints of s are on this segment. Definition at line 1260 of file point.H.
References Aleph::and, contains(), get_src_point(), and get_tgt_point().
|
inline |
Computes the counter-clockwise angle of this segment with respect to the x-axis.
Definition at line 1046 of file point.H.
References Aleph::divide_and_conquer_partition_dp(), and Point.
Referenced by TEST_F().
Computes the counter-clockwise rotation angle FROM this segment TO another.
Returns the angle (in radians) you would rotate this segment counter-clockwise to align it with segment s. For example, if this segment points along +X and s points along +Y, the result is π/2 (90°).
| s | The target segment. |
Definition at line 1025 of file point.H.
References Aleph::arctan2(), Aleph::divide_and_conquer_partition_dp(), Aleph::geom_number_to_double(), Aleph::geom_pi(), Aleph::Point::get_x(), Aleph::Point::get_y(), src_, tgt_, and y1().
|
inline |
Calculates the Euclidean distance from a point to this segment.
| p | The point. |
p to any point on the segment. Definition at line 1169 of file point.H.
References Aleph::Point::distance_to(), and project().
Referenced by Aleph::DouglasPeuckerSimplification::dp_recurse(), and TEST_F().
|
inline |
|
inline |
Constructs a segment perpendicular to this that passes through point p.
| p | The point through which the perpendicular segment will pass. |
Segment starting at the projected point on this segment's line and ending at p. Definition at line 1190 of file point.H.
References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Point::dot(), Aleph::Point::lerp(), src_, and tgt_.
Referenced by TEST_F().
Gets the source point of the segment.
Definition at line 915 of file point.H.
References src_.
Referenced by Segment(), Aleph::SweepLineSegmentIntersection::canonicalize(), Aleph::Polygon::centroid(), Aleph::SegmentSegmentIntersection::collinear_overlap(), Aleph::TrapezoidalMapPointLocation::Result::contains(), contains(), Aleph::CuttingEarsTriangulation::diagonalize(), Aleph::Tikz_Plane::draw_segment(), Aleph::QuickHull::get_farthest_point(), Aleph::RotatedEllipse::intersection_with(), Aleph::Ellipse::intersection_with(), intersection_with(), Aleph::Ellipse::intersects_with(), Aleph::RotatedEllipse::intersects_with(), Aleph::TrapezoidalMapPointLocation::Result::locate(), Aleph::Polygon::locate_point(), Aleph::ConstrainedDelaunayTriangulation::map_constraints(), Aleph::ConstrainedDelaunayTriangulation::merge_and_deduplicate(), nearest_point(), Aleph::TrapezoidalMapPointLocation::operator()(), Aleph::BruteForceConvexHull::operator()(), Aleph::operator<<(), Aleph::TrapezoidalMapPointLocation::point_above_segment(), print_case(), Aleph::put_trapezoidal_map_result(), Aleph::Polygon::signed_area(), Aleph::SweepLineSegmentIntersection::slope_less(), Aleph::TrapezoidalMapPointLocation::split_multiple_trapezoids(), Aleph::TrapezoidalMapPointLocation::split_single_trapezoid(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), Aleph::GeomSerializer::to_geojson(), Aleph::GeomSerializer::to_wkt(), and Aleph::SweepLineSegmentIntersection::y_at_x().
Gets the target point of the segment.
Definition at line 921 of file point.H.
References tgt_.
Referenced by Segment(), Aleph::SweepLineSegmentIntersection::canonicalize(), Aleph::Polygon::centroid(), Aleph::TrapezoidalMapPointLocation::Result::contains(), contains(), Aleph::CuttingEarsTriangulation::diagonalize(), Aleph::Tikz_Plane::draw_segment(), Aleph::TrapezoidalMapPointLocation::find_crossed_trapezoids(), Aleph::QuickHull::get_farthest_point(), Aleph::Regular_Polygon::get_vertex(), Aleph::RotatedEllipse::intersection_with(), Aleph::Ellipse::intersection_with(), intersection_with(), Aleph::Ellipse::intersects_with(), Aleph::RotatedEllipse::intersects_with(), Aleph::TrapezoidalMapPointLocation::Result::locate(), Aleph::Polygon::locate_point(), Aleph::ConstrainedDelaunayTriangulation::map_constraints(), Aleph::ConstrainedDelaunayTriangulation::merge_and_deduplicate(), nearest_point(), Aleph::BruteForceConvexHull::operator()(), Aleph::operator<<(), Aleph::TrapezoidalMapPointLocation::point_above_segment(), print_case(), Aleph::put_trapezoidal_map_result(), Aleph::Polygon::signed_area(), Aleph::SweepLineSegmentIntersection::slope_less(), Aleph::TrapezoidalMapPointLocation::split_multiple_trapezoids(), Aleph::TrapezoidalMapPointLocation::split_single_trapezoid(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), Aleph::GeomSerializer::to_geojson(), Aleph::GeomSerializer::to_wkt(), and Aleph::SweepLineSegmentIntersection::y_at_x().
Gets the endpoint with the largest y-coordinate.
Definition at line 879 of file point.H.
References Aleph::Point::get_y(), src_, and tgt_.
Referenced by Aleph::Tikz_Plane::bbox_of().
Computes the intersection segment with an ellipse.
| e | The ellipse. |
Segment of intersection. Can be a point for tangency. | std::domain_error | if there is no intersection. |
Definition at line 2379 of file point.H.
References Aleph::Ellipse::intersection_with().
Computes the intersection point of the infinite lines defined by two segments.
| s | The other segment. |
Point of intersection. | std::domain_error | if the segments are parallel. |
Definition at line 1313 of file point.H.
References ah_domain_error_if, Aleph::Point::cross(), src_, and tgt_.
Referenced by arc_segment(), arc_trigon(), Aleph::PolygonOffset::find_self_intersections(), Aleph::BooleanPolygonOperations::greiner_hormann(), Aleph::Triangle::intersection_with(), intersection_with(), and main().
Computes the intersection segment with a triangle.
| t | The triangle. |
Segment of intersection. Can be a point (degenerate segment). | std::domain_error | if there is no intersection. |
Definition at line 1933 of file point.H.
References Segment(), ah_domain_error_if, contains(), Aleph::count(), Aleph::divide_and_conquer_partition_dp(), Aleph::Triangle::get_p1(), Aleph::Triangle::get_p2(), Aleph::Triangle::get_p3(), get_src_point(), get_tgt_point(), intersection_with(), intersects_with(), and is_parallel_with().
Checks if this segment properly intersects another segment.
A proper intersection means the segments cross at an interior point, and do not share any endpoints or overlap collinearly.
| s | The other segment. |
true if they properly intersect. Definition at line 1228 of file point.H.
References Aleph::and, Aleph::area_of_parallelogram(), src_, and tgt_.
Referenced by Aleph::ConstrainedDelaunayTriangulation::find_crossing_edges(), Aleph::PolygonOffset::find_self_intersections(), Aleph::BooleanPolygonOperations::greiner_hormann(), intersects_with(), Aleph::ShortestPathInPolygon::operator()(), Aleph::detail::shortest_path_portals(), TEST_F(), TEST_F(), and TEST_F().
Checks if this segment intersects an ellipse.
| e | The ellipse. |
true if the segment and ellipse share at least one point. Definition at line 2372 of file point.H.
References Aleph::Ellipse::intersects_with().
Checks if this segment intersects another one (including endpoints and collinear overlap).
| s | The other segment. |
true if they share at least one point. Definition at line 1274 of file point.H.
References contains(), Aleph::divide_and_conquer_partition_dp(), intersects_properly_with(), src_, and tgt_.
Referenced by Aleph::CuttingEarsTriangulation::diagonalize(), intersection_with(), intersects_with(), and Aleph::segments_intersect().
Checks if this segment intersects a triangle.
| t | The triangle. |
true if the segment and triangle share at least one point. Definition at line 1922 of file point.H.
References Segment(), Aleph::divide_and_conquer_partition_dp(), Aleph::Triangle::get_p1(), Aleph::Triangle::get_p2(), Aleph::Triangle::get_p3(), and intersects_with().
Checks if this segment is to the left of a given point.
| p | The point. |
true if the point is to the right of this directed segment. Definition at line 1081 of file point.H.
References Aleph::Point::is_right_of().
Referenced by is_to_left_from(), and TEST_F().
Checks if this segment is parallel to another one.
| s | The other segment. |
true if their direction vectors are parallel (cross product is zero). Definition at line 1302 of file point.H.
Referenced by intersection_with().
Checks if this segment is to the right of a given point.
| p | The point. |
true if the point is to the left of this directed segment. Definition at line 1092 of file point.H.
References Aleph::Point::is_left_of().
Referenced by is_to_right_from(), and TEST_F().
Definition at line 1099 of file point.H.
References is_left_of().
Definition at line 1106 of file point.H.
References is_right_of().
Gets the endpoint with the smallest x-coordinate.
Definition at line 897 of file point.H.
References Aleph::Point::get_x(), src_, and tgt_.
Referenced by Aleph::Tikz_Plane::bbox_of().
|
inline |
Returns the Euclidean length of the segment.
Definition at line 1056 of file point.H.
References Aleph::euclidean_distance(), Aleph::Point::get_x(), Aleph::Point::get_y(), src_, and tgt_.
Referenced by demo_coverage_area(), size(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
Gets the endpoint with the smallest y-coordinate.
Definition at line 888 of file point.H.
References Aleph::Point::get_y(), src_, and tgt_.
Referenced by Aleph::Tikz_Plane::bbox_of().
|
inline |
Returns the perpendicular chord of a given length passing through the midpoint.
| dist | The half-length of the perpendicular chord. The total length will be 2*dist. |
Segment perpendicular to this one, centered on its midpoint. | std::domain_error | if this segment has zero length. |
Definition at line 1212 of file point.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), Aleph::Point::get_y(), mid_point(), src_, and tgt_.
|
inline |
Returns the midpoint of this segment.
Point representing the midpoint. Definition at line 1115 of file point.H.
References Aleph::Point::get_x(), Aleph::Point::get_y(), src_, tgt_, and y.
Referenced by Segment(), mid_perpendicular(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
Returns whichever endpoint of this segment is nearer to a given point.
| p | The reference point. |
src_ or tgt_). Definition at line 1180 of file point.H.
References get_src_point(), get_tgt_point(), and Aleph::Point::nearest_point().
|
inline |
Checks for inequality between two segments.
| s | The other segment to compare. |
true if segments are not equal. Definition at line 870 of file point.H.
References Aleph::divide_and_conquer_partition_dp().
Checks for equality between two segments.
| s | The other segment to compare. |
true if segments are equal, false otherwise. Definition at line 859 of file point.H.
References Aleph::and, Aleph::divide_and_conquer_partition_dp(), src_, and tgt_.
Orthogonal projection of a point onto this segment's infinite line, clamped to the segment's endpoints.
| p | The point to project. |
p. Definition at line 1147 of file point.H.
References at(), Aleph::divide_and_conquer_partition_dp(), Aleph::Point::dot(), src_, and tgt_.
Referenced by brute_convex_distance_squared(), distance_to(), Aleph::ConvexPolygonDistanceGJK::exact_refine_disjoint(), and TEST_F().
|
inline |
Gets the endpoint with the largest x-coordinate.
Definition at line 906 of file point.H.
References Aleph::Point::get_x(), src_, and tgt_.
Referenced by Aleph::Tikz_Plane::bbox_of().
|
inline |
Rotates the segment by a given angle around its source point.
| angle | The angle of rotation in radians. |
Definition at line 1398 of file point.H.
References Aleph::divide_and_conquer_partition_dp(), rotate(), src_, and tgt_.
Referenced by Aleph::Regular_Polygon::get_vertex(), and rotate().
|
inline |
|
inline |
|
inline |
Returns the slope of the segment.
double. Returns +/- infinity for vertical lines. Definition at line 999 of file point.H.
References compute_slope().
Referenced by TEST_F().
|
inline |
Returns the exact slope of the segment as a Geom_Number.
| std::domain_error | if the segment is vertical. |
Definition at line 1009 of file point.H.
References ah_domain_error_if, Aleph::Point::get_x(), Aleph::Point::get_y(), src_, and tgt_.
|
inline |
Returns a string representation of the segment, e.g., "(x1,y1)(x2,y2)".
std::string representing the segment. Definition at line 1381 of file point.H.
References src_, tgt_, and Aleph::Point::to_string().
Referenced by operator std::string().
Definition at line 828 of file point.H.
Referenced by counterclockwise_angle().
|
private |
Definition at line 831 of file point.H.
Referenced by Segment(), at(), compute_slope(), contains(), counterclockwise_angle_with(), enlarge_src(), enlarge_tgt(), get_perpendicular(), get_src_point(), highest_point(), intersection_with(), intersects_properly_with(), intersects_with(), Aleph::Point::is_clockwise_with(), is_colinear_with(), Aleph::Point::is_colinear_with(), Aleph::Point::is_left_of(), is_parallel_with(), Aleph::Point::is_right_of(), leftmost_point(), length(), lowest_point(), mid_perpendicular(), mid_point(), operator==(), project(), reversed(), rightmost_point(), rotate(), sense(), slope_exact(), and to_string().
|
private |
Definition at line 831 of file point.H.
Referenced by Segment(), at(), compute_slope(), contains(), counterclockwise_angle_with(), enlarge_src(), enlarge_tgt(), get_perpendicular(), get_tgt_point(), highest_point(), intersection_with(), intersects_properly_with(), intersects_with(), Aleph::Point::is_clockwise_with(), is_colinear_with(), Aleph::Point::is_colinear_with(), Aleph::Point::is_left_of(), is_parallel_with(), Aleph::Point::is_right_of(), leftmost_point(), length(), lowest_point(), mid_perpendicular(), mid_point(), operator==(), project(), reversed(), rightmost_point(), rotate(), sense(), slope_exact(), and to_string().