CGAL 5.1 - 2D and 3D Linear Geometry Kernel
CGAL::Segment_2< Kernel > Class Template Reference

#include <CGAL/Segment_2.h>

Definition

template<typename Kernel>
class CGAL::Segment_2< Kernel >

An object s of the data type Segment_2 is a directed straight line segment in the two-dimensional Euclidean plane \( \E^2\), i.e. a straight line segment \( [p,q]\) connecting two points \( p,q \in \mathbb{R}^2\). The segment is topologically closed, i.e. the end points belong to it. Point p is called the source and q is called the target of s. The length of s is the Euclidean distance between p and q. Note that there is only a function to compute the square of the length, because otherwise we had to perform a square root operation which is not defined for all number types, which is expensive, and may not be exact.

Is Model Of:

Kernel::Segment_2

Hashable if Kernel is a cartesian kernel and if Kernel::FT is Hashable

Creation

 Segment_2 (const Point_2< Kernel > &p, const Point_2< Kernel > &q)
 introduces a segment s with source p and target q. More...
 

Operations

bool operator== (const Segment_2< Kernel > &q) const
 Test for equality: Two segments are equal, iff their sources and targets are equal. More...
 
bool operator!= (const Segment_2< Kernel > &q) const
 Test for inequality. More...
 
Point_2< Kernelsource () const
 returns the source of s. More...
 
Point_2< Kerneltarget () const
 returns the target of s. More...
 
Point_2< Kernelmin () const
 returns the point of s with lexicographically smallest coordinate. More...
 
Point_2< Kernelmax () const
 returns the point of s with lexicographically largest coordinate. More...
 
Point_2< Kernelvertex (int i) const
 returns source or target of s: vertex(0) returns the source of s, vertex(1) returns the target of s. More...
 
Point_2< Kernelpoint (int i) const
 returns vertex(i). More...
 
Point_2< Kerneloperator[] (int i) const
 returns vertex(i). More...
 
Kernel::FT squared_length () const
 returns the squared length of s. More...
 
Direction_2< Kerneldirection () const
 returns the direction from source to target of s. More...
 
Vector_2< Kernelto_vector () const
 returns the vector s.target() - s.source(). More...
 
Segment_2< Kernelopposite () const
 returns a segment with source and target point interchanged. More...
 
Line_2< Kernelsupporting_line () const
 returns the line l passing through s. More...
 

Predicates

bool is_degenerate () const
 segment s is degenerate, if source and target are equal. More...
 
bool is_horizontal () const
 
bool is_vertical () const
 
bool has_on (const Point_2< Kernel > &p) const
 A point is on s, iff it is equal to the source or target of s, or if it is in the interior of s. More...
 
bool collinear_has_on (const Point_2< Kernel > &p) const
 checks if point p is on segment s. More...
 

Miscellaneous

Bbox_2 bbox () const
 returns a bounding box containing s. More...
 
Segment_2< Kerneltransform (const Aff_transformation_2< Kernel > &t) const
 returns the segment obtained by applying t on the source and the target of s. More...
 

Constructor & Destructor Documentation

◆ Segment_2()

template<typename Kernel >
CGAL::Segment_2< Kernel >::Segment_2 ( const Point_2< Kernel > &  p,
const Point_2< Kernel > &  q 
)

introduces a segment s with source p and target q.

The segment is directed from the source towards the target.

Member Function Documentation

◆ bbox()

template<typename Kernel >
Bbox_2 CGAL::Segment_2< Kernel >::bbox ( ) const

returns a bounding box containing s.

◆ collinear_has_on()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::collinear_has_on ( const Point_2< Kernel > &  p) const

checks if point p is on segment s.

This function is faster than function has_on().

Precondition
p is on the supporting line of s.

◆ direction()

template<typename Kernel >
Direction_2<Kernel> CGAL::Segment_2< Kernel >::direction ( ) const

returns the direction from source to target of s.

◆ has_on()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::has_on ( const Point_2< Kernel > &  p) const

A point is on s, iff it is equal to the source or target of s, or if it is in the interior of s.

◆ is_degenerate()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::is_degenerate ( ) const

segment s is degenerate, if source and target are equal.

◆ is_horizontal()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::is_horizontal ( ) const

◆ is_vertical()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::is_vertical ( ) const

◆ max()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::max ( ) const

returns the point of s with lexicographically largest coordinate.

◆ min()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::min ( ) const

returns the point of s with lexicographically smallest coordinate.

◆ operator!=()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::operator!= ( const Segment_2< Kernel > &  q) const

Test for inequality.

◆ operator==()

template<typename Kernel >
bool CGAL::Segment_2< Kernel >::operator== ( const Segment_2< Kernel > &  q) const

Test for equality: Two segments are equal, iff their sources and targets are equal.

◆ operator[]()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::operator[] ( int  i) const

returns vertex(i).

◆ opposite()

template<typename Kernel >
Segment_2<Kernel> CGAL::Segment_2< Kernel >::opposite ( ) const

returns a segment with source and target point interchanged.

◆ point()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::point ( int  i) const

returns vertex(i).

◆ source()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::source ( ) const

returns the source of s.

◆ squared_length()

template<typename Kernel >
Kernel::FT CGAL::Segment_2< Kernel >::squared_length ( ) const

returns the squared length of s.

◆ supporting_line()

template<typename Kernel >
Line_2<Kernel> CGAL::Segment_2< Kernel >::supporting_line ( ) const

returns the line l passing through s.

Line l has the same orientation as segment s.

◆ target()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::target ( ) const

returns the target of s.

◆ to_vector()

template<typename Kernel >
Vector_2<Kernel> CGAL::Segment_2< Kernel >::to_vector ( ) const

returns the vector s.target() - s.source().

◆ transform()

template<typename Kernel >
Segment_2<Kernel> CGAL::Segment_2< Kernel >::transform ( const Aff_transformation_2< Kernel > &  t) const

returns the segment obtained by applying t on the source and the target of s.

◆ vertex()

template<typename Kernel >
Point_2<Kernel> CGAL::Segment_2< Kernel >::vertex ( int  i) const

returns source or target of s: vertex(0) returns the source of s, vertex(1) returns the target of s.

The parameter i is taken modulo 2, which gives easy access to the other vertex.