Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Ellipse Class Reference

An axis-aligned ellipse. More...

#include <point.H>

Inheritance diagram for Aleph::Ellipse:
[legend]
Collaboration diagram for Aleph::Ellipse:
[legend]

Public Member Functions

 Ellipse (Point center, const Geom_Number &hr, const Geom_Number &vr)
 Constructs an ellipse.
 
 Ellipse (const Ellipse &e)=default
 Copy constructor.
 
 Ellipse ()
 Default constructor.
 
bool operator== (const Ellipse &e) const noexcept
 Checks for exact equality.
 
bool operator!= (const Ellipse &e) const noexcept
 Checks for inequality.
 
const Pointget_center () const
 Gets the center point of the ellipse.
 
const Geom_Numberget_hradius () const
 Gets the horizontal radius.
 
const Geom_Numberget_vradius () const
 Gets the vertical radius.
 
Geom_Number area () const
 Calculates the area of the ellipse.
 
Geom_Number perimeter () const
 Approximates the perimeter of the ellipse.
 
Point sample (const Geom_Number &angle) const
 Samples a point on the ellipse's boundary at a given angle.
 
std::string to_string () const
 Returns a string representation of the ellipse.
 
Point highest_point () const
 Gets the highest point on the ellipse boundary.
 
Point lowest_point () const
 Gets the lowest point on the ellipse boundary.
 
Point leftmost_point () const
 Gets the leftmost point on the ellipse boundary.
 
Point rightmost_point () const
 Gets the rightmost point on the ellipse boundary.
 
void compute_tangents (Segment &s1, Segment &s2, const Geom_Number &m) const
 Computes the two tangent segments to this ellipse with a given slope.
 
bool intersects_with (const Segment &s) const
 Checks if a segment intersects the ellipse.
 
bool contains (const Point &p) const
 Checks if a point lies inside or on the boundary of this ellipse.
 
bool contains_to (const Point &p) const
 
bool intersects_with (const Point &p) const
 Checks if a point lies exactly on the ellipse boundary.
 
Segment intersection_with (const Segment &sg) const
 Computes the intersection segment between a line segment and this ellipse.
 
- Public Member Functions inherited from Aleph::Geom_Object
 Geom_Object ()=default
 
virtual ~Geom_Object ()=default
 

Static Public Member Functions

static bool is_clockwise ()
 Returns the orientation of the ellipse.
 

Private Member Functions

void validate_positive_radii () const
 Validates that radii are positive.
 
Geom_Number compute_radius (const Point &p) const
 Computes the ellipse equation value for a point.
 

Static Private Member Functions

static bool in_unit_interval (const Geom_Number &t)
 Helper to check if a parameter t is in the [0, 1] interval.
 

Private Attributes

Point center_
 
Geom_Number hr_
 
Geom_Number vr_
 

Friends

class Point
 

Detailed Description

An axis-aligned ellipse.

Represents an axis-aligned ellipse centered at a point with a horizontal and a vertical radius. Provides methods for calculating geometric properties and handling intersections.

Definition at line 2005 of file point.H.

Constructor & Destructor Documentation

◆ Ellipse() [1/3]

Aleph::Ellipse::Ellipse ( Point  center,
const Geom_Number hr,
const Geom_Number vr 
)
inline

Constructs an ellipse.

Parameters
centerThe center point of the ellipse.
hrThe horizontal radius.
vrThe vertical radius.
Exceptions
std::domain_errorif either radius is not positive.

Definition at line 2032 of file point.H.

References validate_positive_radii().

◆ Ellipse() [2/3]

Aleph::Ellipse::Ellipse ( const Ellipse e)
default

Copy constructor.

◆ Ellipse() [3/3]

Aleph::Ellipse::Ellipse ( )
inline

Default constructor.

Note
Creates a unit circle centered at the origin.

Definition at line 2050 of file point.H.

Member Function Documentation

◆ area()

Geom_Number Aleph::Ellipse::area ( ) const
inline

Calculates the area of the ellipse.

Returns
The area (pi * hr * vr).

Definition at line 2086 of file point.H.

References Aleph::geom_pi(), hr_, validate_positive_radii(), and vr_.

◆ compute_radius()

Geom_Number Aleph::Ellipse::compute_radius ( const Point p) const
inlineprivate

Computes the ellipse equation value for a point.

Calculates (x-xc)^2/hr^2 + (y-yc)^2/vr^2.

Parameters
pThe point to evaluate.
Returns
A value that is < 1 for interior points, = 1 for boundary points, and > 1 for exterior points.

Definition at line 2266 of file point.H.

References center_, Aleph::Point::get_x(), Aleph::Point::get_y(), hr_, validate_positive_radii(), and vr_.

Referenced by contains(), and intersects_with().

◆ compute_tangents()

void Aleph::Ellipse::compute_tangents ( Segment s1,
Segment s2,
const Geom_Number m 
) const
inline

Computes the two tangent segments to this ellipse with a given slope.

Parameters
[out]s1The first tangent segment.
[out]s2The second tangent segment.
[in]mThe slope of the tangents.

Definition at line 2189 of file point.H.

References ah_domain_error_if, center_, Aleph::divide_and_conquer_partition_dp(), hr_, m, Point, Aleph::square_root(), validate_positive_radii(), and vr_.

◆ contains()

bool Aleph::Ellipse::contains ( const Point p) const
inline

Checks if a point lies inside or on the boundary of this ellipse.

Parameters
pThe point to check.
Returns
true if the point is contained within the ellipse.

Definition at line 2285 of file point.H.

References compute_radius().

Referenced by contains_to(), Aleph::Point::is_inside(), TEST_F(), and TEST_F().

◆ contains_to()

bool Aleph::Ellipse::contains_to ( const Point p) const
inline
Deprecated:
Use contains() instead.

Definition at line 2292 of file point.H.

References contains().

◆ get_center()

const Point & Aleph::Ellipse::get_center ( ) const
inline

Gets the center point of the ellipse.

Definition at line 2076 of file point.H.

References center_.

Referenced by Aleph::Tikz_Plane::draw_ellipse(), and Eepic_Plane::draw_ellipse().

◆ get_hradius()

const Geom_Number & Aleph::Ellipse::get_hradius ( ) const
inline

Gets the horizontal radius.

Definition at line 2078 of file point.H.

References hr_.

Referenced by Aleph::Tikz_Plane::draw_ellipse(), Eepic_Plane::draw_ellipse(), and TEST_F().

◆ get_vradius()

const Geom_Number & Aleph::Ellipse::get_vradius ( ) const
inline

Gets the vertical radius.

Definition at line 2080 of file point.H.

References vr_.

Referenced by Aleph::Tikz_Plane::draw_ellipse(), Eepic_Plane::draw_ellipse(), and TEST_F().

◆ highest_point()

Point Aleph::Ellipse::highest_point ( ) const
inline

Gets the highest point on the ellipse boundary.

Definition at line 2159 of file point.H.

References center_, Aleph::Point::get_x(), Aleph::Point::get_y(), and vr_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ in_unit_interval()

static bool Aleph::Ellipse::in_unit_interval ( const Geom_Number t)
inlinestaticprivate

Helper to check if a parameter t is in the [0, 1] interval.

Definition at line 2146 of file point.H.

References Aleph::and.

Referenced by intersection_with(), and intersects_with().

◆ intersection_with()

Segment Aleph::Ellipse::intersection_with ( const Segment sg) const
inline

Computes the intersection segment between a line segment and this ellipse.

Parameters
sgThe segment to intersect with.
Returns
A Segment representing the portion of sg inside the ellipse. If tangent, the segment is degenerate (a point).
Exceptions
std::domain_errorif there is no intersection.

Definition at line 2311 of file point.H.

References ah_domain_error_if, Aleph::and, Aleph::Segment::at(), center_, Aleph::divide_and_conquer_partition_dp(), Aleph::Segment::get_src_point(), Aleph::Segment::get_tgt_point(), Aleph::Point::get_x(), Aleph::Point::get_y(), hr_, in_unit_interval(), root(), Aleph::square_root(), validate_positive_radii(), and vr_.

Referenced by Aleph::Segment::intersection_with(), Aleph::RotatedEllipse::intersection_with(), and TEST_F().

◆ intersects_with() [1/2]

bool Aleph::Ellipse::intersects_with ( const Point p) const
inline

Checks if a point lies exactly on the ellipse boundary.

Parameters
pThe point to check.
Returns
true if the point is on the boundary.

Definition at line 2299 of file point.H.

References compute_radius().

◆ intersects_with() [2/2]

bool Aleph::Ellipse::intersects_with ( const Segment s) const
inline

Checks if a segment intersects the ellipse.

Solves the quadratic equation for the intersection of a line and an ellipse.

Parameters
sThe segment to check.
Returns
true if the segment and ellipse share at least one point.

Definition at line 2224 of file point.H.

References center_, Aleph::divide_and_conquer_partition_dp(), Aleph::Segment::get_src_point(), Aleph::Segment::get_tgt_point(), Aleph::Point::get_x(), Aleph::Point::get_y(), hr_, in_unit_interval(), root(), Aleph::square_root(), validate_positive_radii(), and vr_.

Referenced by Aleph::Point::intersects_with(), Aleph::Segment::intersects_with(), Aleph::RotatedEllipse::intersects_with(), TEST_F(), TEST_F(), and TEST_F().

◆ is_clockwise()

static bool Aleph::Ellipse::is_clockwise ( )
inlinestatic

Returns the orientation of the ellipse.

Always counter-clockwise.

Returns
false, indicating CCW.

Definition at line 2156 of file point.H.

Referenced by TEST_F().

◆ leftmost_point()

Point Aleph::Ellipse::leftmost_point ( ) const
inline

Gets the leftmost point on the ellipse boundary.

Definition at line 2171 of file point.H.

References center_, Aleph::Point::get_x(), Aleph::Point::get_y(), and hr_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ lowest_point()

Point Aleph::Ellipse::lowest_point ( ) const
inline

Gets the lowest point on the ellipse boundary.

Definition at line 2165 of file point.H.

References center_, Aleph::Point::get_x(), Aleph::Point::get_y(), and vr_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ operator!=()

bool Aleph::Ellipse::operator!= ( const Ellipse e) const
inlinenoexcept

Checks for inequality.

Parameters
eThe other ellipse.
Returns
true if center or radii are different.

Definition at line 2070 of file point.H.

References Aleph::divide_and_conquer_partition_dp().

◆ operator==()

bool Aleph::Ellipse::operator== ( const Ellipse e) const
inlinenoexcept

Checks for exact equality.

Parameters
eThe other ellipse.
Returns
true if center and radii are identical.

Definition at line 2060 of file point.H.

References Aleph::and, center_, hr_, and vr_.

◆ perimeter()

Geom_Number Aleph::Ellipse::perimeter ( ) const
inline

Approximates the perimeter of the ellipse.

Uses Ramanujan's second approximation formula for the perimeter.

Returns
The approximate perimeter length.

Definition at line 2097 of file point.H.

References Aleph::divide_and_conquer_partition_dp(), Aleph::geom_pi(), h, hr_, Aleph::square_root(), validate_positive_radii(), and vr_.

◆ rightmost_point()

Point Aleph::Ellipse::rightmost_point ( ) const
inline

Gets the rightmost point on the ellipse boundary.

Definition at line 2177 of file point.H.

References center_, Aleph::Point::get_x(), Aleph::Point::get_y(), and hr_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ sample()

Point Aleph::Ellipse::sample ( const Geom_Number angle) const
inline

Samples a point on the ellipse's boundary at a given angle.

Parameters
angleThe parametric angle in radians.
Returns
A Point on the ellipse's boundary.

Definition at line 2113 of file point.H.

References center_, Aleph::cosinus(), Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), Aleph::Point::get_y(), hr_, Aleph::sinus(), validate_positive_radii(), and vr_.

◆ to_string()

std::string Aleph::Ellipse::to_string ( ) const
inline

Returns a string representation of the ellipse.

Returns
A std::string describing the ellipse's properties.

Definition at line 2126 of file point.H.

References center_, Aleph::geom_number_to_double(), hr_, Aleph::Point::to_string(), and vr_.

Referenced by Aleph::operator<<().

◆ validate_positive_radii()

void Aleph::Ellipse::validate_positive_radii ( ) const
inlineprivate

Validates that radii are positive.

Exceptions
std::domain_errorif either radius is not > 0.

Definition at line 2138 of file point.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), hr_, and vr_.

Referenced by Ellipse(), area(), compute_radius(), compute_tangents(), intersection_with(), intersects_with(), perimeter(), and sample().

Friends And Related Symbol Documentation

◆ Point

friend class Point
friend

Definition at line 2007 of file point.H.

Referenced by compute_tangents().

Member Data Documentation

◆ center_

◆ hr_

◆ vr_


The documentation for this class was generated from the following file: