SFCGAL  2.2.0
Public Member Functions | List of all members
SFCGAL::Segment Class Reference

Represents a line segment in space. More...

#include <Segment.h>

Public Member Functions

 Segment ()
 Default constructor creating an empty segment. More...
 
 Segment (const Point &p1, const Point &p2)
 Constructor with two points. More...
 
template<typename PointType , typename = std::enable_if_t<std::is_same_v<PointType, Kernel::Point_2> || std::is_same_v<PointType, Kernel::Point_3>>>
 Segment (const PointType &p1, const PointType &p2)
 Constructor with CGAL points (2D or 3D) More...
 
template<typename SegmentType , typename = std::enable_if_t< std::is_same_v<SegmentType, Kernel::Segment_2> || std::is_same_v<SegmentType, Kernel::Segment_3>>>
 Segment (const SegmentType &segment)
 Constructor with CGAL segment (2D or 3D) More...
 
 Segment (const Segment &other)=default
 Copy constructor. More...
 
auto operator= (const Segment &other) -> Segment &=default
 Assignment operator. More...
 
 ~Segment ()=default
 Destructor. More...
 
auto source () const -> const Point &
 Gets the first endpoint. More...
 
auto target () const -> const Point &
 Gets the second endpoint. More...
 
auto setSource (const Point &p) -> void
 Sets the first endpoint. More...
 
auto setTarget (const Point &p) -> void
 Sets the second endpoint. More...
 
auto setPoints (const Point &source, const Point &target) -> void
 Sets both endpoints at once. More...
 
template<typename PointType , typename = std::enable_if_t<std::is_same_v<PointType, Kernel::Point_2> || std::is_same_v<PointType, Kernel::Point_3>>>
auto setPoints (const PointType &source, const PointType &target) -> void
 Sets both CGAL endpoints at once. More...
 
auto clear () -> void
 Reset the segment to empty. More...
 
auto toSegment_2 () const -> Kernel::Segment_2
 Converts to a CGAL::Segment_2. More...
 
auto toSegment_3 () const -> Kernel::Segment_3
 Converts to a CGAL::Segment_3. More...
 
auto isEmpty () const -> bool
 Checks if the segment is empty (either endpoint is empty) More...
 
auto isDegenerate () const -> bool
 Checks if the segment is degenerate (zero length) More...
 
auto squaredLength () const -> Kernel::FT
 Returns the squared length of the segment. More...
 
auto length () const -> Kernel::FT
 Returns the length of the segment. More...
 
auto is3D () const -> bool
 Checks if the segment is in 3D space. More...
 
auto isMeasured () const -> bool
 Checks if the segment is measured. More...
 
template<typename PointType >
auto squaredDistanceToPoint (const PointType &p) const -> Kernel::FT
 Gets the squared distance from a point to the segment. More...
 
template<typename... Args>
auto distanceToPoint (Args &&...args) const -> double
 Distance from a point to the segment. More...
 
template<typename PointType >
auto exactInterpolationParameter (const PointType &p) const -> Kernel::FT
 Calculates the exact parameter for a projected point on the segment. More...
 
template<typename... Args>
auto interpolationParameter (Args &&...args) const -> double
 Calculates the parameter for a projected point on the segment. More...
 
auto interpolate (double t) const -> Point
 Gets a point on the segment at given parameter. More...
 
template<typename PointType >
auto hasOn (const PointType &p, double tolerance=EPSILON) const -> bool
 Checks if a point is on the segment (works in 2D or 3D) More...
 
auto midpoint () const -> Point
 Returns the midpoint of the segment. More...
 
auto reverse () -> void
 Reverses the segment direction. More...
 

Detailed Description

Represents a line segment in space.

This class provides methods for working with line segments and performing calculations like distance and interpolation. Unlike LineString which inherits from Geometry, this is a lightweight primitive.

Constructor & Destructor Documentation

SFCGAL::Segment::Segment ( )

Default constructor creating an empty segment.

SFCGAL::Segment::Segment ( const Point p1,
const Point p2 
)

Constructor with two points.

Parameters
p1The first endpoint of the segment
p2The second endpoint of the segment
Exceptions
Exceptionif points have inconsistent dimensions
template<typename PointType , typename = std::enable_if_t<std::is_same_v<PointType, Kernel::Point_2> || std::is_same_v<PointType, Kernel::Point_3>>>
SFCGAL::Segment::Segment ( const PointType &  p1,
const PointType &  p2 
)
inline

Constructor with CGAL points (2D or 3D)

Parameters
p1The first endpoint of the segment
p2The second endpoint of the segment
Note
For CGAL points, dimensional consistency is guaranteed by the type system
template<typename SegmentType , typename = std::enable_if_t< std::is_same_v<SegmentType, Kernel::Segment_2> || std::is_same_v<SegmentType, Kernel::Segment_3>>>
SFCGAL::Segment::Segment ( const SegmentType &  segment)
inlineexplicit

Constructor with CGAL segment (2D or 3D)

Parameters
segmentA CGAL segment
Note
For CGAL segments, dimensional consistency is guaranteed by the type system
SFCGAL::Segment::Segment ( const Segment other)
default

Copy constructor.

SFCGAL::Segment::~Segment ( )
default

Destructor.

Member Function Documentation

auto SFCGAL::Segment::clear ( ) -> void

Reset the segment to empty.

template<typename... Args>
auto SFCGAL::Segment::distanceToPoint ( Args &&...  args) const -> double

Distance from a point to the segment.

Parameters
pThe point (can be SFCGAL::Point, coordinate pair, or CGAL points)
Returns
The shortest distance from the point to the segment
Exceptions
Exceptionif the segment is empty
template<typename PointType >
auto SFCGAL::Segment::exactInterpolationParameter ( const PointType &  p) const -> Kernel::FT

Calculates the exact parameter for a projected point on the segment.

Parameters
pThe point to project (SFCGAL::Point, CGAL::Point_2, or CGAL::Point_3)
Returns
Parameter value between 0.0 and 1.0 (clamped)
Exceptions
Exceptionif the segment is empty
template<typename PointType >
auto SFCGAL::Segment::hasOn ( const PointType &  p,
double  tolerance = EPSILON 
) const -> bool

Checks if a point is on the segment (works in 2D or 3D)

Parameters
pThe point to check
toleranceOptional tolerance value
Returns
True if the point lies on the segment
Exceptions
Exceptionif the segment is empty
auto SFCGAL::Segment::interpolate ( double  t) const -> Point

Gets a point on the segment at given parameter.

Parameters
tParameter value between 0.0 (source) and 1.0 (target)
Returns
The interpolated point with M value if points are measured
Exceptions
Exceptionif the segment is empty
template<typename... Args>
auto SFCGAL::Segment::interpolationParameter ( Args &&...  args) const -> double

Calculates the parameter for a projected point on the segment.

Parameters
argsPoint coordinates or point object
Returns
Parameter value between 0.0 (source) and 1.0 (target)
Exceptions
Exceptionif the segment is empty
auto SFCGAL::Segment::is3D ( ) const -> bool

Checks if the segment is in 3D space.

Returns
True if either endpoint has Z coordinate
auto SFCGAL::Segment::isDegenerate ( ) const -> bool

Checks if the segment is degenerate (zero length)

Returns
True if the segment has zero length
auto SFCGAL::Segment::isEmpty ( ) const -> bool

Checks if the segment is empty (either endpoint is empty)

Returns
True if the segment is empty
auto SFCGAL::Segment::isMeasured ( ) const -> bool

Checks if the segment is measured.

Returns
True if either endpoint has M coordinate
auto SFCGAL::Segment::length ( ) const -> Kernel::FT

Returns the length of the segment.

Returns
The length
auto SFCGAL::Segment::midpoint ( ) const -> Point

Returns the midpoint of the segment.

Returns
A point at the middle of the segment
Exceptions
Emptypoint if the segment is empty
auto SFCGAL::Segment::operator= ( const Segment other) -> Segment &=default
default

Assignment operator.

auto SFCGAL::Segment::reverse ( ) -> void

Reverses the segment direction.

Exceptions
Exceptionif the segment is empty
auto SFCGAL::Segment::setPoints ( const Point source,
const Point target 
) -> void

Sets both endpoints at once.

Parameters
sourceThe new first endpoint
targetThe new second endpoint
Exceptions
Exceptionif points have inconsistent dimensions
Note
This is the only way to set points on an empty segment
template<typename PointType , typename = std::enable_if_t<std::is_same_v<PointType, Kernel::Point_2> || std::is_same_v<PointType, Kernel::Point_3>>>
auto SFCGAL::Segment::setPoints ( const PointType &  source,
const PointType &  target 
) -> void
inline

Sets both CGAL endpoints at once.

Parameters
sourceThe new first endpoint
targetThe new second endpoint
Note
Type safety ensures dimensional consistency
auto SFCGAL::Segment::setSource ( const Point p) -> void

Sets the first endpoint.

Parameters
pThe new first endpoint
Exceptions
Exceptionif the segment is empty
Exceptionif the new point has inconsistent dimensions with target
auto SFCGAL::Segment::setTarget ( const Point p) -> void

Sets the second endpoint.

Parameters
pThe new second endpoint
Exceptions
Exceptionif the segment is empty
Exceptionif the new point has inconsistent dimensions with source
auto SFCGAL::Segment::source ( ) const -> const Point &
inline

Gets the first endpoint.

Returns
The first endpoint
template<typename PointType >
auto SFCGAL::Segment::squaredDistanceToPoint ( const PointType &  p) const -> Kernel::FT

Gets the squared distance from a point to the segment.

Parameters
pThe point (SFCGAL::Point, CGAL::Point_2, or CGAL::Point_3)
Returns
The squared distance (exact calculation)
Exceptions
Exceptionif the segment is empty
auto SFCGAL::Segment::squaredLength ( ) const -> Kernel::FT

Returns the squared length of the segment.

Returns
The squared length
auto SFCGAL::Segment::target ( ) const -> const Point &
inline

Gets the second endpoint.

Returns
The second endpoint
auto SFCGAL::Segment::toSegment_2 ( ) const -> Kernel::Segment_2

Converts to a CGAL::Segment_2.

Returns
A CGAL::Segment_2 representation of this segment
auto SFCGAL::Segment::toSegment_3 ( ) const -> Kernel::Segment_3

Converts to a CGAL::Segment_3.

Returns
A CGAL::Segment_3 representation of this segment