Browse Source

The_Birth_of_a_Legend.mp3 Epic renaming

channel
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
654795d7ec
73 changed files with 1087 additions and 1123 deletions
  1. +1
    -1
      .vscode/settings.json
  2. +2
    -2
      Makefile
  3. +2
    -2
      blacklist.txt
  4. +0
    -0
      include/gp/algorithms/cvref.hpp
  5. +0
    -0
      include/gp/algorithms/foreach.hpp
  6. +0
    -0
      include/gp/algorithms/min_max.hpp
  7. +1
    -1
      include/gp/algorithms/min_of.hpp
  8. +3
    -3
      include/gp/algorithms/modifiers.hpp
  9. +3
    -3
      include/gp/algorithms/move.hpp
  10. +2
    -2
      include/gp/algorithms/reference.hpp
  11. +0
    -0
      include/gp/algorithms/repeat.hpp
  12. +1
    -1
      include/gp/algorithms/rotate.hpp
  13. +1
    -1
      include/gp/algorithms/tmp_manip.hpp
  14. +1
    -1
      include/gp/containers/array.hpp
  15. +4
    -4
      include/gp/containers/buffer.hpp
  16. +1
    -1
      include/gp/containers/flat_tree.hpp
  17. +9
    -3
      include/gp/containers/indexed_array.hpp
  18. +3
    -3
      include/gp/containers/probabilistic/bloomfilter.hpp
  19. +3
    -3
      include/gp/containers/probabilistic/quotient_filter.hpp
  20. +4
    -4
      include/gp/containers/ring_list.hpp
  21. +2
    -2
      include/gp/containers/vector.hpp
  22. +5
    -5
      include/gp/functional/function.hpp
  23. +2
    -2
      include/gp/functional/optional.hpp
  24. +4
    -5
      include/gp/functional/variant.hpp
  25. +6
    -6
      include/gp/ipc/enveloppe/cbor.hpp
  26. +0
    -0
      include/gp/ipc/file_description.hpp
  27. +3
    -3
      include/gp/ipc/filesystem.hpp
  28. +0
    -0
      include/gp/ipc/io/io_future.hpp
  29. +1
    -1
      include/gp/ipc/io/io_operation.hpp
  30. +0
    -237
      include/gp/iterator.hpp
  31. +6
    -347
      include/gp/math.hpp
  32. +0
    -0
      include/gp/math/boolean/bitops.hpp
  33. +35
    -0
      include/gp/math/details/math_definitions.hpp
  34. +0
    -267
      include/gp/math/fp_math.hpp
  35. +68
    -0
      include/gp/math/general_purpose.hpp
  36. +3
    -0
      include/gp/math/ieee754.hpp
  37. +255
    -0
      include/gp/math/ieee754/fp_math.hpp
  38. +3
    -0
      include/gp/math/integral.hpp
  39. +6
    -10
      include/gp/math/integral/logarithms.hpp
  40. +0
    -0
      include/gp/math/q_n.hpp
  41. +3
    -0
      include/gp/math/q_n/q_math.hpp
  42. +10
    -12
      include/gp/math/rendering/bmp_viewport.hpp
  43. +1
    -1
      include/gp/math/rendering/characters.hpp
  44. +13
    -12
      include/gp/math/rendering/renderer.hpp
  45. +290
    -0
      include/gp/math/rendering_math.hpp
  46. +0
    -64
      include/gp/memory.hpp
  47. +0
    -0
      include/gp/runtime.hpp
  48. +0
    -29
      include/gp/subtree_iterator.hpp
  49. +1
    -1
      include/gp/system/platforms/gcc-x86_64.hpp
  50. +1
    -1
      include/gp/system/platforms/platform_autopicker.hpp
  51. +5
    -5
      include/gp/system/process_data.hpp
  52. +1
    -1
      include/gp/system/runqueue.hpp
  53. +3
    -3
      include/gp/system/scheduler.hpp
  54. +1
    -1
      include/gp/system/scheduling/simple_scheduling.hpp
  55. +8
    -8
      include/gp/system/system.hpp
  56. +5
    -0
      include/gp/utils/allocators.hpp
  57. +2
    -2
      include/gp/utils/allocators/aggregator.hpp
  58. +0
    -0
      include/gp/utils/allocators/allocator.hpp
  59. +5
    -5
      include/gp/utils/allocators/arena.hpp
  60. +7
    -7
      include/gp/utils/allocators/buddy.hpp
  61. +1
    -1
      include/gp/utils/allocators/dummy.hpp
  62. +240
    -0
      include/gp/utils/iterator.hpp
  63. +1
    -1
      include/gp/utils/pair.hpp
  64. +4
    -4
      include/gp/utils/pointers.hpp
  65. +1
    -1
      include/gp/utils/range.hpp
  66. +2
    -2
      tests/allocator.hpp
  67. +2
    -2
      tests/bloomfilter.cpp
  68. +4
    -4
      tests/cbor_test.cpp
  69. +6
    -6
      tests/channel_test.cpp
  70. +11
    -11
      tests/gp_test.cpp
  71. +17
    -17
      tests/math.cpp
  72. +1
    -1
      tests/pair_test.cpp
  73. +1
    -1
      tests/quotient_filter.cpp

+ 1
- 1
.vscode/settings.json View File

@ -4,7 +4,7 @@
"-I${workspaceRoot}/include"
],
"clang.cxxflags": [
"-std=c++20",
"-std=c++2a",
"-Wall",
"-pedantic",
"-I${workspaceRoot}/include"

+ 2
- 2
Makefile View File

@ -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)

+ 2
- 2
blacklist.txt View File

@ -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*)

include/gp/algorithm/cvref.hpp → include/gp/algorithms/cvref.hpp View File


include/gp/algorithm/foreach.hpp → include/gp/algorithms/foreach.hpp View File


include/gp/algorithm/min_max.hpp → include/gp/algorithms/min_max.hpp View File


include/gp/algorithm/min_of.hpp → include/gp/algorithms/min_of.hpp View File

@ -2,7 +2,7 @@
#include "gp_config.hpp"
#include "gp/algorithm/move.hpp"
#include "gp/algorithms/move.hpp"
namespace gp{

include/gp/algorithm/modifiers.hpp → include/gp/algorithms/modifiers.hpp View File

@ -1,8 +1,8 @@
#pragma once
#include <gp/algorithm/move.hpp>
#include <gp/algorithm/cvref.hpp>
#include <gp/algorithm/reference.hpp>
#include <gp/algorithms/move.hpp>
#include <gp/algorithms/cvref.hpp>
#include <gp/algorithms/reference.hpp>
#include <type_traits>

include/gp/algorithm/move.hpp → include/gp/algorithms/move.hpp View File

@ -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<typename T>

include/gp/algorithm/reference.hpp → include/gp/algorithms/reference.hpp View File

@ -1,7 +1,7 @@
#pragma once
#include <gp/algorithm/move.hpp>
#include <gp/algorithm/cvref.hpp>
#include <gp/algorithms/move.hpp>
#include <gp/algorithms/cvref.hpp>
namespace gp{

include/gp/algorithm/repeat.hpp → include/gp/algorithms/repeat.hpp View File


include/gp/algorithm/rotate.hpp → include/gp/algorithms/rotate.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/algorithm/move.hpp"
#include "gp/algorithms/move.hpp"
namespace gp {
template<typename iterator>

include/gp/algorithm/tmp_manip.hpp → include/gp/algorithms/tmp_manip.hpp View File

@ -4,7 +4,7 @@
#include <typeinfo>
#include <cstddef>
#include <limits>
#include "gp/algorithm/min_max.hpp"
#include "gp/algorithms/min_max.hpp"
namespace gp{

include/gp/array.hpp → include/gp/containers/array.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include <gp/buffer.hpp>
#include <gp/containers/buffer.hpp>
#include <initializer_list>

include/gp/buffer.hpp → include/gp/containers/buffer.hpp View File

@ -1,10 +1,10 @@
#pragma once
#include <gp/algorithm/move.hpp>
#include <gp/function.hpp>
#include <gp/algorithms/move.hpp>
#include <gp/functional/function.hpp>
#include <gp/exception.hpp>
#include <gp/iterator.hpp>
#include <gp/optional.hpp>
#include <gp/utils/iterator.hpp>
#include <gp/functional/optional.hpp>
#include <cstddef>
#include <cstdint>

include/gp/flat_tree.hpp → include/gp/containers/flat_tree.hpp View File

@ -1,6 +1,6 @@
#pragma one
#include <gp/array.hpp>
#include <gp/containers/array.hpp>
#include <gp/integer_math.hpp>
#include <gp/iterator.hpp>
// UNIMPLEMENTED: see filename

include/gp/indexed_array.hpp → include/gp/containers/indexed_array.hpp View File

@ -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 <stddef.h>
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<typename T, size_t _capacity>
class indexed_array{
size_t data_top = 0;

include/gp/bloomfilter.hpp → include/gp/containers/probabilistic/bloomfilter.hpp View File

@ -1,8 +1,8 @@
#pragma once
#include <gp/algorithm/foreach.hpp>
#include <gp/algorithm/tmp_manip.hpp>
#include <gp/array.hpp>
#include <gp/algorithms/foreach.hpp>
#include <gp/algorithms/tmp_manip.hpp>
#include <gp/containers/array.hpp>
#include <atomic>

include/gp/quotient_filter.hpp → include/gp/containers/probabilistic/quotient_filter.hpp View File

@ -1,8 +1,8 @@
#pragma once
#include <gp/algorithm/foreach.hpp>
#include <gp/algorithm/tmp_manip.hpp>
#include <gp/array.hpp>
#include <gp/algorithms/foreach.hpp>
#include <gp/algorithms/tmp_manip.hpp>
#include <gp/containers/array.hpp>
#include <gp/exception.hpp>
#include <atomic>

include/gp/ring_list.hpp → include/gp/containers/ring_list.hpp View File

@ -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 <stddef.h>

include/gp/vector.hpp → include/gp/containers/vector.hpp View File

@ -1,7 +1,7 @@
#pragma once
#include <gp/buffer.hpp>
#include <gp/allocator/allocator.hpp>
#include <gp/containers/buffer.hpp>
#include <gp/utils/allocators/allocator.hpp>
#include <initializer_list>

include/gp/function.hpp → include/gp/functional/function.hpp View File

@ -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{

include/gp/optional.hpp → include/gp/functional/optional.hpp View File

@ -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 <type_traits>

include/gp/variant.hpp → include/gp/functional/variant.hpp View File

@ -2,12 +2,11 @@
#include "gp_config.hpp"
#include <gp/algorithm/move.hpp>
#include <gp/algorithm/tmp_manip.hpp>
#include "gp/allocator/dummy.hpp"
#include <gp/algorithms/move.hpp>
#include <gp/algorithms/tmp_manip.hpp>
#include "gp/utils/allocators/dummy.hpp"
#include "gp/exception.hpp"
#include "gp/function.hpp"
#include "gp/memory.hpp"
#include "gp/functional/function.hpp"
#include <type_traits>
#include <new>

include/gp/enveloppe/cbor.hpp → include/gp/ipc/enveloppe/cbor.hpp View File

@ -1,11 +1,11 @@
#pragma once
#include <gp/algorithm/repeat.hpp>
#include <gp/bitops.hpp>
#include <gp/optional.hpp>
#include <gp/pair.hpp>
#include <gp/variant.hpp>
#include <gp/vector.hpp>
#include <gp/algorithms/repeat.hpp>
#include <gp/math/boolean/bitops.hpp>
#include <gp/functional/optional.hpp>
#include <gp/utils/pair.hpp>
#include <gp/functional/variant.hpp>
#include <gp/containers/vector.hpp>
namespace gp {

include/gp/vfs/file_description.hpp → include/gp/ipc/file_description.hpp View File


include/gp/vfs/filesystem.hpp → include/gp/ipc/filesystem.hpp View File

@ -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{

include/gp/vfs/io/io_future.hpp → include/gp/ipc/io/io_future.hpp View File


include/gp/vfs/io/io_operation.hpp → include/gp/ipc/io/io_operation.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/array.hpp"
#include "gp/containers/array.hpp"
#include <cstddef>
#include <cstdint>

+ 0
- 237
include/gp/iterator.hpp View File

@ -1,237 +0,0 @@
#pragma once
#include <cstddef>
#include <cstdint>
// 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<typename T, int sign = 1>
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<std::intptr_t>(data) <= reinterpret_cast<std::intptr_t>(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<typename T, int sign = 1>
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<std::intptr_t>(data) <= reinterpret_cast<std::intptr_t>(oth.data);
}
constexpr bool operator<=(const const_pointer_iterator oth) const
{
return before_or_equal(oth);
}
};

+ 6
- 347
include/gp/math.hpp View File

@ -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<typename T>
T lerp(T input, T low, T high) {
return low + (high - low) * input;
}
template<typename T>
T lextrap(T input, T low, T high) {
return (input - low) / (high - low);
}
template<typename T, size_t fixed_passes = 16>
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<typename T, size_t cap_passes = 16>
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<typename T, size_t cap_passes = 16>
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<typename T = gp_config::rendering::default_type>
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<typename T = gp_config::rendering::default_type>
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<T> left, T right)
: x{left.x}
, y{left.y}
, z{right}
{}
vec3_g(T left, vec2_g<T> 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<typename T = gp_config::rendering::default_type>
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<typename T>
auto sphere_sdf(vec3_g<T> center, T radius) {
return [=](vec3_g<T> position) -> T const {
auto p = position - center;
return p.length() - radius;
};
}
template<typename T, typename lhs, typename rhs>
auto union_sdf(lhs _l, rhs _r) {
return [=](vec3_g<T> position) -> T const {
return gp::min(_l(position), _r(position));
};
}
template<typename T, typename lhs, typename rhs>
auto intersect_sdf(lhs _l, rhs _r) {
return [=](vec3_g<T> position) -> T const {
return gp::max(_l(position), _r(position));
};
}
template<typename T, typename lhs, typename rhs>
auto difference_sdf(lhs _l, rhs _r) {
return [=](vec3_g<T> position) -> T const {
return gp::max(_l(position), -_r(position));
};
}
template<typename T>
vec2_g<T> operator*(vec2_g<T> p, T v) {
return {p.x*v, p.y*v};
}
template<typename T>
vec3_g<T> operator*(vec3_g<T> p, T v) {
return {p.x*v, p.y*v, p.z*v};
}
template<typename T>
vec4_g<T> operator*(vec4_g<T> p, T v) {
return {p.x*v, p.y*v, p.z*v, p.w*v};
}
template<typename T>
vec2_g<T> operator*(T v, vec2_g<T> p) {
return p*v;
}
template<typename T>
vec3_g<T> operator*(T v, vec3_g<T> p) {
return p*v;
}
template<typename T>
vec4_g<T> operator*(T v, vec4_g<T> p) {
return p*v;
}
}
static_assert(sizeof(gp::vec3_g<int>) == sizeof(int)*3, "vec3_g has strange alignment");
static_assert(sizeof(gp::vec4_g<int>) == sizeof(int)*4, "vec4_g has strange alignment");
#include "gp/math/q_n.hpp"
#include "gp/math/general_purpose.hpp"

include/gp/bitops.hpp → include/gp/math/boolean/bitops.hpp View File


+ 35
- 0
include/gp/math/details/math_definitions.hpp View File

@ -0,0 +1,35 @@
#pragma once
namespace gp {
namespace math {
template<typename T>
constexpr T pi;
template<typename T>
T abs(T);
template<typename word_t>
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<typename word_t>
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<typename T>
T sign(T);
}
}

+ 0
- 267
include/gp/math/fp_math.hpp View File

@ -1,267 +0,0 @@
#pragma once
#include "gp/algorithm/repeat.hpp"
#include <limits>
#include <stddef.h>
#include <stdint.h>
namespace gp{
template<typename T>
constexpr T pi;
template<>
constexpr float pi<float> = 3.1415926535897932384626433832795028841971693993751058209749445923078164062;
template<>
constexpr double pi<double> = 3.1415926535897932384626433832795028841971693993751058209749445923078164062L;
template<typename T>
T abs(T);
template<>
float abs<float>(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>(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<typename T>
T floor(T);
template<>
float floor<float>(float value) {
static_assert(sizeof(float) == 4, "bad float size");
if(
value >= 16777216
|| value <= std::numeric_limits<int32_t>::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>(double value) {
static_assert(sizeof(double) == 8, "bad double size");
if(
value >= 9007199254740992
|| value <= std::numeric_limits<int64_t>::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<typename T>
T sign(T);
template<>
float sign<float>(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>(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<size_t steps, typename T, size_t accuracy = 1000000>
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<float>;
v = v - 2*pi<float>*floor(v/(2*pi<float>));
v -= pi<float>;
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<double>;
v = v - 2*pi<double>*floor(v/(2*pi<double>));
v -= pi<double>;
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<float>/2);
}
// TODO: replace with an actual implementation
double cos(double v) {
return sin(v+pi<double>/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<size_t cycles = 5>
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<size_t cycles = 5>
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);}
}

+ 68
- 0
include/gp/math/general_purpose.hpp View File

@ -0,0 +1,68 @@
#pragma once
#include "gp_config.hpp"
#include "gp/algorithms/repeat.hpp"
namespace gp {
template<typename T>
T lerp(T input, T low, T high) {
return low + (high - low) * input;
}
template<typename T>
T lextrap(T input, T low, T high) {
return (input - low) / (high - low);
}
template<typename T, size_t fixed_passes = 16>
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<typename T, size_t cap_passes = 16>
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<typename T, size_t cap_passes = 16>
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;
}
}

+ 3
- 0
include/gp/math/ieee754.hpp View File

@ -0,0 +1,3 @@
#pragma once
#include "gp/math/ieee754/fp_math.hpp"

+ 255
- 0
include/gp/math/ieee754/fp_math.hpp View File

@ -0,0 +1,255 @@
#pragma once
#include "gp/algorithms/repeat.hpp"
#include "gp/math/details/math_definitions.hpp"
#include <limits>
#include <stddef.h>
#include <stdint.h>
namespace gp{
namespace math{
template<>
constexpr float pi<float> = 3.1415926535897932384626433832795028841971693993751058209749445923078164062;
template<>
constexpr double pi<double> = 3.1415926535897932384626433832795028841971693993751058209749445923078164062L;
template<>
float abs<float>(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>(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<typename T>
T floor(T);
template<>
float floor<float>(float value) {
static_assert(sizeof(float) == 4, "bad float size");
if(
value >= 16777216
|| value <= std::numeric_limits<int32_t>::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>(double value) {
static_assert(sizeof(double) == 8, "bad double size");
if(
value >= 9007199254740992
|| value <= std::numeric_limits<int64_t>::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>(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>(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<size_t steps, typename T, size_t accuracy = 1000000>
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<float>;
v = v - 2*pi<float>*floor(v/(2*pi<float>));
v -= pi<float>;
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<double>;
v = v - 2*pi<double>*floor(v/(2*pi<double>));
v -= pi<double>;
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<float>/2);
}
// TODO: replace with an actual implementation
inline double cos(double v) {
return sin(v+pi<double>/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<size_t cycles = 5>
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<size_t cycles = 5>
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);}
}
}

+ 3
- 0
include/gp/math/integral.hpp View File

@ -0,0 +1,3 @@
#pragma once
#include "gp/math/integral/logarithms.hpp"

include/gp/math/integer_math.hpp → include/gp/math/integral/logarithms.hpp View File

@ -1,20 +1,19 @@
#pragma once
#include "gp/math/details/math_definitions.hpp"
#include <stdint.h>
#include <stddef.h>
namespace gp {
namespace math {
template<typename word_t>
size_t log2(word_t v);
/**
Sean Eron Anderson
seander@cs.stanford.edu
**/
template<>
constexpr n">size_t log2<uint32_t>(uint32_t v)
constexpr kt">uint32_t log2<uint32_t>(uint32_t v)
{
constexpr int MultiplyDeBruijnBitPosition[32] =
{
@ -32,7 +31,7 @@ namespace gp {
}
template<>
constexpr n">size_t log2<uint64_t>(uint64_t v)
constexpr kt">uint64_t log2<uint64_t>(uint64_t v)
{
constexpr int MultiplyDeBruijnBitPosition[64] =
{
@ -55,17 +54,14 @@ namespace gp {
static_assert(log2<uint32_t>(7) == 2, "bad log2");
static_assert(log2<uint32_t>(8) == 3, "bad log2");
template<typename word_t>
constexpr size_t msb(word_t v);
template<>
constexpr n">size_t msb<uint32_t>(uint32_t v)
constexpr uint32_t msb<uint32_t>(uint32_t v)
{
auto l = log2(v);
return l + (((1 << l) ^ v) != 0);
}
template<>
constexpr n">size_t msb<uint64_t>(uint64_t v)
constexpr kt">uint64_t msb<uint64_t>(uint64_t v)
{
auto l = log2(v);
return l + (((1 << l) ^ v) != 0);

include/gp/math/q_math.hpp → include/gp/math/q_n.hpp View File


+ 3
- 0
include/gp/math/q_n/q_math.hpp View File

@ -0,0 +1,3 @@
#pragma once
// UNIMPLEMENTED

include/gp/rendering/bmp_viewport.hpp → include/gp/math/rendering/bmp_viewport.hpp View File

@ -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 <iostream>
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<uint8_t> is supported
* @tparam color_type the type that represents the color. as of now only gp::math::vec4_g<uint8_t> is supported
*/
template<bool lazy, typename color_type>
class bmp_viewport {
@ -23,12 +21,12 @@ namespace gp{
* @brief The type of data source expected
*/
using src_t = typename gp::either<lazy,
gp::function<color_type(gp::vec2_g<int32_t>)>,
gp::function<color_type(gp::math::vec2_g<int32_t>)>,
gp::buffer<gp::buffer<color_type>>
>::type;
private:
src_t source;
gp::vec2_g<int32_t> resolution;
gp::math::vec2_g<int32_t> 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<int32_t> res, src_t src)
bmp_viewport(gp::math::vec2_g<int32_t> 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<color_type, gp::vec4_g<uint8_t>>::value)
if constexpr (std::is_same<color_type, gp::math::vec4_g<uint8_t>>::value)
{
auto color = get(row, line);
*(it++) = color.b();

include/gp/rendering/characters.hpp → include/gp/math/rendering/characters.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/array.hpp"
#include "gp/containers/array.hpp"
using display_char = gp::array<uint8_t, 8>;

include/gp/rendering/renderer.hpp → include/gp/math/rendering/renderer.hpp View File

@ -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<g_t>,gp::pi<g_t>};
pixel = pixel / vec2{180, 180} * vec2{gp::math::pi<g_t>,gp::math::pi<g_t>};
// 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};

+ 290
- 0
include/gp/math/rendering_math.hpp View File

@ -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<typename T = gp_config::rendering::default_type>
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<typename T = gp_config::rendering::default_type>
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<T> left, T right)
: x{left.x}
, y{left.y}
, z{right}
{}
vec3_g(T left, vec2_g<T> 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<typename T = gp_config::rendering::default_type>
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<typename T>
auto sphere_sdf(vec3_g<T> center, T radius) {
return [=](vec3_g<T> position) -> T const {
auto p = position - center;
return p.length() - radius;
};
}
template<typename T, typename lhs, typename rhs>
auto union_sdf(lhs _l, rhs _r) {
return [=](vec3_g<T> position) -> T const {
return gp::min(_l(position), _r(position));
};
}
template<typename T, typename lhs, typename rhs>
auto intersect_sdf(lhs _l, rhs _r) {
return [=](vec3_g<T> position) -> T const {
return gp::max(_l(position), _r(position));
};
}
template<typename T, typename lhs, typename rhs>
auto difference_sdf(lhs _l, rhs _r) {
return [=](vec3_g<T> position) -> T const {
return gp::max(_l(position), -_r(position));
};
}
template<typename T>
vec2_g<T> operator*(vec2_g<T> p, T v) {
return {p.x*v, p.y*v};
}
template<typename T>
vec3_g<T> operator*(vec3_g<T> p, T v) {
return {p.x*v, p.y*v, p.z*v};
}
template<typename T>
vec4_g<T> operator*(vec4_g<T> p, T v) {
return {p.x*v, p.y*v, p.z*v, p.w*v};
}
template<typename T>
vec2_g<T> operator*(T v, vec2_g<T> p) {
return p*v;
}
template<typename T>
vec3_g<T> operator*(T v, vec3_g<T> p) {
return p*v;
}
template<typename T>
vec4_g<T> operator*(T v, vec4_g<T> p) {
return p*v;
}
}
}
static_assert(sizeof(gp::math::vec3_g<int>) == sizeof(int)*3, "vec3_g has strange alignment");
static_assert(sizeof(gp::math::vec4_g<int>) == sizeof(int)*4, "vec4_g has strange alignment");

+ 0
- 64
include/gp/memory.hpp View File

@ -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 <type_traits>
// XXX: THIS FILE SHOULD BE REMOVED, AS SHOULD ALL DEPENDENCIES ON THE C-ALLOCATOR AS IS
/*
namespace gp{
template<class T, typename I = std::enable_if_t<gp_config::memory_module::is_ok,int>>
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 <pointer_type> (gp_config::memory_module::memory_allocator<gp_config::memory_module::memory_mode>(sizeof(T) * sz));
}
void deallocate(pointer_type ptr)
{
gp_config::memory_module::memory_deallocator<gp_config::memory_module::memory_mode>(ptr);
}
template<typename ...params>
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<gp_config::memory_module::memory_mode>(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<gp_config::memory_module::memory_mode>(ptr);
}
*/

+ 0
- 0
include/gp/runtime.hpp View File


+ 0
- 29
include/gp/subtree_iterator.hpp View File

@ -1,29 +0,0 @@
#pragma once
#include <gp/buffer.hpp>
#include <stddef.h>
#include <stdint.h>
// UNIMPLEMENTED: see filename
template<typename T>
struct subtree_iterator final
{
gp::buffer<T> target;
size_t idx;
public:
subtree_iterator()
: target{}
, idx{0}
{}
subtree_iterator(gp::buffer<T> data, size_t itr_idx)
: target{data}
, idx{itr_idx}
{}
template<typename func>
void climb_traversal(func& traverser) {
}
};

include/gp/vfs/platforms/gcc-x86_64.hpp → include/gp/system/platforms/gcc-x86_64.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/buffer.hpp"
#include "gp/containers/buffer.hpp"
#include <cstdint>

include/gp/vfs/platforms/platform_autopicker.hpp → include/gp/system/platforms/platform_autopicker.hpp View File

@ -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__

include/gp/vfs/process_data.hpp → include/gp/system/process_data.hpp View File

@ -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 <atomic>

include/gp/vfs/runqueue.hpp → include/gp/system/runqueue.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/vfs/process_data.hpp"
#include "gp/system/process_data.hpp"
#include <atomic>
#include <new>

include/gp/vfs/scheduler.hpp → include/gp/system/scheduler.hpp View File

@ -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{

include/gp/vfs/scheduling/simple_scheduling.hpp → include/gp/system/scheduling/simple_scheduling.hpp View File

@ -1,5 +1,5 @@
#pragma once
#include "gp/vfs/system.hpp"
#include "gp/system/system.hpp"
namespace gp{

include/gp/vfs/system.hpp → include/gp/system/system.hpp View File

@ -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{

+ 5
- 0
include/gp/utils/allocators.hpp View File

@ -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"

include/gp/allocator/aggregator.hpp → include/gp/utils/allocators/aggregator.hpp View File

@ -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 <stddef.h>

include/gp/allocator/allocator.hpp → include/gp/utils/allocators/allocator.hpp View File


include/gp/allocator/arena.hpp → include/gp/utils/allocators/arena.hpp View File

@ -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 <type_traits>

include/gp/allocator/buddy.hpp → include/gp/utils/allocators/buddy.hpp View File

@ -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 <type_traits>

include/gp/allocator/dummy.hpp → include/gp/utils/allocators/dummy.hpp View File

@ -1,7 +1,7 @@
#pragma once
#include <stddef.h>
#include "gp/allocator/allocator.hpp"
#include "gp/utils/allocators/allocator.hpp"
namespace gp {
struct dummy_allocator : public allocator {

+ 240
- 0
include/gp/utils/iterator.hpp View File

@ -0,0 +1,240 @@
#pragma once
#include <cstddef>
#include <cstdint>
// 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<typename T, int sign = 1>
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<std::intptr_t>(data) <= reinterpret_cast<std::intptr_t>(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<typename T, int sign = 1>
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<std::intptr_t>(data) <= reinterpret_cast<std::intptr_t>(oth.data);
}
constexpr bool operator<=(const const_pointer_iterator oth) const
{
return before_or_equal(oth);
}
};
}

include/gp/pair.hpp → include/gp/utils/pair.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/algorithm/move.hpp"
#include "gp/algorithms/move.hpp"
namespace gp{
template<typename T1, typename T2>

include/gp/pointers.hpp → include/gp/utils/pointers.hpp View File

@ -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 {

include/gp/range.hpp → include/gp/utils/range.hpp View File

@ -1,6 +1,6 @@
#pragma once
#include "gp/algorithm/tmp_manip.hpp"
#include "gp/algorithms/tmp_manip.hpp"
namespace gp{
/*template<typename T>

+ 2
- 2
tests/allocator.hpp View File

@ -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<char, 4096> store;

+ 2
- 2
tests/bloomfilter.cpp View File

@ -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 <random>

+ 4
- 4
tests/cbor_test.cpp View File

@ -1,8 +1,8 @@
#include <gp/algorithm/foreach.hpp>
#include <gp/allocator/arena.hpp>
#include <gp/array.hpp>
#include <gp/enveloppe/cbor.hpp>
#include <gp/algorithms/foreach.hpp>
#include <gp/utils/allocators/arena.hpp>
#include <gp/containers/array.hpp>
#include <gp/ipc/enveloppe/cbor.hpp>
#include "test_scaffold.h"
struct cbor_test : public test_scaffold {

+ 6
- 6
tests/channel_test.cpp View File

@ -1,10 +1,10 @@
#include <gp/algorithm/foreach.hpp>
#include <gp/allocator/buddy.hpp>
#include <gp/array.hpp>
#include <gp/enveloppe/cbor.hpp>
#include <gp/vfs/system.hpp>
#include <gp/vfs/scheduling/simple_scheduling.hpp>
#include <gp/algorithms/foreach.hpp>
#include <gp/utils/allocators/buddy.hpp>
#include <gp/containers/array.hpp>
#include <gp/ipc/enveloppe/cbor.hpp>
#include <gp/system/system.hpp>
#include <gp/system/scheduling/simple_scheduling.hpp>
#include "test_scaffold.h"
#include <atomic>

+ 11
- 11
tests/gp_test.cpp View File

@ -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 <algorithm>

+ 17
- 17
tests/math.cpp View File

@ -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 <chrono>
#include <cmath>
@ -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<float>(ref - v)*100.0/(gp::abs(ref+0.00000001));
res += 0.3 < gp::math::abs<float>(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<float>(ref - v)*100.0/(gp::abs(ref+0.00000001));
res += 0.3 < gp::math::abs<float>(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<float>(
gp::sphere_sdf<float>({0.0,0.0,0.0}, 1.0),
gp::sphere_sdf<float>({-0.75,0.0,0.0}, 1.0)
auto l_sdf = gp::math::difference_sdf<float>(
gp::math::sphere_sdf<float>({0.0,0.0,0.0}, 1.0),
gp::math::sphere_sdf<float>({-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<float>({-0.75,0.0,0.0}, 1.0);
auto l_sdf_b = gp::math::sphere_sdf<float>({-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<uint8_t>;
using pic_color = gp::math::vec4_g<uint8_t>;
using viewport = gp::bmp_viewport<true, pic_color>;
viewport vp{
{128,64},
viewport::src_t{[&](gp::vec2_g<int32_t> p) -> pic_color {
viewport::src_t{[&](gp::math::vec2_g<int32_t> 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<char, 2048> allocation_buffer;
gp::buddy<> allocator{allocation_buffer.begin().data, allocation_buffer.size()};
gp::function<float(vec3)> l_sdf_b{gp::sphere_sdf<float>({0.0,0.0,0.0}, 1.0), allocator};
gp::function<float(vec3)> l_sdf_b{gp::math::sphere_sdf<float>({0.0,0.0,0.0}, 1.0), allocator};
{
gp::function<float(vec3)> sdf{l_sdf_b};

+ 1
- 1
tests/pair_test.cpp View File

@ -1,4 +1,4 @@
#include "gp/pair.hpp"
#include "gp/utils/pair.hpp"
#include "test_scaffold.h"
#include <random>

+ 1
- 1
tests/quotient_filter.cpp View File

@ -1,4 +1,4 @@
#include "gp/quotient_filter.hpp"
#include "gp/containers/probabilistic/quotient_filter.hpp"
#include "test_scaffold.h"
#include <random>

Loading…
Cancel
Save