23#ifndef VCL_SPACE_CORE_SEGMENT_H
24#define VCL_SPACE_CORE_SEGMENT_H
39template<Po
intConcept Po
intT>
60 static const uint
DIM = PointT::DIM;
81 PointT&
p0() {
return mPoint0; }
88 const PointT&
p0()
const {
return mPoint0; }
95 PointT&
p1() {
return mPoint1; }
102 const PointT&
p1()
const {
return mPoint1; }
104 PointT midPoint()
const {
return (mPoint0 + mPoint1) / 2.0; }
106 PointT direction()
const {
return mPoint1 - mPoint0; }
108 PointT normalizedDirection()
const
110 return (mPoint1 - mPoint0).normalize();
113 ScalarType length()
const { (mPoint0 - mPoint1).norm(); }
115 ScalarType squaredLength()
const { (mPoint0 - mPoint1).squaredNorm(); }
117 void flip() { std::swap(mPoint0, mPoint1); }
119 bool operator==(
const Segment<PointT>& s)
const =
default;
121 bool operator!=(
const Segment<PointT>& s)
const =
default;
123 Segment<PointT> operator+(
const Segment<PointT>& s)
const
125 return Segment<PointT>(mPoint0 + s.mPoint0, mPoint1 + s.mPoint1);
128 Segment<PointT> operator-(
const Segment<PointT>& s)
const
130 return Segment<PointT>(mPoint0 - s.mPoint0, mPoint1 - s.mPoint1);
133 Segment<PointT> operator*(
const ScalarType& s)
const
135 return Segment<PointT>(mPoint0 * s, mPoint1 * s);
138 Segment<PointT> operator/(
const ScalarType& s)
const
140 return Segment<PointT>(mPoint0 / s, mPoint1 / s);
143 Segment<PointT>& operator+=(
const Segment<PointT>& s)
const
145 mPoint0 += s.mPoint0;
146 mPoint1 += s.mPoint1;
150 Segment<PointT>& operator-=(
const Segment<PointT>& s)
const
152 mPoint0 -= s.mPoint0;
153 mPoint1 -= s.mPoint1;
157 Segment<PointT>& operator*=(
const ScalarType& s)
const
164 Segment<PointT>& operator/=(
const ScalarType& s)
const
175using Segment2 = Segment<Point2<S>>;
177using Segment2i = Segment<Point2i>;
178using Segment2f = Segment<Point2f>;
179using Segment2d = Segment<Point2d>;
182using Segment3 = Segment<Point3<S>>;
184using Segment3i = Segment<Point3i>;
185using Segment3f = Segment<Point3f>;
186using Segment3d = Segment<Point3d>;
202 std::remove_cvref_t<T>,
203 Segment<typename RemoveRef<T>::PointType>>;
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
PointT::ScalarType ScalarType
The scalar type of the endpoint points.
Definition segment.h:55
static const uint DIM
The dimensionality of the segment.
Definition segment.h:60
PointT & p0()
Returns the first endpoint of the segment.
Definition segment.h:81
PointT & p1()
Returns the second endpoint of the segment.
Definition segment.h:95
Segment()
Default constructor. Creates a segment with endpoints at the origin.
Definition segment.h:66
const PointT & p1() const
Returns the second endpoint of the segment.
Definition segment.h:102
Segment(const PointT &p0, const PointT &p1)
Creates a segment with the given endpoints.
Definition segment.h:74
const PointT & p0() const
Returns the first endpoint of the segment.
Definition segment.h:88
PointT PointType
The type of point used to represent the endpoint points of the segment.
Definition segment.h:50
A concept representing a 2D Segment.
Definition segment.h:216
A concept representing a 3D Segment.
Definition segment.h:229
A concept representing a Segment.
Definition segment.h:201