EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Vec.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
12#ifndef EBGEOMETRY_VEC_HPP
13#define EBGEOMETRY_VEC_HPP
14
15// Std includes
16#include <algorithm>
17#include <array>
18#include <cstddef>
19#include <limits>
20#include <ostream>
21#include <type_traits>
22
23// Our includes
24#include "EBGeometry_Macros.hpp"
25
26namespace EBGeometry {
27
35template <typename T>
36class Vec2T
37{
38public:
39 static_assert(std::is_floating_point_v<T>, "Vec2T<T>: T must be a floating-point type");
43 constexpr Vec2T() noexcept;
44
51
59
64
68 T x;
69
73 T y;
74
81
88
95
102
109
115 constexpr Vec2T<T>&
117
125
133
140
148
156
164
172
180
188
196
204
212};
213
225{
226public:
227 static_assert(std::is_floating_point_v<T>, "Vec3T<T>: T must be a floating-point type");
228
235 friend std::ostream&
236 operator<<(std::ostream& os, const Vec3T<T>& vec)
237 {
238 os << '(' << vec[0] << ',' << vec[1] << ',' << vec[2] << ')';
239
240 return os;
241 }
242
246 constexpr Vec3T() noexcept;
247
254
263
268
275
282
289 unit(const size_t a_dir) noexcept;
290
297
304
311
320 [[nodiscard]] inline constexpr bool
322
329 operator[](size_t i) noexcept;
330
338
344 [[nodiscard]] inline constexpr bool
346
352 [[nodiscard]] inline constexpr bool
354
365
373 [[nodiscard]] inline constexpr bool
375
386
395 [[nodiscard]] inline constexpr bool
397
403 constexpr Vec3T<T>&
405
413
421
428
435
444
453
461
469
478
487
496
505
513
521
527 [[nodiscard]] inline size_t
529
537 [[nodiscard]] inline size_t
539
546
553
558 std::array<T, 3> m_X;
559};
560
571
583
594
605
614[[nodiscard]] inline T
616
624[[nodiscard]] inline T
626
638
649
662
673
684
696
707
718
728
729} // namespace EBGeometry
730
731#include "EBGeometry_VecImplem.hpp"
732
733#endif
Utility macros for EBGeometry.
Two-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:37
constexpr T dot(const Vec2T &a_other) const noexcept
Dot product.
T y
Second component in the vector.
Definition EBGeometry_Vec.hpp:73
static constexpr Vec2T< T > infinity() noexcept
Return a vector with infinite components.
T x
First component in the vector.
Definition EBGeometry_Vec.hpp:68
static constexpr Vec2T< T > zeros() noexcept
Return av vector with x = y = 0.
constexpr T length2() const noexcept
Compute square of vector.
static constexpr Vec2T< T > min() noexcept
Return the most-negative representable vector.
constexpr T length() const noexcept
Compute length of vector.
static constexpr Vec2T< T > max() noexcept
Return the most-positive representable vector.
constexpr Vec2T() noexcept
Default constructor. Sets the vector to the zero vector.
static constexpr Vec2T< T > ones() noexcept
Return a vector with x = y = 1.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:225
constexpr Vec3T() noexcept
Default constructor. Sets the vector to the zero vector.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_AnalyticDistanceFunctions.hpp:31
constexpr Vec3T< T > clamp(const Vec3T< T > &v, const Vec3T< T > &lo, const Vec3T< T > &hi) noexcept
Component-wise clamp of a 3D vector.
constexpr Vec3T< T > cross(const Vec3T< T > &u, const Vec3T< T > &v) noexcept
Cross product of two 3D vectors.