Visual Computing Library  devel
Loading...
Searching...
No Matches
line.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_SPACE_CORE_LINE_H
24#define VCL_SPACE_CORE_LINE_H
25
26#include "point.h"
27
28namespace vcl {
29
39template<PointConcept PointT>
40class Line
41{
42 PointT mOrigin;
43 PointT mDirection;
44
45public:
50 using PointType = PointT;
51
55 using ScalarType = PointT::ScalarType;
56
60 static const uint DIM = PointT::DIM;
61
66 Line() {}
67
74 Line(const PointT& origin, const PointT& direction) :
75 mOrigin(origin), mDirection(direction)
76 {
77 }
78
84 PointT& origin() { return mOrigin; }
85
91 const PointT& origin() const { return mOrigin; }
92
98 PointT& direction() { return mDirection; }
99
105 const PointT& direction() const { return mDirection; }
106
112 PointT normalizedDirection() const { return mDirection.normalized(); }
113
121 {
122 return mOrigin + mDirection * t;
123 }
124
125 bool operator==(const Line<PointT>& s) const = default;
126
127 bool operator!=(const Line<PointT>& s) const = default;
128};
129
130/* Specialization Aliases */
131
132template<typename S>
133using Line2 = Line<Point2<S>>;
134
135using Line2i = Line<Point2i>;
136using Line2f = Line<Point2f>;
137using Line2d = Line<Point2d>;
138
139template<typename S>
140using Line3 = Line<Point3<S>>;
141
142using Line3i = Line<Point3i>;
143using Line3f = Line<Point3f>;
144using Line3d = Line<Point3d>;
145
146/* Concepts */
147
158template<typename T>
159concept LineConcept = std::derived_from< // same type or derived type
160 std::remove_cvref_t<T>,
161 Line<typename RemoveRef<T>::PointType>>;
162
173template<typename T>
174concept Line2Concept = LineConcept<T> && RemoveRef<T>::DIM == 2;
175
186template<typename T>
187concept Line3Concept = LineConcept<T> && RemoveRef<T>::DIM == 3;
188
189} // namespace vcl
190
191#endif // VCL_SPACE_CORE_LINE_H
A class representing a line in n-dimensional space. The class is parameterized by a PointConcept,...
Definition line.h:41
static const uint DIM
The dimensionality of the line.
Definition line.h:60
PointT::ScalarType ScalarType
The scalar type of the line.
Definition line.h:55
PointT normalizedDirection() const
Returns the normalized direction of the line.
Definition line.h:112
const PointT & origin() const
Returns the origin of the line.
Definition line.h:91
PointT PointType
The type of point used to represent the origin and direction of the line.
Definition line.h:50
PointT pointAtParameter(ScalarType t) const
Returns the point at parameter t along the line.
Definition line.h:120
PointT & origin()
Returns the origin of the line.
Definition line.h:84
Line(const PointT &origin, const PointT &direction)
Creates a line with the given origin and direction.
Definition line.h:74
const PointT & direction() const
Returns the direction of the line.
Definition line.h:105
PointT & direction()
Returns the direction of the line.
Definition line.h:98
Line()
Default constructor. Creates an invalid Line at the origin (direction is zero).
Definition line.h:66
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
A concept representing a 2D Line.
Definition line.h:174
A concept representing a 3D Line.
Definition line.h:187
A concept representing a Line.
Definition line.h:159