diff --git a/.vscode/settings.json b/.vscode/settings.json index 2d90911..8e4ddd9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,7 @@ "-I${workspaceRoot}/include" ], "clang.cxxflags": [ - "-std=c++20", + "-std=c++2a", "-Wall", "-pedantic", "-I${workspaceRoot}/include" diff --git a/Makefile b/Makefile index 6566eaf..83205b0 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,8 @@ all: tests tests: bin/tests LLVM_PROFILE_FILE="./bin/tests.profraw" ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./bin/tests @llvm-profdata merge -sparse ./bin/tests.profraw -o ./bin/tests.profdata - @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/enveloppe/*.hpp include/gp/vfs/*.hpp include/gp/allocator/*.hpp - @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithm/*.hpp include/gp/enveloppe/*.hpp include/gp/vfs/*.hpp include/gp/allocator/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' + @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithms/*.hpp include/gp/enveloppe/*.hpp include/gp/system/*.hpp include/gp/ipc/*.hpp include/gp/utils/allocators/*.hpp + @llvm-cov report ./bin/tests -instr-profile=./bin/tests.profdata include/*.hpp include/gp/*.hpp include/gp/algorithms/*.hpp include/gp/enveloppe/*.hpp include/gp/system/*.hpp include/gp/ipc/*.hpp include/gp/utils/allocators/*.hpp | tail -n 1 | tr -s " " | sed -e 's/ /,/g' -- | awk -F "," '{print $$9}' | sed -e 's/^/Untested lines: /g' bin/tests: tests.cpp $(wildcard tests/*.cpp) $(wildcard include/*.hpp) ./tests/test_scaffold.h @mkdir -p $(@D) diff --git a/blacklist.txt b/blacklist.txt index 6a86a7a..1581d42 100644 --- a/blacklist.txt +++ b/blacklist.txt @@ -1,3 +1,3 @@ -src:gp/vfs/scheduler.hpp -src:gp/vfs/platforms/gcc-x86_64.hpp +src:gp/system/scheduler.hpp +src:gp/system/platforms/gcc-x86_64.hpp fun:gp::specifics::platform_data::push(void*) \ No newline at end of file diff --git a/include/gp/algorithm/cvref.hpp b/include/gp/algorithms/cvref.hpp similarity index 100% rename from include/gp/algorithm/cvref.hpp rename to include/gp/algorithms/cvref.hpp diff --git a/include/gp/algorithm/foreach.hpp b/include/gp/algorithms/foreach.hpp similarity index 100% rename from include/gp/algorithm/foreach.hpp rename to include/gp/algorithms/foreach.hpp diff --git a/include/gp/algorithm/min_max.hpp b/include/gp/algorithms/min_max.hpp similarity index 100% rename from include/gp/algorithm/min_max.hpp rename to include/gp/algorithms/min_max.hpp diff --git a/include/gp/algorithm/min_of.hpp b/include/gp/algorithms/min_of.hpp similarity index 93% rename from include/gp/algorithm/min_of.hpp rename to include/gp/algorithms/min_of.hpp index 8832163..7df7229 100644 --- a/include/gp/algorithm/min_of.hpp +++ b/include/gp/algorithms/min_of.hpp @@ -2,7 +2,7 @@ #include "gp_config.hpp" -#include "gp/algorithm/move.hpp" +#include "gp/algorithms/move.hpp" namespace gp{ diff --git a/include/gp/algorithm/modifiers.hpp b/include/gp/algorithms/modifiers.hpp similarity index 68% rename from include/gp/algorithm/modifiers.hpp rename to include/gp/algorithms/modifiers.hpp index c2d5f10..11b05bd 100644 --- a/include/gp/algorithm/modifiers.hpp +++ b/include/gp/algorithms/modifiers.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include diff --git a/include/gp/algorithm/move.hpp b/include/gp/algorithms/move.hpp similarity index 95% rename from include/gp/algorithm/move.hpp rename to include/gp/algorithms/move.hpp index 8220ffd..789badd 100644 --- a/include/gp/algorithm/move.hpp +++ b/include/gp/algorithms/move.hpp @@ -1,8 +1,8 @@ #pragma once -#include "gp/algorithm/tmp_manip.hpp" -#include "gp/algorithm/cvref.hpp" -#include "gp/range.hpp" +#include "gp/algorithms/tmp_manip.hpp" +#include "gp/algorithms/cvref.hpp" +#include "gp/utils/range.hpp" namespace gp{ template diff --git a/include/gp/algorithm/reference.hpp b/include/gp/algorithms/reference.hpp similarity index 98% rename from include/gp/algorithm/reference.hpp rename to include/gp/algorithms/reference.hpp index cdb30fa..8420c56 100644 --- a/include/gp/algorithm/reference.hpp +++ b/include/gp/algorithms/reference.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include namespace gp{ diff --git a/include/gp/algorithm/repeat.hpp b/include/gp/algorithms/repeat.hpp similarity index 100% rename from include/gp/algorithm/repeat.hpp rename to include/gp/algorithms/repeat.hpp diff --git a/include/gp/algorithm/rotate.hpp b/include/gp/algorithms/rotate.hpp similarity index 93% rename from include/gp/algorithm/rotate.hpp rename to include/gp/algorithms/rotate.hpp index 126f7e1..8296894 100644 --- a/include/gp/algorithm/rotate.hpp +++ b/include/gp/algorithms/rotate.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/algorithm/move.hpp" +#include "gp/algorithms/move.hpp" namespace gp { template diff --git a/include/gp/algorithm/tmp_manip.hpp b/include/gp/algorithms/tmp_manip.hpp similarity index 99% rename from include/gp/algorithm/tmp_manip.hpp rename to include/gp/algorithms/tmp_manip.hpp index a484b72..01cb41a 100644 --- a/include/gp/algorithm/tmp_manip.hpp +++ b/include/gp/algorithms/tmp_manip.hpp @@ -4,7 +4,7 @@ #include #include #include -#include "gp/algorithm/min_max.hpp" +#include "gp/algorithms/min_max.hpp" namespace gp{ diff --git a/include/gp/array.hpp b/include/gp/containers/array.hpp similarity index 98% rename from include/gp/array.hpp rename to include/gp/containers/array.hpp index fcf7399..419ff59 100644 --- a/include/gp/array.hpp +++ b/include/gp/containers/array.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/include/gp/buffer.hpp b/include/gp/containers/buffer.hpp similarity index 94% rename from include/gp/buffer.hpp rename to include/gp/containers/buffer.hpp index beccefc..3508005 100644 --- a/include/gp/buffer.hpp +++ b/include/gp/containers/buffer.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include #include -#include -#include +#include +#include #include #include diff --git a/include/gp/flat_tree.hpp b/include/gp/containers/flat_tree.hpp similarity index 85% rename from include/gp/flat_tree.hpp rename to include/gp/containers/flat_tree.hpp index 5ad62b0..932fd99 100644 --- a/include/gp/flat_tree.hpp +++ b/include/gp/containers/flat_tree.hpp @@ -1,6 +1,6 @@ #pragma one -#include +#include #include #include // UNIMPLEMENTED: see filename diff --git a/include/gp/indexed_array.hpp b/include/gp/containers/indexed_array.hpp similarity index 91% rename from include/gp/indexed_array.hpp rename to include/gp/containers/indexed_array.hpp index 1e54b34..988e62a 100644 --- a/include/gp/indexed_array.hpp +++ b/include/gp/containers/indexed_array.hpp @@ -2,13 +2,19 @@ #include "gp_config.hpp" -#include "gp/algorithm/move.hpp" -#include "gp/array.hpp" -#include "gp/iterator.hpp" +#include "gp/algorithms/move.hpp" +#include "gp/containers/array.hpp" +#include "gp/utils/iterator.hpp" #include namespace gp{ + /** + * @brief An array that has static indexes that are not affected by deletions or new additions + * + * @tparam T The stored type + * @tparam _capacity The total capacity of the array + */ template class indexed_array{ size_t data_top = 0; diff --git a/include/gp/bloomfilter.hpp b/include/gp/containers/probabilistic/bloomfilter.hpp similarity index 90% rename from include/gp/bloomfilter.hpp rename to include/gp/containers/probabilistic/bloomfilter.hpp index 21f1ef8..efffd72 100644 --- a/include/gp/bloomfilter.hpp +++ b/include/gp/containers/probabilistic/bloomfilter.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include diff --git a/include/gp/quotient_filter.hpp b/include/gp/containers/probabilistic/quotient_filter.hpp similarity index 97% rename from include/gp/quotient_filter.hpp rename to include/gp/containers/probabilistic/quotient_filter.hpp index 32feffc..28bca5a 100644 --- a/include/gp/quotient_filter.hpp +++ b/include/gp/containers/probabilistic/quotient_filter.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include diff --git a/include/gp/ring_list.hpp b/include/gp/containers/ring_list.hpp similarity index 94% rename from include/gp/ring_list.hpp rename to include/gp/containers/ring_list.hpp index fd600c6..a4bfbdc 100644 --- a/include/gp/ring_list.hpp +++ b/include/gp/containers/ring_list.hpp @@ -2,10 +2,10 @@ #include "gp_config.hpp" -#include "gp/algorithm/modifiers.hpp" -#include "gp/algorithm/tmp_manip.hpp" -#include "gp/allocator/allocator.hpp" -#include "gp/allocator/dummy.hpp" +#include "gp/algorithms/modifiers.hpp" +#include "gp/algorithms/tmp_manip.hpp" +#include "gp/utils/allocators/allocator.hpp" +#include "gp/utils/allocators/dummy.hpp" #include diff --git a/include/gp/vector.hpp b/include/gp/containers/vector.hpp similarity index 98% rename from include/gp/vector.hpp rename to include/gp/containers/vector.hpp index 9aaeaa4..ff9bdab 100644 --- a/include/gp/vector.hpp +++ b/include/gp/containers/vector.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include #include diff --git a/include/gp/function.hpp b/include/gp/functional/function.hpp similarity index 97% rename from include/gp/function.hpp rename to include/gp/functional/function.hpp index c6e486b..02aa50a 100644 --- a/include/gp/function.hpp +++ b/include/gp/functional/function.hpp @@ -1,11 +1,11 @@ #pragma once #include "gp/exception.hpp" -#include "gp/algorithm/modifiers.hpp" -#include "gp/algorithm/move.hpp" -#include "gp/algorithm/tmp_manip.hpp" -#include "gp/allocator/allocator.hpp" -#include "gp/optional.hpp" +#include "gp/algorithms/modifiers.hpp" +#include "gp/algorithms/move.hpp" +#include "gp/algorithms/tmp_manip.hpp" +#include "gp/utils/allocators/allocator.hpp" +#include "gp/functional/optional.hpp" namespace gp{ diff --git a/include/gp/optional.hpp b/include/gp/functional/optional.hpp similarity index 94% rename from include/gp/optional.hpp rename to include/gp/functional/optional.hpp index 38d7ec9..5d744ca 100644 --- a/include/gp/optional.hpp +++ b/include/gp/functional/optional.hpp @@ -2,8 +2,8 @@ #include "gp_config.hpp" -#include "gp/algorithm/modifiers.hpp" -#include "gp/algorithm/move.hpp" +#include "gp/algorithms/modifiers.hpp" +#include "gp/algorithms/move.hpp" #include "gp/exception.hpp" #include diff --git a/include/gp/variant.hpp b/include/gp/functional/variant.hpp similarity index 98% rename from include/gp/variant.hpp rename to include/gp/functional/variant.hpp index 8dd123c..5fb7871 100644 --- a/include/gp/variant.hpp +++ b/include/gp/functional/variant.hpp @@ -2,12 +2,11 @@ #include "gp_config.hpp" -#include -#include -#include "gp/allocator/dummy.hpp" +#include +#include +#include "gp/utils/allocators/dummy.hpp" #include "gp/exception.hpp" -#include "gp/function.hpp" -#include "gp/memory.hpp" +#include "gp/functional/function.hpp" #include #include diff --git a/include/gp/enveloppe/cbor.hpp b/include/gp/ipc/enveloppe/cbor.hpp similarity index 98% rename from include/gp/enveloppe/cbor.hpp rename to include/gp/ipc/enveloppe/cbor.hpp index b12eb25..46bed25 100644 --- a/include/gp/enveloppe/cbor.hpp +++ b/include/gp/ipc/enveloppe/cbor.hpp @@ -1,11 +1,11 @@ #pragma once -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include namespace gp { diff --git a/include/gp/vfs/file_description.hpp b/include/gp/ipc/file_description.hpp similarity index 100% rename from include/gp/vfs/file_description.hpp rename to include/gp/ipc/file_description.hpp diff --git a/include/gp/vfs/filesystem.hpp b/include/gp/ipc/filesystem.hpp similarity index 81% rename from include/gp/vfs/filesystem.hpp rename to include/gp/ipc/filesystem.hpp index 31ee2ae..6771304 100644 --- a/include/gp/vfs/filesystem.hpp +++ b/include/gp/ipc/filesystem.hpp @@ -1,8 +1,8 @@ #pragma once -#include "gp/buffer.hpp" -#include "gp/vector.hpp" -#include "gp/vfs/file_description.hpp" +#include "gp/containers/buffer.hpp" +#include "gp/containers/vector.hpp" +#include "gp/ipc/file_description.hpp" namespace gp{ diff --git a/include/gp/vfs/io/io_future.hpp b/include/gp/ipc/io/io_future.hpp similarity index 100% rename from include/gp/vfs/io/io_future.hpp rename to include/gp/ipc/io/io_future.hpp diff --git a/include/gp/vfs/io/io_operation.hpp b/include/gp/ipc/io/io_operation.hpp similarity index 99% rename from include/gp/vfs/io/io_operation.hpp rename to include/gp/ipc/io/io_operation.hpp index ca7d2e4..171c121 100644 --- a/include/gp/vfs/io/io_operation.hpp +++ b/include/gp/ipc/io/io_operation.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/array.hpp" +#include "gp/containers/array.hpp" #include #include diff --git a/include/gp/iterator.hpp b/include/gp/iterator.hpp deleted file mode 100644 index 689e41e..0000000 --- a/include/gp/iterator.hpp +++ /dev/null @@ -1,237 +0,0 @@ -#pragma once - -#include -#include - -// BUG: none of this is in a namespace -// TODO: Specify the concept of an iterator - -/** - * @brief An enumeration that may be used to determine iterator categories - * - */ -enum class iterator_type_t{ - contiguous_iterator, /**< Defines an iterator for something that is continuous and random access */ - non_contiguous_iterator, /**< Defines an iterator for a non contiguous datastructure, for example an iterator over a hashmap or a tree*/ - lazy_iterator /**< Defines an iterator for which the actual data layout and availability are still unknown*/ -}; - -/** - * @brief An abstraction of a pointer to iterate against, in both normal and reverse order - * - * @tparam T The type of data pointed by the iterator - * @tparam sign the direction in which data is scrutinized, should be either 1 or -1, behaviour for other value is left undefined - */ -template -struct pointer_iterator final -{ - T* data; /**< the only data field of the class */ - typedef T value_type; /**< The type of which a reference will be returned on dereferencing */ - typedef std::size_t difference_type; /**< The type of the substraction of two pointers */ - static constexpr iterator_type_t iterator_type = iterator_type_t::contiguous_iterator; /**< @see iterator_type_t */ - - /** - * @brief Generates an empty iterator - */ - constexpr pointer_iterator() - : data{nullptr} - {} - - constexpr pointer_iterator(const pointer_iterator& oth) - : data{oth.data} - {} - - /** - * @brief Generates an iterator from any pointer - */ - constexpr pointer_iterator(T* ptr) - : data{ptr} - {} - - /** - * @brief Dereference unary operator - * - * @return constexpr T& returns a reference to the pointed value - */ - constexpr T& operator*() const - { - return *data; - } - - constexpr pointer_iterator& operator++() - { - data += sign; - return *this; - } - - constexpr pointer_iterator operator++(int) - { - auto p = *this; - data += sign; - return p; - } - - constexpr pointer_iterator& operator--() - { - data -= sign; - return *this; - } - - constexpr pointer_iterator operator--(int) - { - auto p = *this; - data -= sign; - return p; - } - - constexpr pointer_iterator operator+(const std::size_t offset) const - { - return pointer_iterator{data+sign*offset}; - } - - constexpr pointer_iterator operator+(const int offset) const - { - return pointer_iterator{data+sign*offset}; - } - - constexpr pointer_iterator operator-(const std::size_t offset) const - { - return pointer_iterator{data-sign*offset}; - } - - constexpr pointer_iterator operator-(const int offset) const - { - return pointer_iterator{data-sign*offset}; - } - - constexpr difference_type operator-(const pointer_iterator& oth) const - { - return ((T*)data-(T*)oth.data)*sign; - } - - constexpr bool operator==(const pointer_iterator oth) const - { - return data==oth.data; - } - - constexpr bool operator!=(pointer_iterator oth) const - { - return data!=oth.data; - } - - constexpr bool before_or_equal(const pointer_iterator oth) const - { - return reinterpret_cast(data) <= reinterpret_cast(oth.data); - } - - constexpr bool operator<=(const pointer_iterator oth) const - { - return before_or_equal(oth); - } -}; - -/** - * @brief An identical twin to the pointer_iterator, but which dereference to a const reference - * - * @see pointer_iterator - * @tparam T @see pointer_iterator - * @tparam sign @see pointer_iterator - */ -template -struct const_pointer_iterator final -{ - const T* data; /**< @see pointer_iterator */ - typedef T value_type; /**< @see pointer_iterator */ - typedef std::size_t difference_type; /**< @see pointer_iterator */ - static constexpr iterator_type_t iterator_type = iterator_type_t::contiguous_iterator; /**< @see pointer_iterator */ - - constexpr const_pointer_iterator(const const_pointer_iterator& oth) - : data{oth.data} - {} - - /** - * @brief @see pointer_iterator - */ - constexpr const_pointer_iterator(const T* ptr) - : data{ptr} - {} - - /** - * @brief Dereferencing returns a const version of what a pointer_iterator would return - */ - constexpr const T& operator*() const - { - return *data; - } - - constexpr const_pointer_iterator& operator++() - { - data += sign; - return *this; - } - - constexpr const_pointer_iterator operator++(int) - { - auto p = data; - data += sign; - return const_pointer_iterator{p}; - } - - constexpr const_pointer_iterator& operator--() - { - data -= sign; - return *this; - } - - constexpr const_pointer_iterator operator--(int) - { - auto p = data; - data -= sign; - return const_pointer_iterator{p}; - } - - constexpr const_pointer_iterator operator+(const std::size_t offset) const - { - return const_pointer_iterator{data+sign*offset}; - } - - constexpr const_pointer_iterator operator+(const int offset) const - { - return const_pointer_iterator{data+sign*offset}; - } - - constexpr const_pointer_iterator operator-(const std::size_t offset) const - { - return const_pointer_iterator{data-sign*offset}; - } - - constexpr const_pointer_iterator operator-(const int offset) - { - return const_pointer_iterator{data-sign*offset}; - } - - constexpr difference_type operator-(const const_pointer_iterator& oth) const - { - return ((T*)data-(T*)oth.data)*sign; - } - - constexpr bool operator==(const const_pointer_iterator oth) const - { - return data==oth.data; - } - - constexpr bool operator!=(const_pointer_iterator oth) const - { - return data!=oth.data; - } - - constexpr bool before_or_equal(const const_pointer_iterator oth) const - { - return reinterpret_cast(data) <= reinterpret_cast(oth.data); - } - - constexpr bool operator<=(const const_pointer_iterator oth) const - { - return before_or_equal(oth); - } -}; \ No newline at end of file diff --git a/include/gp/math.hpp b/include/gp/math.hpp index 0a2259f..fc9ec26 100644 --- a/include/gp/math.hpp +++ b/include/gp/math.hpp @@ -2,352 +2,11 @@ #include "gp_config.hpp" -#include "gp/algorithm/min_max.hpp" -#include "gp/algorithm/repeat.hpp" -#include "gp/math/integer_math.hpp" +#include "gp/algorithms/min_max.hpp" +#include "gp/algorithms/repeat.hpp" +#include "gp/math/integral.hpp" #if !defined(NO_FP_MATH) -# include "gp/math/fp_math.hpp" +# include "gp/math/ieee754.hpp" #endif -#include "gp/math/q_math.hpp" - -namespace gp { - template - T lerp(T input, T low, T high) { - return low + (high - low) * input; - } - template - T lextrap(T input, T low, T high) { - return (input - low) / (high - low); - } - - template - T fixed_sqrt(T value) { - gp_config::assertion(value >= 0, "trying to compute square root of negative number"); - if(value == 0) return 0; - T ret = value / 2; - T tmp; - - gp::repeat(fixed_passes, [&](){ - tmp = ret; - ret = (value / tmp + tmp) / 2; - }); - - return ret; - } - - template - T epsilon_sqrt(T value) { - gp_config::assertion(value >= 0, "trying to compute square root of negative number"); - if(value == 0) return 0; - T ret = value / 2; - T tmp; - constexpr T epsilon = gp_config::rendering::epsilon; - size_t cnt = 0; - while( - !( - (ret+epsilon)*ret > value - && (ret-epsilon)*ret < value - ) - && cnt < cap_passes - ){ - tmp = ret; - ret = (value / tmp + tmp) / 2; - ++cnt; - }; - - return ret; - } - - template - T stable_sqrt(T value) { - gp_config::assertion(value >= 0, "trying to compute square root of negative number"); - if(value == 0) return 0; - T ret = value / 2; - T tmp; - while(ret != tmp){ - tmp = ret; - ret = (value / tmp + tmp) / 2; - }; - - return ret; - } - - template - struct vec2_g { - T x; - T y; - - vec2_g() - : x{} - , y{} - {} - - vec2_g( - T _x, - T _y - ) - : x{_x} - , y{_y} - {} - - vec2_g operator/(vec2_g rhs) { - return { - x / rhs.x, - y / rhs.y - }; - } - - vec2_g operator*(vec2_g rhs) { - return { - x * rhs.x, - y * rhs.y - }; - } - - vec2_g operator+(vec2_g oth) { - return {x+oth.x, y+oth.y}; - } - - vec2_g operator-(vec2_g oth) { - return {x-oth.x, y-oth.y}; - } - - vec2_g normalize() { - T ilen = fast_isqrt(x*x+y*y); - return {x*ilen, y*ilen}; - } - - T length() { - return fixed_sqrt(x*x+y*y); - } - }; - - template - struct vec3_g { - T x; - T y; - T z; - - T& r(){ - return x; - } - T& g(){ - return y; - } - T& b(){ - return z; - } - - vec3_g() - : x{} - , y{} - , z{} - {} - - vec3_g( - T _x, - T _y, - T _z - ) - : x{_x} - , y{_y} - , z{_z} - {} - - vec3_g(vec2_g left, T right) - : x{left.x} - , y{left.y} - , z{right} - {} - - vec3_g(T left, vec2_g right) - : x{left} - , y{right.x} - , z{right.y} - {} - - vec3_g operator/(vec3_g rhs) { - return { - x / rhs.x, - y / rhs.y, - z / rhs.z - }; - } - - vec3_g operator*(vec3_g rhs) { - return { - x * rhs.x, - y * rhs.y, - z * rhs.z - }; - } - - vec3_g operator+(vec3_g oth) { - return {x+oth.x, y+oth.y, z+oth.z}; - } - - vec3_g operator-(vec3_g oth) { - return {x-oth.x, y-oth.y, z-oth.z}; - } - - vec3_g normalize() { - T ilen = fast_isqrt(x*x+y*y+z*z); - return {x*ilen, y*ilen, z*ilen}; - } - - T length() { - return fixed_sqrt(x*x+y*y+z*z); - } - }; - - template - struct vec4_g { - T x; - T y; - T z; - T w; - - T& r(){ - return x; - } - T& g(){ - return y; - } - T& b(){ - return z; - } - T& a(){ - return w; - } - - vec4_g() - : x{} - , y{} - , z{} - , w{} - {} - - vec4_g( - T _x, - T _y, - T _z, - T _w - ) - : x{_x} - , y{_y} - , z{_z} - , w{_w} - {} - - vec4_g(T left, vec3_g<> right) - : x{left} - , y{right.x} - , z{right.y} - , w{right.z} - {} - - vec4_g(vec3_g<> left, T right) - : x{left.x} - , y{left.y} - , z{left.z} - , w{right} - {} - - vec4_g operator/(vec4_g rhs) { - return { - x / rhs.x, - y / rhs.y, - z / rhs.z, - w / rhs.w - }; - } - - vec4_g operator*(vec4_g rhs) { - return { - x * rhs.x, - y * rhs.y, - z * rhs.z, - w * rhs.w - }; - } - - vec4_g operator+(vec4_g oth) { - return {x+oth.x, y+oth.y, z+oth.z, w+oth.w}; - } - - vec4_g operator-(vec4_g oth) { - return {x-oth.x, y-oth.y, z-oth.w, z-oth.w}; - } - - vec4_g normalize() { - T ilen = fast_isqrt(x*x+y*y+z*z+w*w); - return {x*ilen, y*ilen, z*ilen, w*ilen}; - } - - T length() { - return fixed_sqrt(x*x+y*y+z*z+w*w); - } - }; - - template - auto sphere_sdf(vec3_g center, T radius) { - return [=](vec3_g position) -> T const { - auto p = position - center; - return p.length() - radius; - }; - } - - template - auto union_sdf(lhs _l, rhs _r) { - return [=](vec3_g position) -> T const { - return gp::min(_l(position), _r(position)); - }; - } - - template - auto intersect_sdf(lhs _l, rhs _r) { - return [=](vec3_g position) -> T const { - return gp::max(_l(position), _r(position)); - }; - } - - template - auto difference_sdf(lhs _l, rhs _r) { - return [=](vec3_g position) -> T const { - return gp::max(_l(position), -_r(position)); - }; - } - - template - vec2_g operator*(vec2_g p, T v) { - return {p.x*v, p.y*v}; - } - - template - vec3_g operator*(vec3_g p, T v) { - return {p.x*v, p.y*v, p.z*v}; - } - - template - vec4_g operator*(vec4_g p, T v) { - return {p.x*v, p.y*v, p.z*v, p.w*v}; - } - - template - vec2_g operator*(T v, vec2_g p) { - return p*v; - } - - template - vec3_g operator*(T v, vec3_g p) { - return p*v; - } - - template - vec4_g operator*(T v, vec4_g p) { - return p*v; - } -} - -static_assert(sizeof(gp::vec3_g) == sizeof(int)*3, "vec3_g has strange alignment"); -static_assert(sizeof(gp::vec4_g) == sizeof(int)*4, "vec4_g has strange alignment"); \ No newline at end of file +#include "gp/math/q_n.hpp" +#include "gp/math/general_purpose.hpp" diff --git a/include/gp/bitops.hpp b/include/gp/math/boolean/bitops.hpp similarity index 100% rename from include/gp/bitops.hpp rename to include/gp/math/boolean/bitops.hpp diff --git a/include/gp/math/details/math_definitions.hpp b/include/gp/math/details/math_definitions.hpp new file mode 100644 index 0000000..a798b98 --- /dev/null +++ b/include/gp/math/details/math_definitions.hpp @@ -0,0 +1,35 @@ +#pragma once + +namespace gp { + namespace math { + template + constexpr T pi; + + template + T abs(T); + + template + word_t log2(word_t v); + + /** + * @brief Returns \f$n\f$ so that it is the smallest value that matches for \f$v\leq{}log2(2^n)\f$ + * + * @tparam word_t + * @param v + * @return constexpr word_t + */ + template + constexpr word_t msb(word_t v); + + /** + * @brief Reads the sign of a value + * + * @tparam T + * @return -1 if the value is negative + * @return 0 if the value is 0 or not a number + * @return 1 if the value is positive + */ + template + T sign(T); + } +} \ No newline at end of file diff --git a/include/gp/math/fp_math.hpp b/include/gp/math/fp_math.hpp deleted file mode 100644 index caa40a8..0000000 --- a/include/gp/math/fp_math.hpp +++ /dev/null @@ -1,267 +0,0 @@ -#pragma once - -#include "gp/algorithm/repeat.hpp" - -#include - -#include -#include - -namespace gp{ - - template - constexpr T pi; - - template<> - constexpr float pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062; - - template<> - constexpr double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062L; - - template - T abs(T); - - template<> - float abs(float value) { - static_assert(sizeof(float) == 4, "bad float size"); - union { - float fp; - uint32_t ab; - } p; - p.fp = value; - p.ab &= 0x7fFFffFF; - return p.fp; - } - - template<> - double abs(double value) { - static_assert(sizeof(double) == 8, "bad double size"); - union { - double fp; - uint64_t ab; - } p; - p.fp = value; - p.ab &= 0x7fFFffFFffFFffFF; - return p.fp; - } - - template - T floor(T); - - template<> - float floor(float value) { - static_assert(sizeof(float) == 4, "bad float size"); - if( - value >= 16777216 - || value <= std::numeric_limits::min() - || value != value - ) { - return value; - } - int32_t ret = value; - float ret_d = ret; - if(value == ret_d || value >= 0) { - return ret; - } else { - return ret-1; - } - } - - template<> - double floor(double value) { - static_assert(sizeof(double) == 8, "bad double size"); - if( - value >= 9007199254740992 - || value <= std::numeric_limits::min() - || value != value - ) { - return value; - } - int64_t ret = value; - double ret_d = ret; - if(value == ret_d || value >= 0) { - return ret; - } else { - return ret-1; - } - } - - /** - * @brief Reads the sign of a value - * - * @tparam T - * @return -1 if the value is negative - * @return 0 if the value is 0 or not a number - * @return 1 if the value is positive - */ - template - T sign(T); - - template<> - float sign(float value) { - static_assert(sizeof(float) == 4, "bad float size"); - if(!value) return 0; - union { - float fp; - uint32_t ab; - } p; - p.fp = value; - p.ab &= 0x7fFFffFF; - return value/p.fp; - } - - template<> - double sign(double value) { - static_assert(sizeof(double) == 8, "bad double size"); - if(!value) return 0; - union { - double fp; - uint64_t ab; - } p; - p.fp = value; - p.ab &= 0x7fFFffFFffFFffFF; - return value/p.fp; - } - - - /** - * @brief Calculate the sin of a value using Taylor's method - * - * @tparam steps The number of steps to do at the maximum - * @tparam T the type of value and the return type expected - * @tparam accuracy the maximum accuracy to shoot for (early stopping) - * @param value The value to calculate the sin of. Works better for values close to 0. - * @return T the sin of the value (the sign may be off idk I don't remember) - */ - template - T sin_taylor(T value) { - const T acc = T{1}/T{accuracy}; - T B = value; - T C = 1; - T ret = B/C; - for(size_t i = 1; (i < steps) && (abs<>(B/C) > acc); ++i) { - B *= -1*value*value; - C *= 2*i*(2*i+1); - ret += B/C; - } - return ret; - } - - /** - * @brief General purpose sin function - * - * @param v - * @return float - */ - float sin(float v) { - // limit the range between -pi and +pi - v += pi; - v = v - 2*pi*floor(v/(2*pi)); - v -= pi; - float s = sign(v); - v *= s; - - // use taylor's method on the value - return sin_taylor<10>(v)*s; - } - - /** - * @brief General purpose sin function - * - * @param v - * @return double - */ - double sin(double v) { - v += pi; - v = v - 2*pi*floor(v/(2*pi)); - v -= pi; - float s = sign(v); - v *= s; - return sin_taylor<10>(v)*s; - } - - - // TODO: replace with an actual implementation - float cos(float v) { - return sin(v+pi/2); - } - - // TODO: replace with an actual implementation - double cos(double v) { - return sin(v+pi/2); - } - - // TODO: replace with an actual implementation - float tan(float v) { - return sin(v)/cos(v); - } - - // TODO: replace with an actual implementation - double tan(double v) { - return sin(v)/cos(v); - } - - - /** - * @brief Quake isqrt (x) -> 1/sqrt(x) - * - * @tparam cycles the number of newton method cycles to apply - * @param v the value to apply the function on - * @return float \f$\frac{1}{\sqrt{v}}\f$ - */ - template - float isqrt(float v) { - int32_t i; - float x2, y; - constexpr float threehalfs = 1.5F; - - x2 = v * 0.5F; - y = v; - i = * ( int32_t * ) &y; - i = 0x5F375A86 - ( i >> 1 ); - y = * ( float * ) &i; - gp::repeat(cycles, [&](){ - y = y * ( threehalfs - ( x2 * y * y ) ); - }); - return y; - } - - /** - * @brief Quake isqrt (x) -> 1/sqrt(x) but for doubles - * - * @tparam cycles the number of newton method cycles to apply - * @param v the value to apply the function on - * @return double \f$\frac{1}{\sqrt{v}}\f$ - */ - template - double isqrt(double v) { - int64_t i; - double x2, y; - constexpr double threehalfs = 1.5F; - - x2 = v * 0.5F; - y = v; - i = * ( int64_t * ) &y; - i = 0x5FE6EB50C7B537A9 - ( i >> 1 ); - y = * ( double * ) &i; - gp::repeat(cycles, [&](){ - y = y * ( threehalfs - ( x2 * y * y ) ); - }); - return y; - } - - /** - * @brief A faster version of the Quake isqrt (actually the same but with defined cycles) - * - * @param v - * @return float - */ - float fast_isqrt(float v) {return isqrt<1>(v);} - /** - * @brief A faster version of the Quake isqrt (actually the same but with defined cycles) - * - * @param v - * @return double - */ - double fast_isqrt(double v) {return isqrt<1>(v);} -} diff --git a/include/gp/math/general_purpose.hpp b/include/gp/math/general_purpose.hpp new file mode 100644 index 0000000..62035cd --- /dev/null +++ b/include/gp/math/general_purpose.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include "gp_config.hpp" + +#include "gp/algorithms/repeat.hpp" + +namespace gp { + template + T lerp(T input, T low, T high) { + return low + (high - low) * input; + } + template + T lextrap(T input, T low, T high) { + return (input - low) / (high - low); + } + + template + T fixed_sqrt(T value) { + gp_config::assertion(value >= 0, "trying to compute square root of negative number"); + if(value == 0) return 0; + T ret = value / 2; + T tmp; + + gp::repeat(fixed_passes, [&](){ + tmp = ret; + ret = (value / tmp + tmp) / 2; + }); + + return ret; + } + + template + T epsilon_sqrt(T value) { + gp_config::assertion(value >= 0, "trying to compute square root of negative number"); + if(value == 0) return 0; + T ret = value / 2; + T tmp; + constexpr T epsilon = gp_config::rendering::epsilon; + size_t cnt = 0; + while( + !( + (ret+epsilon)*ret > value + && (ret-epsilon)*ret < value + ) + && cnt < cap_passes + ){ + tmp = ret; + ret = (value / tmp + tmp) / 2; + ++cnt; + }; + + return ret; + } + + template + T stable_sqrt(T value) { + gp_config::assertion(value >= 0, "trying to compute square root of negative number"); + if(value == 0) return 0; + T ret = value / 2; + T tmp; + while(ret != tmp){ + tmp = ret; + ret = (value / tmp + tmp) / 2; + }; + + return ret; + } +} \ No newline at end of file diff --git a/include/gp/math/ieee754.hpp b/include/gp/math/ieee754.hpp new file mode 100644 index 0000000..778de10 --- /dev/null +++ b/include/gp/math/ieee754.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "gp/math/ieee754/fp_math.hpp" \ No newline at end of file diff --git a/include/gp/math/ieee754/fp_math.hpp b/include/gp/math/ieee754/fp_math.hpp new file mode 100644 index 0000000..3a0b50b --- /dev/null +++ b/include/gp/math/ieee754/fp_math.hpp @@ -0,0 +1,255 @@ +#pragma once + + +#include "gp/algorithms/repeat.hpp" +#include "gp/math/details/math_definitions.hpp" + +#include + +#include +#include + +namespace gp{ + namespace math{ + + template<> + constexpr float pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062; + + template<> + constexpr double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062L; + + + template<> + float abs(float value) { + static_assert(sizeof(float) == 4, "bad float size"); + union { + float fp; + uint32_t ab; + } p; + p.fp = value; + p.ab &= 0x7fFFffFF; + return p.fp; + } + + template<> + double abs(double value) { + static_assert(sizeof(double) == 8, "bad double size"); + union { + double fp; + uint64_t ab; + } p; + p.fp = value; + p.ab &= 0x7fFFffFFffFFffFF; + return p.fp; + } + + template + T floor(T); + + template<> + float floor(float value) { + static_assert(sizeof(float) == 4, "bad float size"); + if( + value >= 16777216 + || value <= std::numeric_limits::min() + || value != value + ) { + return value; + } + int32_t ret = value; + float ret_d = ret; + if(value == ret_d || value >= 0) { + return ret; + } else { + return ret-1; + } + } + + template<> + double floor(double value) { + static_assert(sizeof(double) == 8, "bad double size"); + if( + value >= 9007199254740992 + || value <= std::numeric_limits::min() + || value != value + ) { + return value; + } + int64_t ret = value; + double ret_d = ret; + if(value == ret_d || value >= 0) { + return ret; + } else { + return ret-1; + } + } + + template<> + float sign(float value) { + static_assert(sizeof(float) == 4, "bad float size"); + if(!value) return 0; + union { + float fp; + uint32_t ab; + } p; + p.fp = value; + p.ab &= 0x7fFFffFF; + return value/p.fp; + } + + template<> + double sign(double value) { + static_assert(sizeof(double) == 8, "bad double size"); + if(!value) return 0; + union { + double fp; + uint64_t ab; + } p; + p.fp = value; + p.ab &= 0x7fFFffFFffFFffFF; + return value/p.fp; + } + + + /** + * @brief Calculate the sin of a value using Taylor's method + * + * @tparam steps The number of steps to do at the maximum + * @tparam T the type of value and the return type expected + * @tparam accuracy the maximum accuracy to shoot for (early stopping) + * @param value The value to calculate the sin of. Works better for values close to 0. + * @return T the sin of the value (the sign may be off idk I don't remember) + */ + template + T sin_taylor(T value) { + const T acc = T{1}/T{accuracy}; + T B = value; + T C = 1; + T ret = B/C; + for(size_t i = 1; (i < steps) && (abs<>(B/C) > acc); ++i) { + B *= -1*value*value; + C *= 2*i*(2*i+1); + ret += B/C; + } + return ret; + } + + /** + * @brief General purpose sin function + * + * @param v + * @return float + */ + inline float sin(float v) { + // limit the range between -pi and +pi + v += pi; + v = v - 2*pi*floor(v/(2*pi)); + v -= pi; + float s = sign(v); + v *= s; + + // use taylor's method on the value + return sin_taylor<10>(v)*s; + } + + /** + * @brief General purpose sin function + * + * @param v + * @return double + */ + inline double sin(double v) { + v += pi; + v = v - 2*pi*floor(v/(2*pi)); + v -= pi; + float s = sign(v); + v *= s; + return sin_taylor<10>(v)*s; + } + + + // TODO: replace with an actual implementation + inline float cos(float v) { + return sin(v+pi/2); + } + + // TODO: replace with an actual implementation + inline double cos(double v) { + return sin(v+pi/2); + } + + // TODO: replace with an actual implementation + inline float tan(float v) { + return sin(v)/cos(v); + } + + // TODO: replace with an actual implementation + inline double tan(double v) { + return sin(v)/cos(v); + } + + + /** + * @brief Quake isqrt (x) -> 1/sqrt(x) + * + * @tparam cycles the number of newton method cycles to apply + * @param v the value to apply the function on + * @return float \f$\frac{1}{\sqrt{v}}\f$ + */ + template + float isqrt(float v) { + int32_t i; + float x2, y; + constexpr float threehalfs = 1.5F; + + x2 = v * 0.5F; + y = v; + i = * ( int32_t * ) &y; + i = 0x5F375A86 - ( i >> 1 ); + y = * ( float * ) &i; + gp::repeat(cycles, [&](){ + y = y * ( threehalfs - ( x2 * y * y ) ); + }); + return y; + } + + /** + * @brief Quake isqrt (x) -> 1/sqrt(x) but for doubles + * + * @tparam cycles the number of newton method cycles to apply + * @param v the value to apply the function on + * @return double \f$\frac{1}{\sqrt{v}}\f$ + */ + template + double isqrt(double v) { + int64_t i; + double x2, y; + constexpr double threehalfs = 1.5F; + + x2 = v * 0.5F; + y = v; + i = * ( int64_t * ) &y; + i = 0x5FE6EB50C7B537A9 - ( i >> 1 ); + y = * ( double * ) &i; + gp::repeat(cycles, [&](){ + y = y * ( threehalfs - ( x2 * y * y ) ); + }); + return y; + } + + /** + * @brief A faster version of the Quake isqrt (actually the same but with defined cycles) + * + * @param v + * @return float + */ + inline float fast_isqrt(float v) {return isqrt<1>(v);} + /** + * @brief A faster version of the Quake isqrt (actually the same but with defined cycles) + * + * @param v + * @return double + */ + inline double fast_isqrt(double v) {return isqrt<1>(v);} + } +} diff --git a/include/gp/math/integral.hpp b/include/gp/math/integral.hpp new file mode 100644 index 0000000..3d25567 --- /dev/null +++ b/include/gp/math/integral.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "gp/math/integral/logarithms.hpp" \ No newline at end of file diff --git a/include/gp/math/integer_math.hpp b/include/gp/math/integral/logarithms.hpp similarity index 82% rename from include/gp/math/integer_math.hpp rename to include/gp/math/integral/logarithms.hpp index 746dd01..a5db9d5 100644 --- a/include/gp/math/integer_math.hpp +++ b/include/gp/math/integral/logarithms.hpp @@ -1,20 +1,19 @@ #pragma once +#include "gp/math/details/math_definitions.hpp" + #include #include namespace gp { namespace math { - - template - size_t log2(word_t v); /** Sean Eron Anderson seander@cs.stanford.edu **/ template<> - constexpr size_t log2(uint32_t v) + constexpr uint32_t log2(uint32_t v) { constexpr int MultiplyDeBruijnBitPosition[32] = { @@ -32,7 +31,7 @@ namespace gp { } template<> - constexpr size_t log2(uint64_t v) + constexpr uint64_t log2(uint64_t v) { constexpr int MultiplyDeBruijnBitPosition[64] = { @@ -55,17 +54,14 @@ namespace gp { static_assert(log2(7) == 2, "bad log2"); static_assert(log2(8) == 3, "bad log2"); - template - constexpr size_t msb(word_t v); - template<> - constexpr size_t msb(uint32_t v) + constexpr uint32_t msb(uint32_t v) { auto l = log2(v); return l + (((1 << l) ^ v) != 0); } template<> - constexpr size_t msb(uint64_t v) + constexpr uint64_t msb(uint64_t v) { auto l = log2(v); return l + (((1 << l) ^ v) != 0); diff --git a/include/gp/math/q_math.hpp b/include/gp/math/q_n.hpp similarity index 100% rename from include/gp/math/q_math.hpp rename to include/gp/math/q_n.hpp diff --git a/include/gp/math/q_n/q_math.hpp b/include/gp/math/q_n/q_math.hpp new file mode 100644 index 0000000..f4200fc --- /dev/null +++ b/include/gp/math/q_n/q_math.hpp @@ -0,0 +1,3 @@ +#pragma once + +// UNIMPLEMENTED \ No newline at end of file diff --git a/include/gp/rendering/bmp_viewport.hpp b/include/gp/math/rendering/bmp_viewport.hpp similarity index 90% rename from include/gp/rendering/bmp_viewport.hpp rename to include/gp/math/rendering/bmp_viewport.hpp index dd4b734..fedcd22 100644 --- a/include/gp/rendering/bmp_viewport.hpp +++ b/include/gp/math/rendering/bmp_viewport.hpp @@ -1,20 +1,18 @@ #pragma once -#include "gp/algorithm/tmp_manip.hpp" -#include "gp/bitops.hpp" -#include "gp/buffer.hpp" -#include "gp/function.hpp" -#include "gp/math.hpp" +#include "gp/algorithms/tmp_manip.hpp" +#include "gp/math/boolean/bitops.hpp" +#include "gp/containers/buffer.hpp" +#include "gp/functional/function.hpp" +#include "gp/math/rendering_math.hpp" -#include - namespace gp{ /** * @brief A bmp format viewport that can be used to generate and export bmp file contents * * @tparam lazy if true, will expect the source to be a function, else would expect it to be a buffer - * @tparam color_type the type that represents the color. as of now only gp::vec4_g is supported + * @tparam color_type the type that represents the color. as of now only gp::math::vec4_g is supported */ template class bmp_viewport { @@ -23,12 +21,12 @@ namespace gp{ * @brief The type of data source expected */ using src_t = typename gp::either)>, + gp::function)>, gp::buffer> >::type; private: src_t source; - gp::vec2_g resolution; + gp::math::vec2_g resolution; color_type get(int32_t x, int32_t y) { gp_config::assertion(x>=0, "getting an x below zero"); gp_config::assertion(y>=0, "getting an y below zero"); @@ -46,7 +44,7 @@ namespace gp{ * @param res The viewport size in pixels * @param src The viewport source @see src_t */ - bmp_viewport(gp::vec2_g res, src_t src) + bmp_viewport(gp::math::vec2_g res, src_t src) : source{src} , resolution{res} {} @@ -128,7 +126,7 @@ namespace gp{ for(int32_t row = 0; row < resolution.x; row++) { // TODO: add more default color modes - if constexpr (std::is_same>::value) + if constexpr (std::is_same>::value) { auto color = get(row, line); *(it++) = color.b(); diff --git a/include/gp/rendering/characters.hpp b/include/gp/math/rendering/characters.hpp similarity index 99% rename from include/gp/rendering/characters.hpp rename to include/gp/math/rendering/characters.hpp index 49bdb13..9b3cd0a 100644 --- a/include/gp/rendering/characters.hpp +++ b/include/gp/math/rendering/characters.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/array.hpp" +#include "gp/containers/array.hpp" using display_char = gp::array; diff --git a/include/gp/rendering/renderer.hpp b/include/gp/math/rendering/renderer.hpp similarity index 76% rename from include/gp/rendering/renderer.hpp rename to include/gp/math/rendering/renderer.hpp index d06fec4..6195e23 100644 --- a/include/gp/rendering/renderer.hpp +++ b/include/gp/math/rendering/renderer.hpp @@ -2,15 +2,16 @@ #include "gp_config.hpp" -#include "gp/algorithm/min_of.hpp" -#include "gp/allocator/buddy.hpp" -#include "gp/function.hpp" -#include "gp/indexed_array.hpp" +#include "gp/algorithms/min_of.hpp" +#include "gp/utils/allocators/buddy.hpp" +#include "gp/functional/function.hpp" +#include "gp/containers/indexed_array.hpp" #include "gp/math.hpp" +#include "gp/math/rendering_math.hpp" -using vec2 = gp::vec2_g<>; -using vec3 = gp::vec3_g<>; -using vec4 = gp::vec4_g<>; +using vec2 = gp::math::vec2_g<>; +using vec3 = gp::math::vec3_g<>; +using vec4 = gp::math::vec4_g<>; struct camera{ vec3 position; @@ -78,19 +79,19 @@ public: pixel = pixel - half_res; pixel = pixel / half_res; pixel = pixel * _fov; - pixel = pixel / vec2{180, 180} * vec2{gp::pi,gp::pi}; + pixel = pixel / vec2{180, 180} * vec2{gp::math::pi,gp::math::pi}; // Y-rot (adjusts x) target = vec3{ - target.x*gp::cos(pixel.x) + target.z*gp::sin(pixel.x), + target.x*gp::math::cos(pixel.x) + target.z*gp::math::sin(pixel.x), target.y, - -target.x*gp::sin(pixel.x)+target.z*gp::cos(pixel.x) + -target.x*gp::math::sin(pixel.x)+target.z*gp::math::cos(pixel.x) }; // X-rot (adjusts y) target = vec3{ target.x, - target.y*gp::cos(pixel.y) - target.z*gp::sin(pixel.y), - target.y*gp::sin(pixel.y) + target.z*gp::cos(pixel.y) + target.y*gp::math::cos(pixel.y) - target.z*gp::math::sin(pixel.y), + target.y*gp::math::sin(pixel.y) + target.z*gp::math::cos(pixel.y) }; vec3 render_target{_camera.position}; diff --git a/include/gp/math/rendering_math.hpp b/include/gp/math/rendering_math.hpp new file mode 100644 index 0000000..17d0f6a --- /dev/null +++ b/include/gp/math/rendering_math.hpp @@ -0,0 +1,290 @@ +#pragma once + +#include "gp_config.hpp" + +#include "gp/algorithms/min_max.hpp" +#include "gp/algorithms/repeat.hpp" +#include "gp/math.hpp" + +namespace gp{ + namespace math { + template + struct vec2_g { + T x; + T y; + + vec2_g() + : x{} + , y{} + {} + + vec2_g( + T _x, + T _y + ) + : x{_x} + , y{_y} + {} + + vec2_g operator/(vec2_g rhs) { + return { + x / rhs.x, + y / rhs.y + }; + } + + vec2_g operator*(vec2_g rhs) { + return { + x * rhs.x, + y * rhs.y + }; + } + + vec2_g operator+(vec2_g oth) { + return {x+oth.x, y+oth.y}; + } + + vec2_g operator-(vec2_g oth) { + return {x-oth.x, y-oth.y}; + } + + vec2_g normalize() { + T ilen = fast_isqrt(x*x+y*y); + return {x*ilen, y*ilen}; + } + + T length() { + return fixed_sqrt(x*x+y*y); + } + }; + + template + struct vec3_g { + T x; + T y; + T z; + + T& r(){ + return x; + } + T& g(){ + return y; + } + T& b(){ + return z; + } + + vec3_g() + : x{} + , y{} + , z{} + {} + + vec3_g( + T _x, + T _y, + T _z + ) + : x{_x} + , y{_y} + , z{_z} + {} + + vec3_g(vec2_g left, T right) + : x{left.x} + , y{left.y} + , z{right} + {} + + vec3_g(T left, vec2_g right) + : x{left} + , y{right.x} + , z{right.y} + {} + + vec3_g operator/(vec3_g rhs) { + return { + x / rhs.x, + y / rhs.y, + z / rhs.z + }; + } + + vec3_g operator*(vec3_g rhs) { + return { + x * rhs.x, + y * rhs.y, + z * rhs.z + }; + } + + vec3_g operator+(vec3_g oth) { + return {x+oth.x, y+oth.y, z+oth.z}; + } + + vec3_g operator-(vec3_g oth) { + return {x-oth.x, y-oth.y, z-oth.z}; + } + + vec3_g normalize() { + T ilen = fast_isqrt(x*x+y*y+z*z); + return {x*ilen, y*ilen, z*ilen}; + } + + T length() { + return fixed_sqrt(x*x+y*y+z*z); + } + }; + + template + struct vec4_g { + T x; + T y; + T z; + T w; + + T& r(){ + return x; + } + T& g(){ + return y; + } + T& b(){ + return z; + } + T& a(){ + return w; + } + + vec4_g() + : x{} + , y{} + , z{} + , w{} + {} + + vec4_g( + T _x, + T _y, + T _z, + T _w + ) + : x{_x} + , y{_y} + , z{_z} + , w{_w} + {} + + vec4_g(T left, vec3_g<> right) + : x{left} + , y{right.x} + , z{right.y} + , w{right.z} + {} + + vec4_g(vec3_g<> left, T right) + : x{left.x} + , y{left.y} + , z{left.z} + , w{right} + {} + + vec4_g operator/(vec4_g rhs) { + return { + x / rhs.x, + y / rhs.y, + z / rhs.z, + w / rhs.w + }; + } + + vec4_g operator*(vec4_g rhs) { + return { + x * rhs.x, + y * rhs.y, + z * rhs.z, + w * rhs.w + }; + } + + vec4_g operator+(vec4_g oth) { + return {x+oth.x, y+oth.y, z+oth.z, w+oth.w}; + } + + vec4_g operator-(vec4_g oth) { + return {x-oth.x, y-oth.y, z-oth.w, z-oth.w}; + } + + vec4_g normalize() { + T ilen = fast_isqrt(x*x+y*y+z*z+w*w); + return {x*ilen, y*ilen, z*ilen, w*ilen}; + } + + T length() { + return fixed_sqrt(x*x+y*y+z*z+w*w); + } + }; + + template + auto sphere_sdf(vec3_g center, T radius) { + return [=](vec3_g position) -> T const { + auto p = position - center; + return p.length() - radius; + }; + } + + template + auto union_sdf(lhs _l, rhs _r) { + return [=](vec3_g position) -> T const { + return gp::min(_l(position), _r(position)); + }; + } + + template + auto intersect_sdf(lhs _l, rhs _r) { + return [=](vec3_g position) -> T const { + return gp::max(_l(position), _r(position)); + }; + } + + template + auto difference_sdf(lhs _l, rhs _r) { + return [=](vec3_g position) -> T const { + return gp::max(_l(position), -_r(position)); + }; + } + + template + vec2_g operator*(vec2_g p, T v) { + return {p.x*v, p.y*v}; + } + + template + vec3_g operator*(vec3_g p, T v) { + return {p.x*v, p.y*v, p.z*v}; + } + + template + vec4_g operator*(vec4_g p, T v) { + return {p.x*v, p.y*v, p.z*v, p.w*v}; + } + + template + vec2_g operator*(T v, vec2_g p) { + return p*v; + } + + template + vec3_g operator*(T v, vec3_g p) { + return p*v; + } + + template + vec4_g operator*(T v, vec4_g p) { + return p*v; + } + } +} + +static_assert(sizeof(gp::math::vec3_g) == sizeof(int)*3, "vec3_g has strange alignment"); +static_assert(sizeof(gp::math::vec4_g) == sizeof(int)*4, "vec4_g has strange alignment"); \ No newline at end of file diff --git a/include/gp/memory.hpp b/include/gp/memory.hpp deleted file mode 100644 index 1a9b13b..0000000 --- a/include/gp/memory.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include "gp_config.hpp" - -#include "gp/algorithm/move.hpp" -#include "gp/allocator/allocator.hpp" -#include "gp/exception.hpp" - -#include -// XXX: THIS FILE SHOULD BE REMOVED, AS SHOULD ALL DEPENDENCIES ON THE C-ALLOCATOR AS IS - -/* -namespace gp{ - template> - class default_memory_allocator - { - public: - using pointer_type = T*; - using reference_type = T&; - using const_pointer_type = const T*; - using const_reference_type = const T&; - - pointer_type allocate(size_t sz) - { - return reinterpret_cast (gp_config::memory_module::memory_allocator(sizeof(T) * sz)); - } - - void deallocate(pointer_type ptr) - { - gp_config::memory_module::memory_deallocator(ptr); - } - - template - pointer_type construct(pointer_type ptr, params... args) - { - new(ptr) T(args...); - return ptr; - } - - void destroy(pointer_type v) - { - v->~T(); - } - }; -} - -void* operator new(size_t sz) -{ - auto ptr = gp_config::memory_module::memory_allocator(sz); - if constexpr (gp_config::has_exceptions) - { - if(!ptr) - { - throw gp::bad_alloc{}; - } - } - return ptr; -} - -void operator delete (void* ptr) noexcept -{ - gp_config::memory_module::memory_deallocator(ptr); -} -*/ \ No newline at end of file diff --git a/include/gp/runtime.hpp b/include/gp/runtime.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/include/gp/subtree_iterator.hpp b/include/gp/subtree_iterator.hpp deleted file mode 100644 index 8ca8460..0000000 --- a/include/gp/subtree_iterator.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include -#include -// UNIMPLEMENTED: see filename - -template -struct subtree_iterator final -{ - gp::buffer target; - size_t idx; -public: - subtree_iterator() - : target{} - , idx{0} - {} - - subtree_iterator(gp::buffer data, size_t itr_idx) - : target{data} - , idx{itr_idx} - {} - - template - void climb_traversal(func& traverser) { - - } -}; \ No newline at end of file diff --git a/include/gp/vfs/platforms/gcc-x86_64.hpp b/include/gp/system/platforms/gcc-x86_64.hpp similarity index 97% rename from include/gp/vfs/platforms/gcc-x86_64.hpp rename to include/gp/system/platforms/gcc-x86_64.hpp index 5989951..2c04b87 100644 --- a/include/gp/vfs/platforms/gcc-x86_64.hpp +++ b/include/gp/system/platforms/gcc-x86_64.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/buffer.hpp" +#include "gp/containers/buffer.hpp" #include diff --git a/include/gp/vfs/platforms/platform_autopicker.hpp b/include/gp/system/platforms/platform_autopicker.hpp similarity index 74% rename from include/gp/vfs/platforms/platform_autopicker.hpp rename to include/gp/system/platforms/platform_autopicker.hpp index 7ccfdca..22c32d2 100644 --- a/include/gp/vfs/platforms/platform_autopicker.hpp +++ b/include/gp/system/platforms/platform_autopicker.hpp @@ -10,7 +10,7 @@ #elif defined(_M_X64) or defined(__amd64) - #include "gp/vfs/platforms/gcc-x86_64.hpp" + #include "gp/system/platforms/gcc-x86_64.hpp" #if __clang__ diff --git a/include/gp/vfs/process_data.hpp b/include/gp/system/process_data.hpp similarity index 85% rename from include/gp/vfs/process_data.hpp rename to include/gp/system/process_data.hpp index af3a2f5..478d993 100644 --- a/include/gp/vfs/process_data.hpp +++ b/include/gp/system/process_data.hpp @@ -1,11 +1,11 @@ #pragma once #include "gp_config.hpp" -#include "gp/function.hpp" -#include "gp/indexed_array.hpp" -#include "gp/pointers.hpp" -#include "gp/vfs/file_description.hpp" -#include "gp/vfs/platforms/platform_autopicker.hpp" +#include "gp/functional/function.hpp" +#include "gp/containers/indexed_array.hpp" +#include "gp/utils/pointers.hpp" +#include "gp/ipc/file_description.hpp" +#include "gp/system/platforms/platform_autopicker.hpp" #include diff --git a/include/gp/vfs/runqueue.hpp b/include/gp/system/runqueue.hpp similarity index 98% rename from include/gp/vfs/runqueue.hpp rename to include/gp/system/runqueue.hpp index 0b514ae..1a1e9a2 100644 --- a/include/gp/vfs/runqueue.hpp +++ b/include/gp/system/runqueue.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/vfs/process_data.hpp" +#include "gp/system/process_data.hpp" #include #include diff --git a/include/gp/vfs/scheduler.hpp b/include/gp/system/scheduler.hpp similarity index 83% rename from include/gp/vfs/scheduler.hpp rename to include/gp/system/scheduler.hpp index 0f7bb9d..1c6be8d 100644 --- a/include/gp/vfs/scheduler.hpp +++ b/include/gp/system/scheduler.hpp @@ -1,8 +1,8 @@ #pragma once -#include "gp/indexed_array.hpp" -#include "gp/vfs/process_data.hpp" -#include "gp/vfs/runqueue.hpp" +#include "gp/containers/indexed_array.hpp" +#include "gp/system/process_data.hpp" +#include "gp/system/runqueue.hpp" namespace gp{ diff --git a/include/gp/vfs/scheduling/simple_scheduling.hpp b/include/gp/system/scheduling/simple_scheduling.hpp similarity index 98% rename from include/gp/vfs/scheduling/simple_scheduling.hpp rename to include/gp/system/scheduling/simple_scheduling.hpp index 96e8aed..df847c7 100644 --- a/include/gp/vfs/scheduling/simple_scheduling.hpp +++ b/include/gp/system/scheduling/simple_scheduling.hpp @@ -1,5 +1,5 @@ #pragma once -#include "gp/vfs/system.hpp" +#include "gp/system/system.hpp" namespace gp{ diff --git a/include/gp/vfs/system.hpp b/include/gp/system/system.hpp similarity index 93% rename from include/gp/vfs/system.hpp rename to include/gp/system/system.hpp index 3b5e1bf..2af97a2 100644 --- a/include/gp/vfs/system.hpp +++ b/include/gp/system/system.hpp @@ -1,13 +1,13 @@ #pragma once -#include "gp/algorithm/foreach.hpp" -#include "gp/algorithm/reference.hpp" -#include "gp/allocator/allocator.hpp" -#include "gp/vector.hpp" -#include "gp/vfs/file_description.hpp" -#include "gp/vfs/filesystem.hpp" -#include "gp/vfs/runqueue.hpp" -#include "gp/vfs/scheduler.hpp" +#include "gp/algorithms/foreach.hpp" +#include "gp/algorithms/reference.hpp" +#include "gp/utils/allocators/allocator.hpp" +#include "gp/containers/vector.hpp" +#include "gp/ipc/file_description.hpp" +#include "gp/ipc/filesystem.hpp" +#include "gp/system/runqueue.hpp" +#include "gp/system/scheduler.hpp" namespace gp{ diff --git a/include/gp/utils/allocators.hpp b/include/gp/utils/allocators.hpp new file mode 100644 index 0000000..1e7047a --- /dev/null +++ b/include/gp/utils/allocators.hpp @@ -0,0 +1,5 @@ +#pragma once +#include "gp/utils/allocators/aggregator.hpp" +#include "gp/utils/allocators/arena.hpp" +#include "gp/utils/allocators/buddy.hpp" +#include "gp/utils/allocators/dummy.hpp" \ No newline at end of file diff --git a/include/gp/allocator/aggregator.hpp b/include/gp/utils/allocators/aggregator.hpp similarity index 95% rename from include/gp/allocator/aggregator.hpp rename to include/gp/utils/allocators/aggregator.hpp index 8edfd1c..4b4b4b6 100644 --- a/include/gp/allocator/aggregator.hpp +++ b/include/gp/utils/allocators/aggregator.hpp @@ -1,7 +1,7 @@ #pragma once -#include "gp/ring_list.hpp" -#include "gp/allocator/allocator.hpp" +#include "gp/containers/ring_list.hpp" +#include "gp/utils/allocators/allocator.hpp" #include diff --git a/include/gp/allocator/allocator.hpp b/include/gp/utils/allocators/allocator.hpp similarity index 100% rename from include/gp/allocator/allocator.hpp rename to include/gp/utils/allocators/allocator.hpp diff --git a/include/gp/allocator/arena.hpp b/include/gp/utils/allocators/arena.hpp similarity index 91% rename from include/gp/allocator/arena.hpp rename to include/gp/utils/allocators/arena.hpp index 2180c3c..a50b512 100644 --- a/include/gp/allocator/arena.hpp +++ b/include/gp/utils/allocators/arena.hpp @@ -2,11 +2,11 @@ #include "gp_config.hpp" -#include "gp/algorithm/min_max.hpp" -#include "gp/algorithm/tmp_manip.hpp" -#include "gp/buffer.hpp" -#include "gp/math/integer_math.hpp" -#include "gp/allocator/allocator.hpp" +#include "gp/algorithms/min_max.hpp" +#include "gp/algorithms/tmp_manip.hpp" +#include "gp/containers/buffer.hpp" +#include "gp/math/integral.hpp" +#include "gp/utils/allocators/allocator.hpp" #include diff --git a/include/gp/allocator/buddy.hpp b/include/gp/utils/allocators/buddy.hpp similarity index 97% rename from include/gp/allocator/buddy.hpp rename to include/gp/utils/allocators/buddy.hpp index f6f3a9f..ad447f9 100644 --- a/include/gp/allocator/buddy.hpp +++ b/include/gp/utils/allocators/buddy.hpp @@ -2,13 +2,13 @@ #include "gp_config.hpp" -#include "gp/algorithm/modifiers.hpp" -#include "gp/algorithm/tmp_manip.hpp" -#include "gp/allocator/dummy.hpp" -#include "gp/array.hpp" -#include "gp/buffer.hpp" -#include "gp/math/integer_math.hpp" -#include "gp/allocator/allocator.hpp" +#include "gp/algorithms/modifiers.hpp" +#include "gp/algorithms/tmp_manip.hpp" +#include "gp/utils/allocators/dummy.hpp" +#include "gp/containers/array.hpp" +#include "gp/containers/buffer.hpp" +#include "gp/math/integral.hpp" +#include "gp/utils/allocators/allocator.hpp" #include diff --git a/include/gp/allocator/dummy.hpp b/include/gp/utils/allocators/dummy.hpp similarity index 90% rename from include/gp/allocator/dummy.hpp rename to include/gp/utils/allocators/dummy.hpp index 1df7845..f311f45 100644 --- a/include/gp/allocator/dummy.hpp +++ b/include/gp/utils/allocators/dummy.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "gp/allocator/allocator.hpp" +#include "gp/utils/allocators/allocator.hpp" namespace gp { struct dummy_allocator : public allocator { diff --git a/include/gp/utils/iterator.hpp b/include/gp/utils/iterator.hpp new file mode 100644 index 0000000..2bc7c8e --- /dev/null +++ b/include/gp/utils/iterator.hpp @@ -0,0 +1,240 @@ +#pragma once + +#include +#include + +// BUG: none of this is in a namespace +// TODO: Specify the concept of an iterator + +namespace gp { + + /** + * @brief An enumeration that may be used to determine iterator categories + * + */ + enum class iterator_type_t{ + contiguous_iterator, /**< Defines an iterator for something that is continuous and random access */ + non_contiguous_iterator, /**< Defines an iterator for a non contiguous datastructure, for example an iterator over a hashmap or a tree*/ + lazy_iterator /**< Defines an iterator for which the actual data layout and availability are still unknown*/ + }; + + /** + * @brief An abstraction of a pointer to iterate against, in both normal and reverse order + * + * @tparam T The type of data pointed by the iterator + * @tparam sign the direction in which data is scrutinized, should be either 1 or -1, behaviour for other value is left undefined + */ + template + struct pointer_iterator final + { + T* data; /**< the only data field of the class */ + typedef T value_type; /**< The type of which a reference will be returned on dereferencing */ + typedef std::size_t difference_type; /**< The type of the substraction of two pointers */ + static constexpr iterator_type_t iterator_type = iterator_type_t::contiguous_iterator; /**< @see iterator_type_t */ + + /** + * @brief Generates an empty iterator + */ + constexpr pointer_iterator() + : data{nullptr} + {} + + constexpr pointer_iterator(const pointer_iterator& oth) + : data{oth.data} + {} + + /** + * @brief Generates an iterator from any pointer + */ + constexpr pointer_iterator(T* ptr) + : data{ptr} + {} + + /** + * @brief Dereference unary operator + * + * @return constexpr T& returns a reference to the pointed value + */ + constexpr T& operator*() const + { + return *data; + } + + constexpr pointer_iterator& operator++() + { + data += sign; + return *this; + } + + constexpr pointer_iterator operator++(int) + { + auto p = *this; + data += sign; + return p; + } + + constexpr pointer_iterator& operator--() + { + data -= sign; + return *this; + } + + constexpr pointer_iterator operator--(int) + { + auto p = *this; + data -= sign; + return p; + } + + constexpr pointer_iterator operator+(const std::size_t offset) const + { + return pointer_iterator{data+sign*offset}; + } + + constexpr pointer_iterator operator+(const int offset) const + { + return pointer_iterator{data+sign*offset}; + } + + constexpr pointer_iterator operator-(const std::size_t offset) const + { + return pointer_iterator{data-sign*offset}; + } + + constexpr pointer_iterator operator-(const int offset) const + { + return pointer_iterator{data-sign*offset}; + } + + constexpr difference_type operator-(const pointer_iterator& oth) const + { + return ((T*)data-(T*)oth.data)*sign; + } + + constexpr bool operator==(const pointer_iterator oth) const + { + return data==oth.data; + } + + constexpr bool operator!=(pointer_iterator oth) const + { + return data!=oth.data; + } + + constexpr bool before_or_equal(const pointer_iterator oth) const + { + return reinterpret_cast(data) <= reinterpret_cast(oth.data); + } + + constexpr bool operator<=(const pointer_iterator oth) const + { + return before_or_equal(oth); + } + }; + + /** + * @brief An identical twin to the pointer_iterator, but which dereference to a const reference + * + * @see pointer_iterator + * @tparam T @see pointer_iterator + * @tparam sign @see pointer_iterator + */ + template + struct const_pointer_iterator final + { + const T* data; /**< @see pointer_iterator */ + typedef T value_type; /**< @see pointer_iterator */ + typedef std::size_t difference_type; /**< @see pointer_iterator */ + static constexpr iterator_type_t iterator_type = iterator_type_t::contiguous_iterator; /**< @see pointer_iterator */ + + constexpr const_pointer_iterator(const const_pointer_iterator& oth) + : data{oth.data} + {} + + /** + * @brief @see pointer_iterator + */ + constexpr const_pointer_iterator(const T* ptr) + : data{ptr} + {} + + /** + * @brief Dereferencing returns a const version of what a pointer_iterator would return + */ + constexpr const T& operator*() const + { + return *data; + } + + constexpr const_pointer_iterator& operator++() + { + data += sign; + return *this; + } + + constexpr const_pointer_iterator operator++(int) + { + auto p = data; + data += sign; + return const_pointer_iterator{p}; + } + + constexpr const_pointer_iterator& operator--() + { + data -= sign; + return *this; + } + + constexpr const_pointer_iterator operator--(int) + { + auto p = data; + data -= sign; + return const_pointer_iterator{p}; + } + + constexpr const_pointer_iterator operator+(const std::size_t offset) const + { + return const_pointer_iterator{data+sign*offset}; + } + + constexpr const_pointer_iterator operator+(const int offset) const + { + return const_pointer_iterator{data+sign*offset}; + } + + constexpr const_pointer_iterator operator-(const std::size_t offset) const + { + return const_pointer_iterator{data-sign*offset}; + } + + constexpr const_pointer_iterator operator-(const int offset) + { + return const_pointer_iterator{data-sign*offset}; + } + + constexpr difference_type operator-(const const_pointer_iterator& oth) const + { + return ((T*)data-(T*)oth.data)*sign; + } + + constexpr bool operator==(const const_pointer_iterator oth) const + { + return data==oth.data; + } + + constexpr bool operator!=(const_pointer_iterator oth) const + { + return data!=oth.data; + } + + constexpr bool before_or_equal(const const_pointer_iterator oth) const + { + return reinterpret_cast(data) <= reinterpret_cast(oth.data); + } + + constexpr bool operator<=(const const_pointer_iterator oth) const + { + return before_or_equal(oth); + } + }; +} \ No newline at end of file diff --git a/include/gp/pair.hpp b/include/gp/utils/pair.hpp similarity index 98% rename from include/gp/pair.hpp rename to include/gp/utils/pair.hpp index 1cec317..96c5f71 100644 --- a/include/gp/pair.hpp +++ b/include/gp/utils/pair.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/algorithm/move.hpp" +#include "gp/algorithms/move.hpp" namespace gp{ template diff --git a/include/gp/pointers.hpp b/include/gp/utils/pointers.hpp similarity index 94% rename from include/gp/pointers.hpp rename to include/gp/utils/pointers.hpp index 1f7bba0..c6691b7 100644 --- a/include/gp/pointers.hpp +++ b/include/gp/utils/pointers.hpp @@ -1,9 +1,9 @@ #pragma once -#include "gp/algorithm/modifiers.hpp" -#include "gp/algorithm/move.hpp" -#include "gp/buffer.hpp" -#include "gp/function.hpp" +#include "gp/algorithms/modifiers.hpp" +#include "gp/algorithms/move.hpp" +#include "gp/containers/buffer.hpp" +#include "gp/functional/function.hpp" namespace gp { diff --git a/include/gp/range.hpp b/include/gp/utils/range.hpp similarity index 96% rename from include/gp/range.hpp rename to include/gp/utils/range.hpp index 42ceed1..1ced2e2 100644 --- a/include/gp/range.hpp +++ b/include/gp/utils/range.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gp/algorithm/tmp_manip.hpp" +#include "gp/algorithms/tmp_manip.hpp" namespace gp{ /*template diff --git a/tests/allocator.hpp b/tests/allocator.hpp index c13a415..d7a0ff6 100644 --- a/tests/allocator.hpp +++ b/tests/allocator.hpp @@ -1,7 +1,7 @@ #pragma once -#include "gp/allocator/buddy.hpp" -#include "gp/allocator/dummy.hpp" +#include "gp/utils/allocators/buddy.hpp" +#include "gp/utils/allocators/dummy.hpp" struct static_mapper { static gp::array store; diff --git a/tests/bloomfilter.cpp b/tests/bloomfilter.cpp index 9ce784b..e0cbad4 100644 --- a/tests/bloomfilter.cpp +++ b/tests/bloomfilter.cpp @@ -1,5 +1,5 @@ -#include "gp/algorithm/repeat.hpp" -#include "gp/bloomfilter.hpp" +#include "gp/algorithms/repeat.hpp" +#include "gp/containers/probabilistic/bloomfilter.hpp" #include "test_scaffold.h" #include diff --git a/tests/cbor_test.cpp b/tests/cbor_test.cpp index e3ed2c4..e313080 100644 --- a/tests/cbor_test.cpp +++ b/tests/cbor_test.cpp @@ -1,8 +1,8 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include "test_scaffold.h" struct cbor_test : public test_scaffold { diff --git a/tests/channel_test.cpp b/tests/channel_test.cpp index a63be1f..e519634 100644 --- a/tests/channel_test.cpp +++ b/tests/channel_test.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "test_scaffold.h" #include diff --git a/tests/gp_test.cpp b/tests/gp_test.cpp index bc676b5..57a8473 100644 --- a/tests/gp_test.cpp +++ b/tests/gp_test.cpp @@ -1,15 +1,15 @@ #include "allocator.hpp" -#include "gp/algorithm/repeat.hpp" -#include "gp/algorithm/rotate.hpp" -#include "gp/algorithm/move.hpp" -#include "gp/allocator/aggregator.hpp" -#include "gp/allocator/arena.hpp" -#include "gp/allocator/buddy.hpp" -#include "gp/allocator/dummy.hpp" -#include "gp/array.hpp" -#include "gp/bitops.hpp" -#include "gp/indexed_array.hpp" -#include "gp/ring_list.hpp" +#include "gp/algorithms/repeat.hpp" +#include "gp/algorithms/rotate.hpp" +#include "gp/algorithms/move.hpp" +#include "gp/utils/allocators/aggregator.hpp" +#include "gp/utils/allocators/arena.hpp" +#include "gp/utils/allocators/buddy.hpp" +#include "gp/utils/allocators/dummy.hpp" +#include "gp/containers/array.hpp" +#include "gp/math/boolean/bitops.hpp" +#include "gp/containers/indexed_array.hpp" +#include "gp/containers/ring_list.hpp" #include "test_scaffold.h" #include diff --git a/tests/math.cpp b/tests/math.cpp index 01410c2..57a7a18 100644 --- a/tests/math.cpp +++ b/tests/math.cpp @@ -1,8 +1,8 @@ #include "test_scaffold.h" -#include "gp/array.hpp" +#include "gp/containers/array.hpp" #include "gp/math.hpp" -#include "gp/rendering/renderer.hpp" -#include "gp/rendering/bmp_viewport.hpp" +#include "gp/math/rendering/renderer.hpp" +#include "gp/math/rendering/bmp_viewport.hpp" #include #include @@ -20,17 +20,17 @@ struct sin_test : public test_scaffold { virtual int run() { int res = 0; for(float i = 0; i < 100; i += 0.1) { - float v = gp::sin(i); + float v = gp::math::sin(i); float ref = sin(i); - res += 0.3 < gp::abs(ref - v)*100.0/(gp::abs(ref+0.00000001)); + res += 0.3 < gp::math::abs(ref - v)*100.0/(gp::math::abs(ref+0.00000001)); } for(float i = 0; i < 100; i += 0.1) { - float v = gp::cos(i); + float v = gp::math::cos(i); float ref = cos(i); - res += 0.3 < gp::abs(ref - v)*100.0/(gp::abs(ref+0.00000001)); + res += 0.3 < gp::math::abs(ref - v)*100.0/(gp::math::abs(ref+0.00000001)); } for(float i = 0; i < 100; i += 0.1) { - float v = gp::cos(i)*gp::cos(i) + gp::sin(i)*gp::sin(i); + float v = gp::math::cos(i)*gp::math::cos(i) + gp::math::sin(i)*gp::math::sin(i); res += 1 + gp_config::rendering::epsilon < v; res += 1 - gp_config::rendering::epsilon > v; } @@ -85,11 +85,11 @@ struct render_test : public test_scaffold { }, a.get_allocator()) ); - auto sphere = a.scene_elements.push( + volatile auto sphere = a.scene_elements.push( sdf_t([&](vec3 pos) -> render_point { - auto l_sdf = gp::difference_sdf( - gp::sphere_sdf({0.0,0.0,0.0}, 1.0), - gp::sphere_sdf({-0.75,0.0,0.0}, 1.0) + auto l_sdf = gp::math::difference_sdf( + gp::math::sphere_sdf({0.0,0.0,0.0}, 1.0), + gp::math::sphere_sdf({-0.75,0.0,0.0}, 1.0) ); render_point ret; ret.distance = l_sdf(pos); @@ -98,9 +98,9 @@ struct render_test : public test_scaffold { }, a.get_allocator()) ); - auto sphere2 = a.scene_elements.push( + volatile auto sphere2 = a.scene_elements.push( sdf_t([&](vec3 pos) -> render_point { - auto l_sdf_b = gp::sphere_sdf({-0.75,0.0,0.0}, 1.0); + auto l_sdf_b = gp::math::sphere_sdf({-0.75,0.0,0.0}, 1.0); render_point ret; ret.distance = l_sdf_b(pos); ret.material = green; @@ -111,12 +111,12 @@ struct render_test : public test_scaffold { a._camera.position = vec3{0, 0, -2}; a._camera.normal = vec3{0, 0, 1}; - using pic_color = gp::vec4_g; + using pic_color = gp::math::vec4_g; using viewport = gp::bmp_viewport; viewport vp{ {128,64}, - viewport::src_t{[&](gp::vec2_g p) -> pic_color { + viewport::src_t{[&](gp::math::vec2_g p) -> pic_color { auto orig = a.render({(float)p.x,(float)p.y}); pic_color ret{}; ret.x = (uint8_t)(orig.x*255); @@ -164,7 +164,7 @@ struct function_test : public test_scaffold { gp::array allocation_buffer; gp::buddy<> allocator{allocation_buffer.begin().data, allocation_buffer.size()}; - gp::function l_sdf_b{gp::sphere_sdf({0.0,0.0,0.0}, 1.0), allocator}; + gp::function l_sdf_b{gp::math::sphere_sdf({0.0,0.0,0.0}, 1.0), allocator}; { gp::function sdf{l_sdf_b}; diff --git a/tests/pair_test.cpp b/tests/pair_test.cpp index 45d30d4..c3f4bf0 100644 --- a/tests/pair_test.cpp +++ b/tests/pair_test.cpp @@ -1,4 +1,4 @@ -#include "gp/pair.hpp" +#include "gp/utils/pair.hpp" #include "test_scaffold.h" #include diff --git a/tests/quotient_filter.cpp b/tests/quotient_filter.cpp index fd0ea09..54b75c2 100644 --- a/tests/quotient_filter.cpp +++ b/tests/quotient_filter.cpp @@ -1,4 +1,4 @@ -#include "gp/quotient_filter.hpp" +#include "gp/containers/probabilistic/quotient_filter.hpp" #include "test_scaffold.h" #include