196 <<
"Cannot create line from points with same x-coordinate (vertical line): "
197 <<
"x1 = " << x1 <<
", x2 = " << x2;
199 m = (y2 -
y1) / (x2 - x1);
233 :
LineEq(p1.get_x(), p1.get_y(), p2.get_x(), p2.get_y()) {}
273 return abs(
m) <= epsilon;
288 return abs(
m -
l.m) <= epsilon;
318 <<
"Cannot compute x for horizontal line (slope = 0)";
347 <<
"Cannot compute intersection of parallel lines: "
348 <<
"slope1 = " <<
m <<
", slope2 = " <<
l.m;
351 return {x, (*this)(x)};
368 <<
"Cannot compute perpendicular to horizontal line (would be vertical)";
402 return abs(
py - (*
this)(
px)) <= epsilon;
484 return not (*
this ==
l);
509 std::ostringstream s;
510 s <<
"y = " <<
y0 <<
" + " <<
m <<
" * x";
523 return out <<
l.to_string();
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
__gmp_expr< mpfr_t, mpfr_t > mpfr_class
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sqrt_function > > sqrt(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_abs_function > > abs(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
const Geom_Number LINE_EPSILON(0)
Default epsilon for geometric comparisons.
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.
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
mpq_class Geom_Number
Numeric type used by the geometry module.
2D point and geometric utilities.
2D infinite line in slope-intercept form.
bool operator!=(const LineEq &l) const noexcept
Test inequality of two lines.
std::pair< Geom_Number, Geom_Number > intersection(const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const
Compute the intersection point with another line.
LineEq perpendicular_through(const Geom_Number &px, const Geom_Number &py) const
Compute perpendicular line through a point.
bool approx_equal(const LineEq &l, const Geom_Number &epsilon) const noexcept
Test approximate equality of two lines.
Geom_Number operator()(const Geom_Number &x) const noexcept
Evaluate line at given x-coordinate.
bool is_horizontal(const Geom_Number &epsilon=LINE_EPSILON) const noexcept
Check if the line is horizontal (slope = 0).
constexpr LineEq() noexcept=default
Default constructor creates line y = x.
friend std::ostream & operator<<(std::ostream &out, const LineEq &l)
Output stream operator.
LineEq perpendicular_through(const Point &p) const
Compute a perpendicular line through a Point.
bool contains_point(const Point &p, const Geom_Number &epsilon=LINE_EPSILON) const noexcept
Check if a Point lies on this line.
const Geom_Number & y_intercept() const noexcept
Get the y-intercept of the line.
Geom_Number x_at(const Geom_Number &y) const
Compute x-coordinate for a given y-coordinate.
Point intersection_point(const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const
Compute the intersection Point with another line.
std::string to_string() const
Convert line to a string representation.
Geom_Number distance_to(const Geom_Number &px, const Geom_Number &py) const noexcept
Compute distance from a point to this line.
Geom_Number distance_to(const Point &p) const noexcept
Compute distance from a Point to this line.
LineEq(const Geom_Number &x1, const Geom_Number &y1, const Geom_Number &x2, const Geom_Number &y2)
Construct a line through two points.
bool is_perpendicular_to(const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const noexcept
Check if this line is perpendicular to another.
const Geom_Number & slope() const noexcept
Get the slope of the line.
LineEq(const Point &p, const Geom_Number &__m) noexcept
Construct a line through a Point with a given slope.
Geom_Number y0
Y-intercept (where line crosses y-axis)
LineEq(const Point &p1, const Point &p2)
Construct line through two Points.
LineEq(const Geom_Number &x1, const Geom_Number &y1, const Geom_Number &__m) noexcept
Construct line through a point with given slope.
Geom_Number m
Slope (dy/dx)
bool operator==(const LineEq &l) const noexcept
Test equality of two lines.
bool is_parallel_to(const LineEq &l, const Geom_Number &epsilon=LINE_EPSILON) const noexcept
Check if this line is parallel to another.
bool contains_point(const Geom_Number &px, const Geom_Number &py, const Geom_Number &epsilon=LINE_EPSILON) const noexcept
Check if a point lies on this line.