85constexpr double PI = 3.1415926535897932384626433832795028841971693993751;
187 return x == point.
x and y == point.
y;
192 return not (*
this == point);
197 return {
x + p.
x,
y + p.
y};
210 return {
x - p.
x,
y - p.
y};
378 const Point cartesian(*
this);
379 const bool east = cartesian.
get_x() >= 0;
380 const bool north = cartesian.
get_y() >= 0;
384 if (not east and north)
386 if (not east and not north)
428 return std::numeric_limits<double>::max();
429 return -std::numeric_limits<double>::max();
434 return __slope.
get_d();
445 return not (*
this == s);
565 return -angle.
get_d();
642 const Geom_Number x = (y2 -
y1 + m1 * x1 - m2 * x2) / (m1 - m2);
664 if (tgt_polar.
get_r() < 0)
668 arc_perp_pt = -arc_perp_pt;
671 const Polar_Point polar_perp_pt_l(perp_r, arc_tgt_src + arc_perp_pt);
674 const Polar_Point polar_perp_pt_r(perp_r, arc_tgt_src - arc_perp_pt);
746 const Geom_Number x = (y2 -
y1 + m1 * x1 - m2 * x2) / (m1 - m2);
785 const double m =
slope();
798 const double m =
slope();
814 operator std::string()
const
905 :
p1(__p1),
p2(__p2),
p3(__p3)
910 <<
"The three points of triangle are colinears";
919 <<
"The three points of triangle are collinear";
923 :
p1(s.src),
p2(s.tgt),
p3(p)
928 <<
"The three points of triangle are collinear";
1027 <<
"Invalid rectangle";
1042 return this->xmax >= that.
xmin and this->ymax >= that.
ymin and
1059 return dx * dx + dy * dy;
1091 <<
"segment does not intersects with triangle";
1104 catch (std::domain_error &)
1116 catch (std::domain_error &)
1122 return {p[0], p[1]};
1128 catch (std::domain_error &)
1317 return x2 / (
hr *
hr) + y2 / (
vr *
vr);
1410 assert(m == sg.
slope());
1418 assert(m2 >= 0 and yr2 >= 0 and xr2 >= 0);
1422 Geom_Number ab_root = -yr2 + 2 * m * xr * yr - m2 * xr2 + a2m2_plus_b2;
1435 const Geom_Number x1 = -(ab_root + sumx) / a2m2_plus_b2;
1439 const Geom_Number x2 = (ab_root - sumx) / a2m2_plus_b2;
1441 const Geom_Number y2 = (ab_m_root + sumy) / a2m2_plus_b2;
1491 const char *ptr = str.c_str();
1494 for (
int i = 0;
true; )
1500 for (++i;
isalnum(ptr[i])
and ptr[i] !=
'\0'; )
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.
size_t size() const noexcept
Count the number of elements of the list.
Geom_Number compute_radius(const Point &p) const
const Geom_Number & get_vradius() const
const Geom_Number & get_hradius() const
void compute_tangents(Segment &s1, Segment &s2, const Geom_Number &m) const
Point lowest_point() const
Segment intersection_with(const Segment &sg) const
Ellipse(Point __center, const Geom_Number &__hr, const Geom_Number &__vr)
const Point & get_center() const
Ellipse(const Ellipse &e)=default
bool intersects_with(const Point &p) const
bool intersects_with(const Segment &s) const
static bool is_clockwise()
Point leftmost_point() const
bool contains_to(const Point &p) const
Point rightmost_point() const
Point highest_point() const
Rectangular point in the plane.
Point & operator-=(const Point &p)
const Geom_Number & get_y() const
Returns y value.
const Point & highest_point() const
const Point & nearest_point(const Point &p1, const Point &p2) const
Return the nearest point (to this) between p1 and p2.
bool is_inside(const Segment &s) const
Returns true if this is inside of segment s.
const Point & leftmost_point() const
bool is_to_right_from(const Point &p1, const Point &p2) const
Return true if this is to right from points p1 and p2.
bool intersects_with(const Ellipse &e) const
Returns true if this intersects ellipse e.
bool is_colinear_with(const Point &p1, const Point &p2) const
Returns true if this is colinear with p1 and p2.
Point operator+(const Point &p) const
bool is_to_left_on_from(const Point &p1, const Point &p2) const
Return true if this is to left from (or on) points p1 and p2.
bool is_clockwise_with(const Point &p1, const Point &p2) const
Returns true if the sequence this-p1-p2 is clockwise.
const Point & rightmost_point() const
bool is_to_left_from(const Point &p1, const Point &p2) const
Return true if this is to left from points p1 and p2.
std::string to_string() const
Return a string representation of this.
bool is_between(const Point &p1, const Point &p2) const
Returns true if this is between p1 and p2.
Geom_Number distance_with(const Point &p) const
Returns the Euclidean distance between this and p.
Point(const Geom_Number &__x, const Geom_Number &__y)
Builds a new point in coordinates (__x, __y)
const Point & lowest_point() const
bool operator!=(const Point &point) const
bool is_to_right_on_from(const Point &p1, const Point &p2) const
Return true if this is to right from (or on) points p1 and p2.
Point & operator+=(const Point &p)
Point operator-(const Point &p) const
Geom_Number distance_squared_to(const Point &that) const
Returns the square distance between this y that.
const Geom_Number & get_x() const
Returns x value.
bool operator==(const Point &point) const
Polar representation of a 2D point.
Quadrant
Enumerate polar quadrants in counterclockwise order.
const Geom_Number & get_theta() const
Returns the angle.
std::string to_string() const
Convert to string representation "[r,theta]".
Polar_Point(const Point &p)
Construct from Cartesian coordinates (origin at (0,0)).
Polar_Point(const Geom_Number &__r, const Geom_Number &__theta)
Quadrant get_quadrant() const
Return the quadrant where the point lies (origin defaults to First).
const Geom_Number & get_r() const
Returns the magnitude.
bool contains(const Point &p) const
void set_rect(const Geom_Number &__xmin, const Geom_Number &__ymin, const Geom_Number &__xmax, const Geom_Number &__ymax)
const Geom_Number & get_xmin() const
const Geom_Number & get_ymin() const
const Geom_Number & get_xmax() const
Geom_Number height() const
Geom_Number distance_squared_to(const Point &p) const
Rectangle(const Geom_Number &__xmin, const Geom_Number &__ymin, const Geom_Number &__xmax, const Geom_Number &__ymax)
Geom_Number distance_to(const Point &p) const
bool intersects(const Rectangle &that) const
const Geom_Number & get_ymax() const
Geom_Number width() const
Fundamental segment defined by two points.
const Point & get_tgt_point() const
Segment get_perpendicular(const Point &p) const
Construct the segment perpendicular to this passing through p.
std::string to_string() const
Return "(src)(tgt)" textual form.
const Point & nearest_point(const Point &p) const
Return whichever endpoint is nearer to p.
Sense
Cardinal directions associated with a segment.
bool is_colinear_with(const Point &p) const
Return true if p is colinear with this segment.
void enlarge_tgt(const Geom_Number &__dist)
Extend the segment by __dist from the target endpoint.
double counterclockwise_angle_with(const Segment &s) const
Compute the counterclockwise wise angle respect another segment s.
double counterclockwise_angle() const
Compute the counterclockwise angle of this respect x-axis.
Point intersection_with(const Segment &s) const
Compute intersection point solving point-slope equations for both lines.
static Point compute_tgt_point(const Point &__src, const Geom_Number &m, const Geom_Number &d)
Computes the target point of a segment given the source point, slope and length.
double compute_slope() const
const Point & rightmost_point() const
Geom_Number size() const
Return the Euclidean length of the segment (distance between endpoints).
const Point & lowest_point() const
bool intersects_with(const Segment &s) const
Return true if s intersects this segment (including endpoints).
bool is_to_left_from(const Point &p) const
Return true if this segment is to the left of point p.
Segment(Point __src, const Geom_Number &m, const Geom_Number &l)
Builds a new segment given source point, slope and length.
Point mid_point() const
Return the midpoint of this segment.
Segment mid_perpendicular(const Geom_Number &dist) const
Return the perpendicular chord of length 2*dist through the midpoint.
const Point & highest_point() const
void enlarge_src(const Geom_Number &__dist)
Extend the segment by __dist from the source endpoint.
bool contains_to(const Point &p) const
Return true if p lies on this segment.
bool is_to_right_from(const Point &p) const
Return true if this segment is to the right of point p.
bool operator!=(const Segment &s) const
bool operator==(const Segment &s) const
Segment(Point __src, const Point &__tgt)
const Point & leftmost_point() const
const Point & get_src_point() const
bool contains_to(const Segment &s) const
Return true if s lies entirely inside this segment.
bool is_parallel_with(const Segment &s) const
Return true if s has the same slope.
void rotate(const double &angle)
Rotate the segment by angle (radians) around the source point.
bool intersects_properly_with(const Segment &s) const
Return true if the segments intersect at interior points only.
Segment(const Segment &sg, const Geom_Number &dist)
Builds a new segment parallel to sg and with a distance dist.
static const double font_width_in_points
Text(const Point &__p, const std::string &__str)
const Point & get_point() const
const std::string & get_str() const
Point leftmost_point() const
const size_t & len() const
Point highest_point() const
Point lowest_point() const
static const double font_height_in_points
Point rightmost_point() const
Triangle(const Segment &s, const Point &p)
Triangle(Point p, const Segment &s)
const Point & highest_point() const
const Point & rightmost_point() const
const Point & get_p1() const
const Point & lowest_point() const
const Point & leftmost_point() const
bool is_clockwise() const
Returns true if the triangle vertices are ordered clockwise.
Segment intersection_with(const Segment &s) const
Returns the intersection segment between this triangle and segment s.
const Point & get_p3() const
Triangle(const Point &__p1, const Point &__p2, const Point &__p3)
bool contains_to(const Point &p) const
Returns true if point p lies inside this triangle.
const Point & get_p2() 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< 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)
DynList< T > maps(const C &c, Op op)
Classic map operation.
mpq_class Geom_Number
Numeric type used by the geometry module.
Geom_Number pitag(const Geom_Number &x, const Geom_Number &y)
Return the Euclidean distance.
Geom_Number arctan2(const Geom_Number &m, const Geom_Number &n)
Two-argument arc tangent (wrapper over mpfr).
double geom_number_to_double(const Geom_Number &n)
Geom_Number arctan(const Geom_Number &m)
Arc tangent of m (wrapper over mpfr).
std::ostream & operator<<(std::ostream &o, const Geom_Number &n)
Geom_Number square_root(const Geom_Number &x)
Square root of x (wrapper over mpfr).
Geom_Number cosinus(const Geom_Number &x)
Cosine of x (wrapper over mpfr).
Geom_Number sinus(const Geom_Number &x)
Sine of x (wrapper over mpfr).
size_t aproximate_string_size(const std::string &str)
Geom_Number area_of_parallelogram(const Point &a, const Point &b, const Point &c)
Compute the area of parallelogram defined by vectors a->b and b->c.
virtual ~Geom_Object()=default