Skip to content

Class SFCGAL::Segment#

ClassList > SFCGAL > Segment

Represents a line segment in space. More...

  • #include <Segment.h>

Public Functions#

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

Detailed Description#

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.

Public Functions Documentation#

function Segment [1/5]#

Default constructor creating an empty segment.

SFCGAL::Segment::Segment () 

function Segment [2/5]#

Constructor with two points.

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

Parameters:

  • p1 The first endpoint of the segment
  • p2 The second endpoint of the segment

Exception:

  • Exception if points have inconsistent dimensions

function Segment [3/5]#

Constructor with CGAL points (2D or 3D)

template<typename PointType, typename>
inline SFCGAL::Segment::Segment (
    const PointType & p1,
    const PointType & p2
) 

Parameters:

  • p1 The first endpoint of the segment
  • p2 The second endpoint of the segment

Note:

For CGAL points, dimensional consistency is guaranteed by the type system


function Segment [4/5]#

Constructor with CGAL segment (2D or 3D)

template<typename SegmentType, typename>
inline explicit SFCGAL::Segment::Segment (
    const SegmentType & segment
) 

Parameters:

  • segment A CGAL segment

Note:

For CGAL segments, dimensional consistency is guaranteed by the type system


function Segment [5/5]#

Copy constructor.

SFCGAL::Segment::Segment (
    const Segment & other
) = default

function clear#

Reset the segment to empty.

auto SFCGAL::Segment::clear () 

function distanceToPoint#

Distance from a point to the segment.

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

Parameters:

  • p The point (can be SFCGAL::Point, coordinate pair, or CGAL points)

Returns:

The shortest distance from the point to the segment

Exception:


function exactInterpolationParameter#

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

template<typename PointType>
auto SFCGAL::Segment::exactInterpolationParameter (
    const PointType & p
) const

Parameters:

  • p The point to project (SFCGAL::Point, CGAL::Point_2, or CGAL::Point_3)

Returns:

Parameter value between 0.0 and 1.0 (clamped)

Exception:


function hasOn#

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

template<typename PointType>
auto SFCGAL::Segment::hasOn (
    const PointType & p,
    double tolerance=EPSILON
) const

Parameters:

  • p The point to check
  • tolerance Optional tolerance value

Returns:

True if the point lies on the segment

Exception:


function interpolate#

Gets a point on the segment at given parameter.

auto SFCGAL::Segment::interpolate (
    double t
) const

Parameters:

  • t Parameter value between 0.0 (source) and 1.0 (target)

Returns:

The interpolated point with M value if points are measured

Exception:


function interpolationParameter#

Calculates the parameter for a projected point on the segment.

template<typename... Args>
auto SFCGAL::Segment::interpolationParameter (
    Args &&... args
) const

Parameters:

  • args Point coordinates or point object

Returns:

Parameter value between 0.0 (source) and 1.0 (target)

Exception:


function is3D#

Checks if the segment is in 3D space.

auto SFCGAL::Segment::is3D () const

Returns:

True if either endpoint has Z coordinate


function isDegenerate#

Checks if the segment is degenerate (zero length)

auto SFCGAL::Segment::isDegenerate () const

Returns:

True if the segment has zero length


function isEmpty#

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

auto SFCGAL::Segment::isEmpty () const

Returns:

True if the segment is empty


function isMeasured#

Checks if the segment is measured.

auto SFCGAL::Segment::isMeasured () const

Returns:

True if either endpoint has M coordinate


function length#

Returns the length of the segment.

auto SFCGAL::Segment::length () const

Returns:

The length


function midpoint#

Returns the midpoint of the segment.

auto SFCGAL::Segment::midpoint () const

Returns:

A point at the middle of the segment

Exception:

  • Empty point if the segment is empty

function operator=#

Assignment operator.

auto SFCGAL::Segment::operator= (
    const Segment & other
) 

function reverse#

Reverses the segment direction.

auto SFCGAL::Segment::reverse () 

Exception:


function setPoints [1/2]#

Sets both endpoints at once.

auto SFCGAL::Segment::setPoints (
    const Point & source,
    const Point & target
) 

Parameters:

  • source The new first endpoint
  • target The new second endpoint

Exception:

  • Exception if points have inconsistent dimensions

Note:

This is the only way to set points on an empty segment


function setPoints [2/2]#

Sets both CGAL endpoints at once.

template<typename PointType, typename>
inline auto SFCGAL::Segment::setPoints (
    const PointType & source,
    const PointType & target
) 

Parameters:

  • source The new first endpoint
  • target The new second endpoint

Note:

Type safety ensures dimensional consistency


function setSource#

Sets the first endpoint.

auto SFCGAL::Segment::setSource (
    const Point & p
) 

Parameters:

  • p The new first endpoint

Exception:

  • Exception if the segment is empty
  • Exception if the new point has inconsistent dimensions with target

function setTarget#

Sets the second endpoint.

auto SFCGAL::Segment::setTarget (
    const Point & p
) 

Parameters:

  • p The new second endpoint

Exception:

  • Exception if the segment is empty
  • Exception if the new point has inconsistent dimensions with source

function source#

Gets the first endpoint.

inline auto SFCGAL::Segment::source () const

Returns:

The first endpoint


function squaredDistanceToPoint#

Gets the squared distance from a point to the segment.

template<typename PointType>
auto SFCGAL::Segment::squaredDistanceToPoint (
    const PointType & p
) const

Parameters:

Returns:

The squared distance (exact calculation)

Exception:


function squaredLength#

Returns the squared length of the segment.

auto SFCGAL::Segment::squaredLength () const

Returns:

The squared length


function target#

Gets the second endpoint.

inline auto SFCGAL::Segment::target () const

Returns:

The second endpoint


function toSegment_2#

Converts to a CGAL::Segment_2.

auto SFCGAL::Segment::toSegment_2 () const

Returns:

A CGAL::Segment_2 representation of this segment


function toSegment_3#

Converts to a CGAL::Segment_3.

auto SFCGAL::Segment::toSegment_3 () const

Returns:

A CGAL::Segment_3 representation of this segment


function ~Segment#

Destructor.

SFCGAL::Segment::~Segment () = default


The documentation for this class was generated from the following file /builds/sfcgal/SFCGAL/src/Segment.h