Move Vectormath main
C++20 game and graphics mathematics
Loading...
Searching...
No Matches
Line3.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <type_traits>
5
8
9namespace mv::math
10{
11 // Standard infinite line with a unit direction; the signed-distance
12 // parameter convention matches Geometric Tools Line.h (BSL-1.0).
13 template <typename T>
14 requires std::is_floating_point_v<T>
15 class Line3
16 {
17 public:
18 using Component = T;
19
21
23 :
24 Origin_(origin), Direction_(direction)
25 {
26 }
27
29 {
30 return Origin_;
31 }
32
34 {
35 return Direction_;
36 }
37
39 {
40 return Origin_ + Direction_.Vector() * signedDistance;
41 }
42
44 {
45 return std::isfinite(Origin_.X()) && std::isfinite(Origin_.Y()) &&
46 std::isfinite(Origin_.Z());
47 }
48
49 [[nodiscard]] friend bool operator==(const Line3& left,
50 const Line3& right) noexcept
51 {
52 return left.Origin_ == right.Origin_ &&
53 left.Direction_ == right.Direction_;
54 }
55
56 private:
57 Point3<T> Origin_;
58 Direction3<T> Direction_;
59 };
60
63} // namespace mv::math
64
65static_assert(sizeof(mv::math::Line3f) == 32);
66static_assert(alignof(mv::math::Line3f) == 16);
67static_assert(std::is_trivially_copyable_v<mv::math::Line3f>);
68static_assert(std::is_standard_layout_v<mv::math::Line3f>);
69static_assert(sizeof(mv::math::Line3d) == 64);
70static_assert(alignof(mv::math::Line3d) == 32);
71static_assert(std::is_trivially_copyable_v<mv::math::Line3d>);
72static_assert(std::is_standard_layout_v<mv::math::Line3d>);
bool IsFinite() const noexcept
Definition Line3.hpp:43
const Direction3< T > & Direction() const noexcept
Definition Line3.hpp:33
friend bool operator==(const Line3 &left, const Line3 &right) noexcept
Definition Line3.hpp:49
Point3< T > PointAt(T signedDistance) const noexcept
Definition Line3.hpp:38
Line3() noexcept=default
const Point3< T > & Origin() const noexcept
Definition Line3.hpp:28
Line3< double > Line3d
Definition Line3.hpp:62
Line3< float > Line3f
Definition Line3.hpp:61