Orrery
A GPU-accelerated N-body gravitational simulator
Toggle main menu visibility
Loading...
Searching...
No Matches
vec3_span.hpp
Go to the documentation of this file.
1
#pragma once
2
18
19
#include <span>
20
#include <type_traits>
21
22
#include "
orrery/core/types.hpp
"
23
#include "
orrery/core/vec3.hpp
"
24
25
namespace
orrery::core {
26
33
template
<
typename
T>
struct
Vec3Span
{
34
static_assert
(std::is_same_v<std::remove_const_t<T>, Real>,
35
"A Vec3Span views component arrays, which hold Real"
);
36
37
std::span<T> x;
38
std::span<T> y;
39
std::span<T> z;
40
46
[[nodiscard]]
constexpr
Index
size
() const noexcept {
return
x.size(); }
47
48
[[nodiscard]]
constexpr
bool
empty() const noexcept {
return
x.empty(); }
49
51
[[nodiscard]]
constexpr
Vec3
get
(
Index
index)
const
noexcept
{
52
return
{x[index], y[index], z[index]};
53
}
54
59
constexpr
void
set
(
Index
index,
Vec3
value)
const
noexcept
60
requires
(!std::is_const_v<T>)
61
{
62
x[index] = value.x;
63
y[index] = value.y;
64
z[index] = value.z;
65
}
66
69
constexpr
operator
Vec3Span<const T>
() const noexcept
70
requires(!std::is_const_v<T>)
71
{
72
return
{x, y, z};
73
}
74
};
75
76
}
// namespace orrery::core
orrery::core::Vec3Span
A view of three component arrays of equal length.
Definition
vec3_span.hpp:33
orrery::core::Vec3Span::get
constexpr Vec3 get(Index index) const noexcept
Gather one vector from the three arrays.
Definition
vec3_span.hpp:51
orrery::core::Vec3Span::set
constexpr void set(Index index, Vec3 value) const noexcept
Scatter one vector across the three arrays.
Definition
vec3_span.hpp:59
orrery::core::Vec3Span::size
constexpr Index size() const noexcept
The number of vectors in the view.
Definition
vec3_span.hpp:46
orrery::core::Vec3
A vector in three-dimensional Euclidean space.
Definition
vec3.hpp:26
types.hpp
The scalar and index types that every layer of the project agrees on.
orrery::core::Index
std::size_t Index
The type of a particle index and of any count of particles.
Definition
types.hpp:45
vec3.hpp
A three-component vector for interfaces, not for storage.
orrery
core
vec3_span.hpp
Generated by
1.17.0