30 #if !defined(__cpp_lib_byteswap) || __cpp_lib_byteswap < 202110L
36 #if !defined(__cpp_lib_bit_cast)
37 template <
class To,
class From>
38 std::enable_if_t<
sizeof(To) ==
sizeof(From) && std::is_trivially_copyable_v<From> && std::is_trivially_copyable_v<To>, To>
bit_cast(
const From& src) noexcept {
39 static_assert(std::is_trivially_constructible_v<To>,
"This implementation additionally requires destination type to be trivially constructible");
41 ::memcpy(&dst, &src,
sizeof(To));
47 #ifdef __cpp_lib_ranges
48 static_assert(std::has_unique_object_representations_v<T>,
"T may not have padding bits");
49 auto value_representation =
std::bit_cast<std::array<std::byte,
sizeof(T)>>(value);
51 return std::bit_cast<T>(value_representation);
53 if(
sizeof(T) ==
sizeof(uint64_t)) {
55 return ((x << 56) & 0xff00000000000000ULL) |
56 ((x << 40) & 0x00ff000000000000ULL) |
57 ((x << 24) & 0x0000ff0000000000ULL) |
58 ((x << 8) & 0x000000ff00000000ULL) |
59 ((x >> 8) & 0x00000000ff000000ULL) |
60 ((x >> 24) & 0x0000000000ff0000ULL) |
61 ((x >> 40) & 0x000000000000ff00ULL) |
62 ((x >> 56) & 0x00000000000000ffULL);
63 }
else if(
sizeof(T) ==
sizeof(uint32_t)) {
66 ((x << 24) & 0xff000000UL) |
67 ((x << 8) & 0x00ff0000UL) |
68 ((x >> 8) & 0x0000ff00UL) |
69 ((x >> 24) & 0x000000ffUL);
73 ((x << 8) & 0xff00U) |
81 #ifndef __cpp_lib_endian
84 # if defined E3D_TARGET_WINDOWS
89 little = __ORDER_LITTLE_ENDIAN__,
90 big = __ORDER_BIG_ENDIAN__,
97 #if !defined(E3D_EXCEPTIONS)
98 # define CXX_THROW(class, ...) throw class(__VA_ARGS__);
101 # define CXX_THROW(class, ...) { fprintf(stderr, class(__VA_ARGS__).what()); abort(); }
104 template<
typename It>
111 It
end()
const {
return _e; }
114 template<typename ORange, typename OIt = decltype(std::begin(std::declval<ORange>())),
typename It = std::reverse_iterator<OIt>>
116 return Range<It>(It(std::end(originalRange)), It(std::begin(originalRange)));
119 #include <glm/common.hpp>
120 #include <glm/vec2.hpp>
121 #include <glm/vec3.hpp>
122 #include <glm/gtc/matrix_transform.hpp>
123 #include <glm/gtx/intersect.hpp>
127 template <
typename C,
typename T>
129 for(
auto i = c.size(); i-- > 0; ) {
139 template <
typename C,
typename T>
141 for(
auto i = c.size(); i-- > 0; ) {
150 const auto normalized_pos = pos / size;
151 glm::vec2 radiance_pos;
152 radiance_pos.x = normalized_pos.x * 2.f * glm::pi<float>();
153 radiance_pos.y = normalized_pos.y * glm::pi<float>();
155 glm::vec3 sphere_position;
156 sphere_position.x = glm::cos(radiance_pos.x) * glm::sin(radiance_pos.y);
157 sphere_position.y = glm::sin(radiance_pos.x) * glm::sin(radiance_pos.y);
158 sphere_position.z = glm::cos(radiance_pos.y);
159 sphere_position *= radius;
160 return sphere_position;
168 const auto cos_angle = dt / (radius * radius);
169 const auto angle = glm::acos(glm::clamp(cos_angle, -1.f, 1.f));
170 const auto distance = angle * radius;
void fast_erase(C &c, T value) noexcept
float euclidean_distance(glm::vec2 size, float radius, glm::vec2 p0, glm::vec2 p1)
Obtain the euclidean distance from p0 to p1.
glm::vec3 get_sphere_coord(glm::vec2 size, glm::vec2 pos, float radius)
void fast_erase_all(C &c, T value) noexcept
std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable_v< From > &&std::is_trivially_copyable_v< To >, To > bit_cast(const From &src) noexcept
constexpr T byteswap(T value) noexcept
Range< It > reverse(ORange &&originalRange)