69# if defined(_LIBCPP_VERSION)
76inline std::ostream &
operator<<(std::ostream & o, mpq_srcptr q)
88inline std::ostream &
operator<<(std::ostream & o, mpz_srcptr z)
100inline std::ostream &
operator<<(std::ostream & o, mpf_srcptr f)
132 constexpr double PI = 3.1415926535897932384626433832795028841971693993751;
174 [[deprecated(
"Use euclidean_distance() instead")]]
270 return x_ == point.x_
and y_ == point.y_;
280 return not (*
this == point);
290 return x_ < point.x_
or (
x_ == point.x_
and y_ < point.y_);
355 return {
x_ * s,
y_ * s};
365 return {
x_ / s,
y_ / s};
428 return {
x_ * c -
y_ * s,
x_ * s +
y_ * c};
501 [[deprecated(
"Use is_left_of() instead")]]
541 [[deprecated(
"Use is_right_on_of() instead")]]
573 [[deprecated(
"Use is_left_of() instead")]]
580 [[deprecated(
"Use is_right_of() instead")]]
678 [[deprecated(
"Use distance_to() instead")]]
779 const Point cartesian(*
this);
780 const bool east = cartesian.
get_x() >= 0;
842 return std::numeric_limits<double>::max();
843 return -std::numeric_limits<double>::max();
872 return not (*
this == s);
1039 return angle.get_d();
1049 return x_axis.counterclockwise_angle_with(*
this);
1062 [[deprecated(
"Use length() instead")]]
1098 [[deprecated(
"Use is_left_of() instead")]]
1105 [[deprecated(
"Use is_right_of() instead")]]
1238 return (d1 * d2 < 0)
and (d3 * d4 < 0);
1252 [[deprecated(
"Use contains() instead")]]
1266 [[deprecated(
"Use contains() instead")]]
1323 return src_ + v1 * t;
1336 if (dir.
get_x() > 0)
1338 if (dir.
get_y() > 0)
1340 if (dir.
get_y() < 0)
1344 if (dir.
get_x() < 0)
1346 if (dir.
get_y() > 0)
1348 if (dir.
get_y() < 0)
1354 return dir.
get_y() > 0 ?
N :
S;
1389 operator std::string()
const
1458 return dx * dx + dy * dy;
1615 return not (*
this == t);
1653 (x1 * (y2 -
y3) + x2 * (
y3 -
y1) +
x3 * (
y1 - y2));
1654 ah_domain_error_if(d == 0) <<
"Cannot compute circumcenter of a degenerate triangle";
1760 return not (*
this ==
r);
1861 return this->xmax_ >=
that.xmin_
and this->ymax_ >=
that.ymin_
and
1874 if (p.get_x() <
xmin_)
1875 dx = p.get_x() -
xmin_;
1876 else if (p.get_x() >
xmax_)
1877 dx = p.get_x() -
xmax_;
1879 if (p.get_y() <
ymin_)
1880 dy = p.get_y() -
ymin_;
1881 else if (p.get_y() >
ymax_)
1882 dy = p.get_y() -
ymax_;
1884 return dx * dx + dy * dy;
1936 <<
"segment does not intersects with triangle";
1938 std::array<Point, 6> points;
1943 for (
size_t i = 0; i <
count; ++i)
1944 if (points[i] == pt)
1946 points[
count++] = pt;
1956 if (this->
contains(edge.get_src_point()))
1958 if (this->
contains(edge.get_tgt_point()))
1960 if (edge.contains(
this->get_src_point()))
1962 if (edge.contains(
this->get_tgt_point()))
1975 <<
"no intersection point found despite intersection confirmed";
1978 return {points[0], points[0]};
1984 for (
size_t i = 0; i <
count; ++i)
1985 for (
size_t j = i + 1; j <
count; ++j)
2072 return not (*
this == e);
2148 return t >= 0
and t <= 1;
2235 const Geom_Number A = (dx * dx) / a2 + (dy * dy) / b2;
2291 [[deprecated(
"Use contains() instead")]]
2322 const Geom_Number A = dx * dx / a2 + dy * dy / b2;
2355 return {touch, touch};
2529 return not (*
this == e);
2564 return (
lp.get_x() *
lp.get_x()) / (
a_ *
a_) +
2565 (
lp.get_y() *
lp.get_y()) / (
b_ *
b_);
2702 const char *ptr = str.c_str();
2705 for (
int i = 0;
true; )
2711 for (++i;
isalnum(ptr[i])
and ptr[i] !=
'\0'; )
2885 return s1.intersects_with(
s2);
2904 const Point & a =
s1.get_src_point();
2905 const Point & b =
s1.get_tgt_point();
2906 const Point & c =
s2.get_src_point();
2907 const Point & d =
s2.get_tgt_point();
2910 if (a == b
and c == d)
2922 if (
not s1.is_parallel_with(
s2))
2923 return s1.intersection_with(
s2);
3019 return ! (*
this == p);
3084 return {
x_ * s,
y_ * s,
z_ * s};
3094 return {
x_ / s,
y_ / s,
z_ / s};
3131 return dx * dx + dy * dy +
dz *
dz;
3301 return not (*
this == s);
3323 return dot >= 0 && dot <= d.
dot(d);
3441 <<
"Barycentric coordinates undefined for degenerate triangle";
3451 <<
"Barycentric coordinates undefined for degenerate triangle";
3547 if (
d0 == 0)
return false;
3557 return d1 >= 0
and d2 >= 0
and d3 >= 0
and d4 >= 0;
3558 return d1 <= 0
and d2 <= 0
and d3 <= 0
and d4 <= 0;
3592 o <<
"Point(" << p.
get_x() <<
", " << p.
get_y() <<
")";
3605 <<
", " << t.
get_p3() <<
")";
3630 <<
", " << p.
get_z() <<
")";
3643 <<
", " << t.
get_p3() <<
")";
3666 const std::size_t hx = std::hash<std::string>{}(p.
get_x().
get_str());
3667 const std::size_t hy = std::hash<std::string>{}(p.
get_y().
get_str());
3668 return hx ^ (hy + 0x9e3779b97f4a7c15ULL + (hx << 6) + (hx >> 2));
3677#if __cplusplus >= 202002L && __has_include(<format>)
3680# if defined(__cpp_lib_format)
3684struct std::formatter<
Aleph::Point> : std::formatter<std::string>
3686 auto format(
const Aleph::Point & p, std::format_context & ctx)
const
3688 return std::formatter<std::string>::format(
3689 std::format(
"Point({}, {})",
3697struct std::formatter<
Aleph::Segment> : std::formatter<std::string>
3699 auto format(
const Aleph::Segment & s, std::format_context & ctx)
const
3701 return std::formatter<std::string>::format(
3702 std::format(
"Segment({} -> {})",
3709struct std::formatter<
Aleph::Triangle> : std::formatter<std::string>
3711 auto format(
const Aleph::Triangle & t, std::format_context & ctx)
const
3713 return std::formatter<std::string>::format(
3714 std::format(
"Triangle({}, {}, {})",
3721struct std::formatter<
Aleph::Rectangle> : std::formatter<std::string>
3725 return std::formatter<std::string>::format(
3726 std::format(
"Rectangle({}, {} -- {}, {})",
3736struct std::formatter<
Aleph::Polar_Point> : std::formatter<std::string>
3740 return std::formatter<std::string>::format(
3741 std::format(
"PolarPoint(r={}, theta={})",
3749struct std::formatter<
Aleph::Ellipse> : std::formatter<std::string>
3751 auto format(
const Aleph::Ellipse & e, std::format_context & ctx)
const
3753 return std::formatter<std::string>::format(
3761struct std::formatter<
Aleph::RotatedEllipse> : std::formatter<std::string>
3765 return std::formatter<std::string>::format(
3773struct std::formatter<
Aleph::Point3D> : std::formatter<std::string>
3775 auto format(
const Aleph::Point3D & p, std::format_context & ctx)
const
3777 return std::formatter<std::string>::format(
3778 std::format(
"Point3D({}, {}, {})",
3787struct std::formatter<
Aleph::Segment3D> : std::formatter<std::string>
3791 return std::formatter<std::string>::format(
3792 std::format(
"Segment3D({} -> {})",
3799struct std::formatter<
Aleph::Triangle3D> : std::formatter<std::string>
3803 return std::formatter<std::string>::format(
3804 std::format(
"Triangle3D({}, {}, {})",
3811struct std::formatter<
Aleph::Tetrahedron> : std::formatter<std::string>
3815 return std::formatter<std::string>::format(
3816 std::format(
"Tetrahedron({}, {}, {}, {})",
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Debug assertion and warning utilities.
General utility functions and helpers.
static bool in_unit_interval(const Geom_Number &t)
Helper to check if a parameter t is in the [0, 1] interval.
const Geom_Number & get_vradius() const
Gets the vertical radius.
Ellipse(const Ellipse &e)=default
Copy constructor.
Geom_Number area() const
Calculates the area of the ellipse.
void compute_tangents(Segment &s1, Segment &s2, const Geom_Number &m) const
Computes the two tangent segments to this ellipse with a given slope.
std::string to_string() const
Returns a string representation of the ellipse.
Point sample(const Geom_Number &angle) const
Samples a point on the ellipse's boundary at a given angle.
Ellipse(Point center, const Geom_Number &hr, const Geom_Number &vr)
Constructs an ellipse.
bool intersects_with(const Point &p) const
Checks if a point lies exactly on the ellipse boundary.
const Point & get_center() const
Gets the center point of the ellipse.
Point highest_point() const
Gets the highest point on the ellipse boundary.
Point rightmost_point() const
Gets the rightmost point on the ellipse boundary.
Geom_Number perimeter() const
Approximates the perimeter of the ellipse.
bool intersects_with(const Segment &s) const
Checks if a segment intersects the ellipse.
bool contains_to(const Point &p) const
static bool is_clockwise()
Returns the orientation of the ellipse.
const Geom_Number & get_hradius() const
Gets the horizontal radius.
void validate_positive_radii() const
Validates that radii are positive.
Segment intersection_with(const Segment &sg) const
Computes the intersection segment between a line segment and this ellipse.
Geom_Number compute_radius(const Point &p) const
Computes the ellipse equation value for a point.
Point leftmost_point() const
Gets the leftmost point on the ellipse boundary.
Point lowest_point() const
Gets the lowest point on the ellipse boundary.
bool operator!=(const Ellipse &e) const noexcept
Checks for inequality.
Ellipse()
Default constructor.
bool operator==(const Ellipse &e) const noexcept
Checks for exact equality.
bool contains(const Point &p) const
Checks if a point lies inside or on the boundary of this ellipse.
Represents a point in 3D space with exact rational coordinates.
Point3D operator+(const Point3D &p) const
Vector addition.
Point3D & operator=(const Point3D &)=default
Point3D operator/(const Geom_Number &s) const
Scalar division.
Point3D()
Default constructor.
Point3D operator-() const
Unary negation.
static Point3D from_2d(const Point &p)
Lifts a 2D point to 3D, setting its z-coordinate to 0.
Point3D normalize() const
Returns a normalized copy of this vector (unit vector).
Point3D(const Geom_Number &x, const Geom_Number &y, const Geom_Number &z)
Constructs a 3D point from x, y, and z coordinates.
bool operator==(const Point3D &p) const
Checks for exact equality between two 3D points.
Point3D operator-(const Point3D &p) const
Vector subtraction.
bool operator!=(const Point3D &p) const
Checks for inequality between two 3D points.
Geom_Number distance_squared_to(const Point3D &p) const
Squared Euclidean distance to another point.
Point3D cross(const Point3D &p) const
Cross product.
const Geom_Number & get_z() const
Gets the z-coordinate.
Point3D & operator+=(const Point3D &p)
Vector addition and assignment.
const Geom_Number & get_x() const
Gets the x-coordinate.
Point3D operator*(const Geom_Number &s) const
Scalar multiplication.
Point3D(const Point3D &)=default
Geom_Number norm_squared() const
Squared Euclidean norm (magnitude).
const Geom_Number & get_y() const
Gets the y-coordinate.
Geom_Number distance_to(const Point3D &p) const
Euclidean distance to another point.
Point to_2d() const
Projects this 3D point to a 2D point by dropping the z-coordinate.
Point3D & operator-=(const Point3D &p)
Vector subtraction and assignment.
Geom_Number dot(const Point3D &p) const
Dot product.
static Point3D from_2d(const Point &p, const Geom_Number &z)
Lifts a 2D point to 3D with a specified z-coordinate.
Geom_Number norm() const
Euclidean norm (magnitude).
Represents a point with rectangular coordinates in a 2D plane.
bool is_to_right_from(const Point &p1, const Point &p2) const
Checks if this point is to the right of the directed line from p1 to p2.
bool is_between(const Point &p1, const Point &p2) const
Checks if this point is on the bounding box of p1 and p2 and is collinear with them.
Geom_Number distance_with(const Point &p) const
Geom_Number norm_squared() const
Squared Euclidean norm.
bool is_inside(const Segment &s) const
Checks if this point is contained within a segment.
Geom_Number norm() const
Euclidean norm (vector magnitude).
const Point & rightmost_point() const
Returns the rightmost point (largest x-coordinate).
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
bool operator==(const Point &point) const noexcept
Checks for exact equality between two points.
std::string to_string() const
Returns a string representation of the point as "(x,y)".
Geom_Number dot(const Point &p) const
Dot product.
bool intersects_with(const Ellipse &e) const
Checks if this point lies exactly on the boundary of an ellipse.
const Point & leftmost_point() const
Returns the leftmost point (smallest x-coordinate).
Point operator*(const Geom_Number &s) const
Scalar multiplication.
bool operator<(const Point &point) const noexcept
Defines a strict lexicographical ordering for points.
Point(const Geom_Number &x, const Geom_Number &y)
Constructs a point from Cartesian coordinates.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Point operator/(const Geom_Number &s) const
Scalar division.
Point midpoint(const Point &other) const
Calculates the midpoint between this point and another.
bool is_to_left_from(const Point &p1, const Point &p2) const
Geom_Number distance_to(const Point &p) const
Calculates the Euclidean distance to another point.
const Point & highest_point() const
Returns the highest point (largest y-coordinate).
Geom_Number cross(const Point &p) const
2D cross-product (z-component of the 3D cross-product).
bool is_clockwise_with(const Point &p1, const Point &p2) const
Determines if the sequence of three points (this, p1, p2) makes a clockwise turn.
Point lerp(const Point &other, const Geom_Number &t) const
Linear interpolation between this point and another.
const Point & nearest_point(const Point &p1, const Point &p2) const
Returns which of the two points, p1 or p2, is nearer to this point.
const Point & lowest_point() const
Returns the lowest point (smallest y-coordinate).
Point & operator-=(const Point &p)
Vector subtraction and assignment.
Point & operator+=(const Point &p)
Vector addition and assignment.
bool is_to_right_from(const Segment &s) const
bool is_right_on_of(const Point &p1, const Point &p2) const
Checks if this point is to the right of or on the line from p1 to p2.
bool is_to_left_from(const Segment &s) const
bool is_to_left_on_from(const Point &p1, const Point &p2) const
Checks if this point is to the left of or on the line from p1 to p2.
bool is_to_right_on_from(const Point &p1, const Point &p2) const
bool operator!=(const Point &point) const noexcept
Checks for inequality between two points.
Point operator+(const Point &p) const
Vector addition.
bool is_right_of(const Segment &s) const
Checks if this point is to the right of a directed segment.
bool is_left_of(const Point &p1, const Point &p2) const
Checks if this point is to the left of the directed line from p1 to p2.
Geom_Number distance_squared_to(const Point &that) const
Calculates the squared Euclidean distance to another point.
Point rotate(const Geom_Number &angle) const
Rotates the point around the origin by a given angle.
Point()
Default constructor.
Point operator-() const
Unary negation (vector inversion).
bool is_colinear_with(const Point &p1, const Point &p2) const
Checks if this point is collinear with two other points.
Point normalize() const
Returns a normalized copy of this vector (magnitude 1).
Polar representation of a 2D point.
Polar_Point(const Geom_Number &r, const Geom_Number &theta)
Constructs a polar point from a radius and an angle.
Quadrant
Enumerates polar quadrants in counterclockwise order.
Polar_Point(const Point &p)
Constructs a polar point from a Cartesian point.
const Geom_Number & get_theta() const
Gets the angle (theta) of the polar point.
Quadrant get_quadrant() const
Returns the quadrant where the point lies.
std::string to_string() const
Converts the polar point to a string representation "[r,theta]".
Polar_Point()=default
Default constructor.
const Geom_Number & get_r() const
Gets the radius (magnitude) of the polar point.
An axis-aligned rectangle.
const Geom_Number & get_xmin() const
Gets the minimum x-coordinate.
std::string to_string() const
Returns a string representation of the rectangle.
void set_rect(const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax)
Sets the coordinates of the rectangle.
Geom_Number area() const noexcept
Calculates the area of the rectangle.
Rectangle()
Default constructor.
Geom_Number perimeter() const noexcept
Calculates the perimeter of the rectangle.
bool intersects(const Rectangle &that) const noexcept
Checks if this axis-aligned rectangle intersects another one.
Geom_Number width() const noexcept
Calculates the width of the rectangle.
std::array< Point, 4 > corners() const noexcept
Gets the four corners of the rectangle.
const Geom_Number & get_ymax() const
Gets the maximum y-coordinate.
const Geom_Number & get_ymin() const
Gets the minimum y-coordinate.
Geom_Number distance_squared_to(const Point &p) const noexcept
Calculates the squared Euclidean distance from the rectangle to a point.
const Geom_Number & get_xmax() const
Gets the maximum x-coordinate.
Rectangle(const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax)
Constructs a rectangle from four coordinates.
Geom_Number distance_to(const Point &p) const
Calculates the Euclidean distance from the rectangle to a point.
bool operator==(const Rectangle &r) const noexcept
Checks for exact equality between two rectangles.
bool contains(const Point &p) const noexcept
Checks if this axis-aligned rectangle contains a point.
bool operator!=(const Rectangle &r) const noexcept
Checks for inequality between two rectangles.
Point center() const noexcept
Calculates the center point of the rectangle.
Geom_Number height() const noexcept
Calculates the height of the rectangle.
An ellipse with arbitrary rotation.
bool strictly_contains(const Point &p) const
Checks if a point lies strictly inside the ellipse.
RotatedEllipse(Point center, const Geom_Number &a, const Geom_Number &b, const Geom_Number &cos_theta, const Geom_Number &sin_theta)
Constructs a rotated ellipse.
bool operator!=(const RotatedEllipse &e) const noexcept
Checks for inequality between two rotated ellipses.
bool contains(const Point &p) const
Checks if a point lies inside or on the ellipse.
Point sample(const Geom_Number &t) const
Samples a point on the ellipse boundary for a parameter t.
RotatedEllipse(Point center, const Geom_Number &a, const Geom_Number &b)
Constructs an axis-aligned ellipse (rotation angle is 0).
Geom_Number radius_value(const Point &p) const
Evaluates the ellipse equation for a given point.
RotatedEllipse & operator=(const RotatedEllipse &)=default
const Geom_Number & get_b() const
Gets the semi-axis 'b' (local y-axis radius).
void normalize_rotation()
Normalizes the rotation (cos, sin) vector to ensure it's a unit vector.
Geom_Number area() const
Calculates the area of the ellipse.
Segment intersection_with(const Segment &s) const
Computes the intersection segment between s and this ellipse.
Point to_world(const Point &p) const
Transforms a point from the ellipse's local frame back to world coordinates.
Point sample(const Geom_Number &cos_t, const Geom_Number &sin_t) const
Samples a point on the ellipse boundary from a parametric angle.
ExtremalPoints extremal_points() const
Computes the four axis-extremal points of the rotated ellipse.
RotatedEllipse()
Default constructor.
const Geom_Number & get_sin() const
Gets the sine of the rotation angle.
std::string to_string() const
RotatedEllipse(const RotatedEllipse &)=default
Point to_local(const Point &p) const
Transforms a world point to the ellipse's local, unrotated frame.
bool on_boundary(const Point &p) const
Checks if a point lies exactly on the ellipse boundary.
bool intersects_with(const Segment &s) const
Checks if a segment intersects this rotated ellipse.
const Geom_Number & get_a() const
Gets the semi-axis 'a' (local x-axis radius).
const Geom_Number & get_cos() const
Gets the cosine of the rotation angle.
const Point & get_center() const
Gets the center point.
bool operator==(const RotatedEllipse &e) const noexcept
Checks for exact equality between two rotated ellipses.
void validate_positive_radii() const
Validates that semi-axes are positive.
Represents a line segment in 3D space.
bool operator==(const Segment3D &s) const
Checks for equality between two segments.
bool operator!=(const Segment3D &s) const
Checks for inequality.
Point3D midpoint() const
Calculates the midpoint of the segment.
bool contains(const Point3D &p) const
Checks if a point lies on the segment.
const Point3D & get_src() const noexcept
Gets the source point of the segment.
Geom_Number distance_to(const Point3D &p) const
Calculates the shortest distance from a point to this segment.
const Point3D & get_tgt() const noexcept
Gets the target point of the segment.
Segment3D()=default
Default constructor.
const Point3D & get_src_point() const noexcept
Gets the source point of the segment (alias for get_src).
Point3D at(const Geom_Number &t) const
Evaluates a point on the segment via linear interpolation.
Segment3D(const Point3D &src, const Point3D &tgt)
Constructs a 3D segment from two endpoints.
const Point3D & get_tgt_point() const noexcept
Gets the target point of the segment (alias for get_tgt).
Point3D direction() const
Calculates the direction vector of the segment.
Geom_Number length_squared() const
Calculates the squared length of the segment.
Geom_Number length() const
Calculates the length of the segment.
Represents a line segment between two points.
const Point & rightmost_point() const noexcept
Gets the endpoint with the largest x-coordinate.
bool intersects_properly_with(const Segment &s) const
Checks if this segment properly intersects another segment.
bool is_to_right_from(const Point &p) const
bool contains_to(const Point &p) const
bool contains(const Segment &s) const
Checks if another segment s lies entirely inside this segment.
Point mid_point() const
Returns the midpoint of this segment.
bool contains_to(const Segment &s) const
double slope() const
Returns the slope of the segment.
const Point & nearest_point(const Point &p) const
Returns whichever endpoint of this segment is nearer to a given point.
double counterclockwise_angle() const
Computes the counter-clockwise angle of this segment with respect to the x-axis.
Sense
Cardinal and intercardinal directions associated with a segment's vector.
bool is_left_of(const Point &p) const
Checks if this segment is to the left of a given point.
std::string to_string() const
Returns a string representation of the segment, e.g., "(x1,y1)(x2,y2)".
const Point & highest_point() const noexcept
Gets the endpoint with the largest y-coordinate.
double compute_slope() const
Internal helper to compute the slope as a double.
bool is_to_left_from(const Point &p) const
void rotate(const Geom_Number &angle)
Rotates the segment by a given angle around its source point.
Point intersection_with(const Segment &s) const
Computes the intersection point of the infinite lines defined by two segments.
const Point & lowest_point() const noexcept
Gets the endpoint with the smallest y-coordinate.
Segment(Point src, Point tgt)
Constructs a segment from two endpoints.
bool intersects_with(const Segment &s) const
Checks if this segment intersects another one (including endpoints and collinear overlap).
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.
Point project(const Point &p) const
Orthogonal projection of a point onto this segment's infinite line, clamped to the segment's endpoint...
const Point & leftmost_point() const noexcept
Gets the endpoint with the smallest x-coordinate.
Segment(const Segment &sg, const Geom_Number &dist)
Constructs a new segment parallel to a given segment at a specified distance.
Point at(const Geom_Number &t) const
Evaluates a point on the segment via linear interpolation.
double counterclockwise_angle_with(const Segment &s) const
Computes the counter-clockwise rotation angle FROM this segment TO another.
Segment()=default
Default constructor.
Segment mid_perpendicular(const Geom_Number &dist) const
Returns the perpendicular chord of a given length passing through the midpoint.
Segment reversed() const
Returns a new segment with the endpoints swapped.
bool is_right_of(const Point &p) const
Checks if this segment is to the right of a given point.
Geom_Number distance_to(const Point &p) const
Calculates the Euclidean distance from a point to this segment.
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.
bool contains(const Point &p) const
Checks if a point lies on this segment.
Geom_Number slope_exact() const
Returns the exact slope of the segment as a Geom_Number.
bool operator!=(const Segment &s) const noexcept
Checks for inequality between two segments.
Sense sense() const
Determines the cardinal/intercardinal direction of the segment.
bool is_colinear_with(const Point &p) const
Checks if a point is collinear with this segment.
bool operator==(const Segment &s) const noexcept
Checks for equality between two segments.
Segment(Point src, const Geom_Number &m, const Geom_Number &l)
Constructs a new segment from a source point, slope, and length.
const Point & get_tgt_point() const noexcept
Gets the target point of the segment.
bool is_parallel_with(const Segment &s) const
Checks if this segment is parallel to another one.
const Point & get_src_point() const noexcept
Gets the source point of the segment.
Geom_Number length() const
Returns the Euclidean length of the segment.
Segment get_perpendicular(const Point &p) const
Constructs a segment perpendicular to this that passes through point p.
Represents a tetrahedron in 3D space defined by four points.
Point3D centroid() const
Computes the centroid (center of mass) of the tetrahedron.
const Point3D & get_p4() const
Gets the fourth vertex.
Faces faces() const
Gets the four faces of the tetrahedron.
Geom_Number signed_volume_x6() const
Calculates 6 times the signed volume of the tetrahedron.
Tetrahedron(const Point3D &p1, const Point3D &p2, const Point3D &p3, const Point3D &p4)
Constructs a tetrahedron from four vertices.
Tetrahedron()=default
Default constructor.
bool is_degenerate() const
Checks if the tetrahedron is degenerate (i.e., its vertices are coplanar).
Geom_Number volume() const
Calculates the unsigned volume of the tetrahedron.
const Point3D & get_p1() const
Gets the first vertex.
const Point3D & get_p2() const
Gets the second vertex.
const Point3D & get_p3() const
Gets the third vertex.
bool contains(const Point3D &p) const
Checks if a point lies inside the tetrahedron.
Represents a text string positioned at a 2D point.
Text(Point p, const std::string &str)
Constructs a Text object.
Point lowest_point() const
Gets the lowest point (the anchor point).
static constexpr double font_height_in_points
static constexpr double font_width_in_points
Point highest_point() const
Gets the highest point (the anchor point).
Point rightmost_point() const
Gets the rightmost point (the anchor point).
const std::string & get_str() const
Gets the text string.
const Point & get_point() const
Gets the position point of the text.
Point leftmost_point() const
Gets the leftmost point (the anchor point).
const size_t & len() const
Gets the estimated length of the text.
Text()=default
Default constructor.
Represents a triangle in 3D space defined by three points.
BaryCoords barycentric(const Point3D &p) const
Computes the barycentric coordinates of a point p with respect to this triangle.
Point3D centroid() const
Computes the centroid (center of mass) of the triangle.
const Point3D & get_p2() const
Gets the second vertex of the triangle.
Triangle3D()=default
Default constructor.
const Point3D & get_p3() const
Gets the third vertex of the triangle.
Triangle3D(const Point3D &p1, const Point3D &p2, const Point3D &p3)
Constructs a 3D triangle from three vertices.
Point3D normal() const
Computes the normal vector of the triangle's plane.
const Point3D & get_p1() const
Gets the first vertex of the triangle.
Geom_Number double_area_squared() const
Calculates twice the squared area of the triangle.
bool is_degenerate() const
Checks if the triangle is degenerate (i.e., its vertices are collinear).
A non-degenerate triangle defined by three points.
Geom_Number perimeter() const
Computes the perimeter of the triangle.
Segment intersection_with(const Segment &s) const
Computes the intersection segment between this triangle and a segment.
const Point & get_p3() const
Gets the third vertex.
const Point & get_p2() const
Gets the second vertex.
bool contains(const Point &p) const
Checks if a point lies strictly inside this triangle.
Geom_Number area() const
Calculates the unsigned area of the triangle.
Point incenter() const
Computes the incenter of the triangle.
const Point & rightmost_point() const
Gets the vertex with the largest x-coordinate.
const Point & lowest_point() const
Gets the vertex with the smallest y-coordinate.
const Point & get_p1() const
Gets the first vertex.
bool operator==(const Triangle &t) const noexcept
Checks for equality between two triangles.
Triangle(const Segment &s, Point p)
Constructs a triangle from a segment and a point.
std::array< Segment, 3 > edges() const
Gets the three edges of the triangle.
const Point & highest_point() const
Gets the vertex with the largest y-coordinate.
const Point & leftmost_point() const
Gets the vertex with the smallest x-coordinate.
Point circumcenter() const
Computes the circumcenter of the triangle.
bool operator!=(const Triangle &t) const noexcept
Checks for inequality between two triangles.
Point centroid() const
Computes the centroid (center of mass) of the triangle.
Triangle(Point p1, Point p2, Point p3)
Constructs a triangle from three points.
Triangle(Point p, const Segment &s)
Constructs a triangle from a point and a segment.
bool is_clockwise() const
Checks if the triangle vertices are ordered clockwise.
std::string get_str(int base=10) const
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_hypot_function > > hypot(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__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_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_acos_function > > acos(const __gmp_expr< T, U > &expr)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
__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)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_atan2_function > > atan2(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_atan_function > > atan(const __gmp_expr< T, U > &expr)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
__gmp_expr< mpq_t, mpq_t > mpq_class
ostream & operator<<(ostream &os, const Task &t)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Orientation
Classification of three-point orientation.
Geom_Number in_circle_determinant(const Point &a, const Point &b, const Point &c, const Point &p)
Return the exact in-circle determinant for (a,b,c,p).
Geom_Number pitag(const Geom_Number &x, const Geom_Number &y)
Geom_Number area_of_parallelogram(const Point &a, const Point &b, const Point &c)
Compute the signed area of the parallelogram defined by vectors a->b and a->c.
Geom_Number scalar_triple_product(const Point3D &a, const Point3D &b, const Point3D &c)
Scalar triple product: a · (b × c).
bool on_segment(const Segment &s, const Point &p)
Return true if p lies on segment s (exact).
Geom_Number cosinus(const Geom_Number &x)
Cosine of x (wrapper over mpfr).
bool segments_intersect(const Segment &s1, const Segment &s2)
Return true if segments s1 and s2 intersect (including endpoints).
InCircleResult in_circle(const Point &a, const Point &b, const Point &c, const Point &p)
Classify point p against circumcircle of triangle (a,b,c), exactly.
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.
Point segment_intersection_point(const Segment &s1, const Segment &s2)
Compute the exact intersection point of segments s1 and s2.
InCircleResult
Classification of a point with respect to a triangle circumcircle.
Geom_Number square_root(const Geom_Number &x)
Square root of x (wrapper over mpfr).
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
Geom_Number area_of_triangle(const Point &a, const Point &b, const Point &c)
Return the (unsigned) area of triangle (a, b, c) as an exact rational.
Matrix< Trow, Tcol, NumType > operator*(const NumType &scalar, const Matrix< Trow, Tcol, NumType > &m)
Scalar-matrix multiplication (scalar * matrix).
Orientation orientation(const Point &a, const Point &b, const Point &c)
Return the orientation of the triple (a, b, c).
mpq_class Geom_Number
Numeric type used by the geometry module.
Geom_Number arctan2(const Geom_Number &m, const Geom_Number &n)
Two-argument arc tangent (wrapper over mpfr).
const Geom_Number & geom_pi()
High-precision pi value for computations that require Geom_Number.
size_t approximate_string_size(const std::string &str)
Estimate the count of printable characters in a LaTeX string.
Geom_Number arctan(const Geom_Number &m)
Arc tangent of m (wrapper over mpfr).
Geom_Number euclidean_distance(const Geom_Number &x, const Geom_Number &y)
Euclidean distance (hypotenuse) of the vector (x, y).
std::ostream & operator<<(std::ostream &osObject, const Field< T > &rightOp)
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Geom_Number sinus(const Geom_Number &x)
Sine of x (wrapper over mpfr).
Base class for all geometric objects.
virtual ~Geom_Object()=default
Holds the four axis-extremal points of a rotated ellipse.
A struct holding the four faces of the tetrahedron.
Structure to hold barycentric coordinates.
std::size_t operator()(const Aleph::Point &p) const
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)