#include <muu/line_segment.h>
template <typename Scalar>
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
template <typename T>
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
template <typename T>
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
template <typename T>
Returns true if two line segments are exactly equal.