template <typename Scalar>
muu::line_segment struct

A line segment.

Template parameters
Scalar The line segment's scalar component type. Must be a floating-point type.

Public types

using const_iterator = const vector_type*
A const LegacyRandomAccessIterator for the points in the line segment.
using constants = muu::constants<line_segment>
Compile-time line segment constants.
using iterator = vector_type*
A LegacyRandomAccessIterator for the points in the line segment.
using scalar_type = Scalar
The line segment's scalar type.
using vector_type = vector<scalar_type, 3>
The three-dimensional muu::vector with the same scalar_type as the line segment.

Constructors, destructors, conversion operators

line_segment() defaulted noexcept
Default constructor. Values are not initialized.
line_segment(const line_segment&) defaulted constexpr noexcept
Copy constructor.
line_segment(const vector_type& p0, const vector_type& p1) constexpr noexcept
Constructs a line segment from two points.
line_segment(const vector_type(&points)[2]) explicit constexpr noexcept
Constructs a line segment from two points.
line_segment(scalar_type p0_x, scalar_type p0_y, scalar_type p0_z, scalar_type p1_x, scalar_type p1_y, scalar_type p1_z) constexpr noexcept
Constructs a line segment from two points (in scalar form).
template <typename S>
line_segment(const line_segment<S>& seg) explicit constexpr noexcept
Converting constructor.
template <typename T>
line_segment(const T& obj) constexpr noexcept
Constructs a line segment from an implicitly bit-castable type.

Public functions

auto operator=(const line_segment&) -> line_segment& defaulted constexpr noexcept
Copy-assigment operator.

Public variables

vector_type points
the points in the line segment.

Collision detection

static auto colinear(const line_segment& seg, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a line segment and a point are colinear (i.e. they lie on the same infinite line).
static auto colinear(const line_segment& seg1, const line_segment& seg2, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a two line segments are colinear (i.e. they lie on the same infinite line).
static auto contains(const vector_type& start, const vector_type& end, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a point lies on a line segment.
static auto contains(const line_segment& seg, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a point lies on a line segment.
static auto contains(const line_segment& outer, const line_segment& inner, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a line segment contains another line segment.
static auto coplanar(const line_segment& seg1, const line_segment& seg2, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if two line segments are coplanar.
static auto intersects(const line_segment& seg, const plane<scalar_type>& p) -> bool constexpr noexcept
Returns true if a line segment intersects a plane.
static auto intersects(const line_segment& seg, const bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a line segment intersects a bounding box.
auto colinear(const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if a line segment and a point are colinear (i.e. they lie on the same infinite line).
auto colinear(const line_segment& seg, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if a two line segments are colinear (i.e. they lie on the same infinite line).
auto contains(const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if a point lies on a line segment.
auto contains(const vector_type* begin, const vector_type* end, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the points in an arbitrary collection lie on the line segment.
auto contains(const line_segment& seg, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if the line segment contains another line segment.
auto coplanar(const line_segment& seg, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if two line segments are coplanar.
auto intersects(const plane<scalar_type>& p) const -> bool constexpr noexcept
Returns true if a line segment intersects a plane.
auto intersects(const bounding_box<scalar_type>& bb) const -> bool constexpr noexcept
Returns true if a line segment intersects a bounding box.

Equality (approximate)

template <typename T>
static auto approx_equal(const line_segment& seg1, const line_segment<T>& seg2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two line segments are approximately equal.
static auto approx_zero(const line_segment& seg, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the scalar components in a line segment are approximately equal to zero.
template <typename T>
auto approx_equal(const line_segment<T>& seg, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the line segment is approximately equal to another.
auto approx_zero(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if all the scalar components in the line segment are approximately equal to zero.

Equality (exact)

static auto degenerate(const line_segment& seg) -> bool constexpr noexcept
Returns true if a line segment is degenerate (i.e. its points are coincident).
static auto infinity_or_nan(const line_segment& seg) -> bool constexpr noexcept
Returns true if any of the points of a line segment are infinity or NaN.
static auto zero(const line_segment& seg) -> bool constexpr noexcept
Returns true if all the points of a line segment are exactly zero.
auto degenerate() const -> bool constexpr noexcept
Returns true if a line segment is degenerate (i.e. its points are coincident).
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the points in the line segment are infinity or NaN.
auto zero() const -> bool constexpr noexcept
Returns true if all the points of the line segment are exactly zero.
template <typename T>
auto operator!=(const line_segment& lhs, const line_segment<T>& rhs) -> bool constexpr noexcept
Returns true if two line segments are not exactly equal.
template <typename T>
auto operator==(const line_segment& lhs, const line_segment<T>& rhs) -> bool constexpr noexcept
Returns true if two line segments are exactly equal.

Extension

static auto extend(const line_segment& seg, scalar_type extend_by) -> line_segment constexpr noexcept
Extends the end point of a line segment by some amount.
auto extend(scalar_type extend_by) -> line_segment& constexpr noexcept
Extends the end point of a line segment by some amount (in-place).

Geometric properties

static auto direction(const line_segment& seg, scalar_type& length_out) -> vector_type constexpr noexcept
Returns the direction of a line segment (from point 0 to point 1).
static auto direction(const line_segment& seg) -> vector_type constexpr noexcept
Returns the direction of a line segment (from point 0 to point 1).
static auto length(const line_segment& seg) -> scalar_type constexpr noexcept
Returns the length of a line segment.
static auto length_squared(const line_segment& seg) -> scalar_type constexpr noexcept
Returns the squared length of a line segment.
static auto midpoint(const line_segment& seg) -> vector_type constexpr noexcept
Returns a line segment's midpoint.
auto direction(scalar_type& length_out) const -> vector_type constexpr noexcept
Returns the direction of the line segment (from point 0 to point 1).
auto direction() const -> vector_type constexpr noexcept
Returns the direction of the line segment (from point 0 to point 1).
auto length() const -> scalar_type constexpr noexcept
Returns the length of a line segment.
auto length_squared() const -> scalar_type constexpr noexcept
Returns the squared length of a line segment.
auto midpoint() const -> vector_type constexpr noexcept
Returns the line segment's midpoint.

Iterators

auto begin() -> iterator constexpr noexcept
Returns an iterator to the first point in the line segment.
auto begin() const -> const_iterator constexpr noexcept
Returns a const iterator to the first point in the line segment.
auto cbegin() const -> const_iterator constexpr noexcept
Returns a const iterator to the first point in the line segment.
auto cend() const -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in the line segment.
auto end() -> iterator constexpr noexcept
Returns an iterator to the one-past-the-last point in the line segment.
auto end() const -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in the line segment.

Iterators (ADL)

auto begin(line_segment& v) -> iterator constexpr noexcept
Returns an iterator to the first point in a line segment.
auto begin(const line_segment& v) -> const_iterator constexpr noexcept
Returns a const iterator to the first point in a line segment.
auto cbegin(const line_segment& v) -> const_iterator constexpr noexcept
Returns a const iterator to the first point in a line segment.
auto cend(const line_segment& v) -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in a line segment.
auto end(line_segment& v) -> iterator constexpr noexcept
Returns an iterator to the one-past-the-last point in a line segment.
auto end(const line_segment& v) -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in a line segment.

Point accessors

template <size_t P>
auto get() -> vector_type& constexpr noexcept
Returns a reference to one of the line segment's points.
template <size_t P>
auto get() const -> constvector_type& constexpr noexcept
Returns a reference to one of the line segment's points.
auto operator[](size_t p) -> vector_type& constexpr noexcept
Returns a reference to one of the line segment's points.
auto operator[](size_t p) const -> constvector_type& constexpr noexcept
Returns a reference to one of the line segment's points.

Point queries

static auto closest_point(const line_segment& seg, const vector_type& point) -> vector_type constexpr noexcept
Gets the point on a line segment closest to another arbitrary point.
auto closest_point(const vector_type& point) const -> vector_type constexpr noexcept
Gets the point on the line segment closest to another arbitrary point.

Reversal

static auto reverse(const line_segment& seg) -> line_segment constexpr noexcept
Reverses the start and end points of a line segment.
auto reverse() -> line_segment& constexpr noexcept
Reverses the start and end points of a line segment (in-place).

Scalar accessors

auto data() -> scalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the line segment.
auto data() const -> constscalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the line segment.

Friends

template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, const line_segment& seg) -> std::basic_ostream<Char, Traits>&
Writes a line segment out to a text stream.

Function documentation

template <typename Scalar>
template <typename T>
muu::line_segment::line_segment(const T& obj) constexpr noexcept

Constructs a line segment from an implicitly bit-castable type.

Template parameters
T A bit-castable type.

template <typename Scalar>
static bool muu::line_segment::zero(const line_segment& seg) constexpr noexcept

Returns true if all the points of a line segment are exactly zero.

template <typename Scalar>
bool muu::line_segment::zero() const constexpr noexcept

Returns true if all the points of the line segment are exactly zero.

template <typename Scalar>
template <typename T>
bool muu::line_segment::operator!=(const line_segment& lhs, const line_segment<T>& rhs) constexpr noexcept

Returns true if two line segments are not exactly equal.

template <typename Scalar>
template <typename T>
bool muu::line_segment::operator==(const line_segment& lhs, const line_segment<T>& rhs) constexpr noexcept

Returns true if two line segments are exactly equal.