190 <<
"Cannot create line from points with same x-coordinate (vertical line): "
191 <<
"x1 = " << x1 <<
", x2 = " << x2;
193 m = (y2 -
y1) / (x2 - x1);
235 return std::abs(
m) < epsilon;
250 return std::abs(
m -
l.m) < epsilon;
265 return std::abs(
m *
l.m + 1.0) < epsilon;
280 <<
"Cannot compute x for horizontal line (slope = 0)";
309 <<
"Cannot compute intersection of parallel lines: "
310 <<
"slope1 = " <<
m <<
", slope2 = " <<
l.m;
312 double x = (
y0 -
l.y0) / (
l.m -
m);
313 return {x, (*this)(x)};
330 <<
"Cannot compute perpendicular to horizontal line (would be vertical)";
348 return std::abs(
diff) / std::sqrt(1.0 +
m *
m);
362 return std::abs(
py - (*
this)(
px)) < epsilon;
388 return not (*
this ==
l);
398 std::ostringstream s;
399 s <<
"y = " <<
y0 <<
" + " <<
m <<
" * x";
412 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.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
constexpr double LINE_EPSILON
Default epsilon for floating-point comparisons.
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
DynList< T > maps(const C &c, Op op)
Classic map operation.
2D infinite line in slope-intercept form.
LineEq(double x1, double y1, double x2, double y2)
Construct line through two points.
constexpr bool is_horizontal(double epsilon=LINE_EPSILON) const noexcept
Check if the line is horizontal (slope = 0).
bool operator!=(const LineEq &l) const noexcept
Test inequality of two lines.
double x_at(double y) const
Compute x-coordinate for a given y-coordinate.
constexpr LineEq(double x1, double y1, double __m) noexcept
Construct line through a point with given slope.
double distance_to(double px, double py) const noexcept
Compute distance from a point to this line.
double y0
Y-intercept (where line crosses y-axis)
constexpr LineEq() noexcept=default
Default constructor creates line y = x.
constexpr bool is_parallel_to(const LineEq &l, double epsilon=LINE_EPSILON) const noexcept
Check if this line is parallel to another.
friend std::ostream & operator<<(std::ostream &out, const LineEq &l)
Output stream operator.
LineEq perpendicular_through(double px, double py) const
Compute perpendicular line through a point.
constexpr double y_intercept() const noexcept
Get the y-intercept of the line.
constexpr double operator()(double x) const noexcept
Evaluate line at given x-coordinate.
std::string to_string() const
Convert line to string representation.
std::pair< double, double > intersection(const LineEq &l, double epsilon=LINE_EPSILON) const
Compute intersection point with another line.
bool contains_point(double px, double py, double epsilon=LINE_EPSILON) const noexcept
Check if a point lies on this line.
bool operator==(const LineEq &l) const noexcept
Test equality of two lines.
constexpr bool is_perpendicular_to(const LineEq &l, double epsilon=LINE_EPSILON) const noexcept
Check if this line is perpendicular to another.
constexpr double slope() const noexcept
Get the slope of the line.