## CGAL::Segment_2<Kernel>

### Definition

An object s of the data type Segment_2<Kernel> is a directed straight line segment in the two-dimensional Euclidean plane 2, i.e. a straight line segment [p,q] connecting two points p,q 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.

### Creation

 Segment_2 s ( Point_2 p, Point_2 q); introduces a segment s with source p and target q. The segment is directed from the source towards the target.

### Operations

 bool s.operator== ( q) const Test for equality: Two segments are equal, iff their sources and targets are equal. bool s.operator!= ( q) const Test for inequality. Point_2 s.source () const returns the source of s. Point_2 s.target () const returns the target of s. Point_2 s.min () const returns the point of s with lexicographically smallest coordinate. Point_2 s.max () const returns the point of s with lexicographically largest coordinate. Point_2 s.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. Point_2 s.point ( int i) const returns vertex(i). Point_2 s.operator[] ( int i) const returns vertex(i). Kernel::FT s.squared_length () const returns the squared length of s. Direction_2 s.direction () const returns the direction from source to target of s. Vector_2 s.to_vector () const returns the vector s.target() - s.source(). Segment_2 s.opposite () const returns a segment with source and target point interchanged. Line_2 s.supporting_line () const returns the line l passing through s. Line l has the same orientation as segment s.

### Predicates

bool s.is_degenerate () const segment s is degenerate, if source and target are equal.

bool s.is_horizontal () const
bool s.is_vertical () const

bool s.has_on ( 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.

bool s.collinear_has_on ( 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.

### Miscellaneous

 Bbox_2 s.bbox () const returns a bounding box containing s. Segment_2 s.transform ( Aff_transformation_2 t) const returns the segment obtained by applying t on the source and the target of s.