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

Fundamental segment defined by two points. More...

#include <point.H>

Inheritance diagram for Segment:
[legend]
Collaboration diagram for Segment:
[legend]

Public Types

enum  Sense {
  E , NE , N , NW ,
  W , S , SW , SE
}
 Cardinal directions associated with a segment. More...
 

Public Member Functions

bool operator== (const Segment &s) const
 
bool operator!= (const Segment &s) const
 
const Pointhighest_point () const
 
const Pointlowest_point () const
 
const Pointleftmost_point () const
 
const Pointrightmost_point () const
 
const Pointget_src_point () const
 
const Pointget_tgt_point () const
 
 Segment ()=default
 
 Segment (Point __src, const Point &__tgt)
 
 Segment (Point __src, const Geom_Number &m, const Geom_Number &l)
 Builds a new segment given source point, slope and length.
 
 Segment (const Segment &sg, const Geom_Number &dist)
 Builds a new segment parallel to sg and with a distance dist.
 
double slope () const
 
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.
 
Geom_Number size () const
 Return the Euclidean length of the segment (distance between endpoints).
 
bool is_colinear_with (const Point &p) const
 Return true if p is colinear with this segment.
 
bool is_to_left_from (const Point &p) const
 Return true if this segment is to the left of point p.
 
bool is_to_right_from (const Point &p) const
 Return true if this segment is to the right of point p.
 
Point mid_point () const
 Return the midpoint of this segment.
 
const Pointnearest_point (const Point &p) const
 Return whichever endpoint is nearer to p.
 
Segment get_perpendicular (const Point &p) const
 Construct the segment perpendicular to this passing through p.
 
Segment mid_perpendicular (const Geom_Number &dist) const
 Return the perpendicular chord of length 2*dist through the midpoint.
 
bool intersects_properly_with (const Segment &s) const
 Return true if the segments intersect at interior points only.
 
bool contains_to (const Point &p) const
 Return true if p lies on this segment.
 
bool contains_to (const Segment &s) const
 Return true if s lies entirely inside this segment.
 
bool intersects_with (const Segment &s) const
 Return true if s intersects this segment (including endpoints).
 
bool intersects_with (const Triangle &t) const
 
bool intersects_with (const Ellipse &e) const
 
bool is_parallel_with (const Segment &s) const
 Return true if s has the same slope.
 
Point intersection_with (const Segment &s) const
 Compute intersection point solving point-slope equations for both lines.
 
Sense sense () const
 
void enlarge_src (const Geom_Number &__dist)
 Extend the segment by __dist from the source endpoint.
 
void enlarge_tgt (const Geom_Number &__dist)
 Extend the segment by __dist from the target endpoint.
 
std::string to_string () const
 Return "(src)(tgt)" textual form.
 
 operator std::string () const
 
void rotate (const double &angle)
 Rotate the segment by angle (radians) around the source point.
 
Segment intersection_with (const Triangle &t) const
 
Segment intersection_with (const Ellipse &e) const
 
- Public Member Functions inherited from Geom_Object
 Geom_Object ()=default
 
virtual ~Geom_Object ()=default
 

Private Member Functions

double compute_slope () const
 

Static Private Member Functions

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.
 

Private Attributes

Point src
 
Point tgt
 

Friends

class Point
 
class Triangle
 

Detailed Description

Fundamental segment defined by two points.

Definition at line 416 of file point.H.

Member Enumeration Documentation

◆ Sense

Cardinal directions associated with a segment.

Enumerator
NE 
NW 
SW 
SE 

Definition at line 756 of file point.H.

Constructor & Destructor Documentation

◆ Segment() [1/4]

Segment::Segment ( )
default

◆ Segment() [2/4]

Segment::Segment ( Point  __src,
const Point __tgt 
)
inline

Definition at line 480 of file point.H.

◆ Segment() [3/4]

Segment::Segment ( Point  __src,
const Geom_Number m,
const Geom_Number l 
)
inline

Builds a new segment given source point, slope and length.

It computes the source point by usen these equations:

  1. \( d^2 = (x - x_1)^2 + (y - y_1)^2\) (Pythagoras)
  2. \( y - y_1 = m(x - x_1)\) (line equation given point and slope)
Parameters
[in]__srcSource point
[in]mslope (rise over run, dimensionless)
[in]llength

Definition at line 523 of file point.H.

◆ Segment() [4/4]

Segment::Segment ( const Segment sg,
const Geom_Number dist 
)
inline

Builds a new segment parallel to sg and with a distance dist.

Definition at line 532 of file point.H.

References get_src_point(), get_tgt_point(), mid_perpendicular(), mid_point(), src, and tgt.

Member Function Documentation

◆ compute_slope()

double Segment::compute_slope ( ) const
inlineprivate

Definition at line 423 of file point.H.

References __gmp_expr< mpq_t, mpq_t >::get_d(), src, tgt, Point::x, and Point::y.

Referenced by slope().

◆ compute_tgt_point()

static Point Segment::compute_tgt_point ( const Point __src,
const Geom_Number m,
const Geom_Number d 
)
inlinestaticprivate

Computes the target point of a segment given the source point, slope and length.

It uses the solution of these equations:

  • d^2 = (tx-sx)^2 + (ty-sy)^2 (Pythagorean theorem)
  • ty - sy = m(tx-sx) (line equation)
Returns
The point placed to the east (right).

Definition at line 497 of file point.H.

References square_root(), Point::x, y, and Point::y.

Referenced by enlarge_src(), and enlarge_tgt().

◆ contains_to() [1/2]

bool Segment::contains_to ( const Point p) const
inline

Return true if p lies on this segment.

Definition at line 700 of file point.H.

References Point::is_between(), src, and tgt.

Referenced by intersects_with(), and Point::is_inside().

◆ contains_to() [2/2]

bool Segment::contains_to ( const Segment s) const
inline

Return true if s lies entirely inside this segment.

Definition at line 706 of file point.H.

References get_src_point(), get_tgt_point(), Point::is_between(), src, and tgt.

◆ counterclockwise_angle()

double Segment::counterclockwise_angle ( ) const
inline

Compute the counterclockwise angle of this respect x-axis.

Definition at line 571 of file point.H.

References counterclockwise_angle_with(), and Point.

Referenced by TEST_F().

◆ counterclockwise_angle_with()

double Segment::counterclockwise_angle_with ( const Segment s) const
inline

Compute the counterclockwise wise angle respect another segment s.

Definition at line 550 of file point.H.

References arctan2(), __gmp_expr< mpq_t, mpq_t >::get_d(), PI, src, tgt, Point::x, Point::y, and y1().

Referenced by counterclockwise_angle(), Aleph::GiftWrappingConvexHull::operator()(), and TEST_F().

◆ enlarge_src()

void Segment::enlarge_src ( const Geom_Number __dist)
inline

Extend the segment by __dist from the source endpoint.

Definition at line 783 of file point.H.

References compute_tgt_point(), size(), slope(), and src.

Referenced by Ellipse::compute_tangents().

◆ enlarge_tgt()

void Segment::enlarge_tgt ( const Geom_Number __dist)
inline

Extend the segment by __dist from the target endpoint.

Definition at line 796 of file point.H.

References compute_tgt_point(), size(), slope(), and tgt.

Referenced by Ellipse::compute_tangents().

◆ get_perpendicular()

Segment Segment::get_perpendicular ( const Point p) const
inline

Construct the segment perpendicular to this passing through p.

Definition at line 618 of file point.H.

References Point::get_x(), Point::get_y(), Point, slope(), src, tgt, y, and y1().

Referenced by Aleph::QuickHull::get_fartest_point().

◆ get_src_point()

◆ get_tgt_point()

◆ highest_point()

const Point & Segment::highest_point ( ) const
inline

Definition at line 448 of file point.H.

References src, tgt, and Point::y.

Referenced by TEST_F().

◆ intersection_with() [1/3]

Segment Segment::intersection_with ( const Ellipse e) const
inline

Definition at line 1473 of file point.H.

References Ellipse::intersection_with().

◆ intersection_with() [2/3]

Point Segment::intersection_with ( const Segment s) const
inline

Compute intersection point solving point-slope equations for both lines.

Definition at line 733 of file point.H.

References ah_domain_error_if, is_parallel_with(), slope(), src, Point::x, y, Point::y, and y1().

Referenced by Triangle::intersection_with(), and intersection_with().

◆ intersection_with() [3/3]

Segment Segment::intersection_with ( const Triangle t) const
inline

◆ intersects_properly_with()

bool Segment::intersects_properly_with ( const Segment s) const
inline

Return true if the segments intersect at interior points only.

Definition at line 687 of file point.H.

References Point::is_colinear_with(), Point::is_to_left_from(), src, and tgt.

Referenced by intersects_with().

◆ intersects_with() [1/3]

bool Segment::intersects_with ( const Ellipse e) const
inline

Definition at line 1466 of file point.H.

References Ellipse::intersects_with().

◆ intersects_with() [2/3]

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

Return true if s intersects this segment (including endpoints).

Definition at line 713 of file point.H.

References contains_to(), intersects_properly_with(), src, and tgt.

Referenced by Aleph::CuttingEarsTriangulation::diagonalie(), intersection_with(), and intersects_with().

◆ intersects_with() [3/3]

bool Segment::intersects_with ( const Triangle t) const
inline

◆ is_colinear_with()

bool Segment::is_colinear_with ( const Point p) const
inline

Return true if p is colinear with this segment.

Definition at line 584 of file point.H.

References Point::is_colinear_with(), src, and tgt.

Referenced by TEST_F().

◆ is_parallel_with()

bool Segment::is_parallel_with ( const Segment s) const
inline

Return true if s has the same slope.

Definition at line 727 of file point.H.

References slope().

Referenced by intersection_with().

◆ is_to_left_from()

bool Segment::is_to_left_from ( const Point p) const
inline

Return true if this segment is to the left of point p.

Definition at line 590 of file point.H.

References Point::is_to_right_from().

Referenced by Ellipse::intersects_with(), and TEST_F().

◆ is_to_right_from()

bool Segment::is_to_right_from ( const Point p) const
inline

Return true if this segment is to the right of point p.

Definition at line 596 of file point.H.

References Point::is_to_left_from().

Referenced by TEST_F().

◆ leftmost_point()

const Point & Segment::leftmost_point ( ) const
inline

Definition at line 458 of file point.H.

References src, tgt, and Point::x.

Referenced by TEST_F().

◆ lowest_point()

const Point & Segment::lowest_point ( ) const
inline

Definition at line 453 of file point.H.

References src, tgt, and Point::y.

Referenced by TEST_F().

◆ mid_perpendicular()

Segment Segment::mid_perpendicular ( const Geom_Number dist) const
inline

Return the perpendicular chord of length 2*dist through the midpoint.

Definition at line 650 of file point.H.

References arctan(), Polar_Point::get_r(), Polar_Point::get_theta(), Point::is_to_right_from(), pitag(), Point, src, and tgt.

Referenced by Segment().

◆ mid_point()

Point Segment::mid_point ( ) const
inline

Return the midpoint of this segment.

Definition at line 602 of file point.H.

References Point::get_x(), Point::get_y(), src, tgt, and y.

Referenced by Segment(), TEST_F(), TEST_F(), and TEST_F().

◆ nearest_point()

const Point & Segment::nearest_point ( const Point p) const
inline

Return whichever endpoint is nearer to p.

Definition at line 612 of file point.H.

References get_src_point(), get_tgt_point(), and Point::nearest_point().

◆ operator std::string()

Segment::operator std::string ( ) const
inline

Definition at line 814 of file point.H.

References to_string().

◆ operator!=()

bool Segment::operator!= ( const Segment s) const
inline

Definition at line 443 of file point.H.

◆ operator==()

bool Segment::operator== ( const Segment s) const
inline

Definition at line 438 of file point.H.

References src, and tgt.

◆ rightmost_point()

const Point & Segment::rightmost_point ( ) const
inline

Definition at line 463 of file point.H.

References src, tgt, and Point::x.

Referenced by TEST_F().

◆ rotate()

void Segment::rotate ( const double &  angle)
inline

Rotate the segment by angle (radians) around the source point.

Definition at line 820 of file point.H.

References Polar_Point::get_r(), Polar_Point::get_theta(), src, and tgt.

Referenced by Regular_Polygon::get_vertex().

◆ sense()

Sense Segment::sense ( ) const
inline

Definition at line 758 of file point.H.

References E, N, NE, NW, S, SE, src, SW, tgt, W, Point::x, and Point::y.

◆ size()

Geom_Number Segment::size ( ) const
inline

Return the Euclidean length of the segment (distance between endpoints).

Definition at line 578 of file point.H.

References pitag(), src, tgt, Point::x, and Point::y.

Referenced by enlarge_src(), enlarge_tgt(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ slope()

double Segment::slope ( ) const
inline

◆ to_string()

std::string Segment::to_string ( ) const
inline

Return "(src)(tgt)" textual form.

Definition at line 809 of file point.H.

References src, tgt, and Point::to_string().

Referenced by operator std::string().

Friends And Related Symbol Documentation

◆ Point

friend class Point
friend

Definition at line 418 of file point.H.

Referenced by counterclockwise_angle(), get_perpendicular(), and mid_perpendicular().

◆ Triangle

friend class Triangle
friend

Definition at line 419 of file point.H.

Member Data Documentation

◆ src

◆ tgt


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