From d63f5ce1cb86e69da28bd74b21e9452dbd88a38f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 28 Feb 2021 15:42:39 +0000 Subject: Move utility to lib --- Jamroot.jam | 8 ++- lib/collection.hpp | 71 ++++++++++++++++++++++++ lib/embed-glsl.cpp.m4 | 11 ++++ lib/embed-glsl.h.m4 | 4 ++ lib/glRef.hpp | 56 +++++++++++++++++++ lib/maths.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++++ lib/maths.h | 61 +++++++++++++++++++++ lib/ptr.hpp | 25 +++++++++ lib/sorting.hpp | 12 +++++ lib/special_members.hpp | 18 +++++++ lib/stream_support.hpp | 42 +++++++++++++++ utility/collection.hpp | 71 ------------------------ utility/embed-glsl.cpp.m4 | 11 ---- utility/embed-glsl.h.m4 | 4 -- utility/glRef.hpp | 56 ------------------- utility/maths.cpp | 128 -------------------------------------------- utility/maths.h | 61 --------------------- utility/ptr.hpp | 25 --------- utility/sorting.hpp | 12 ----- utility/special_members.hpp | 18 ------- utility/stream_support.hpp | 42 --------------- 21 files changed, 431 insertions(+), 433 deletions(-) create mode 100644 lib/collection.hpp create mode 100644 lib/embed-glsl.cpp.m4 create mode 100644 lib/embed-glsl.h.m4 create mode 100644 lib/glRef.hpp create mode 100644 lib/maths.cpp create mode 100644 lib/maths.h create mode 100644 lib/ptr.hpp create mode 100644 lib/sorting.hpp create mode 100644 lib/special_members.hpp create mode 100644 lib/stream_support.hpp delete mode 100644 utility/collection.hpp delete mode 100644 utility/embed-glsl.cpp.m4 delete mode 100644 utility/embed-glsl.h.m4 delete mode 100644 utility/glRef.hpp delete mode 100644 utility/maths.cpp delete mode 100644 utility/maths.h delete mode 100644 utility/ptr.hpp delete mode 100644 utility/sorting.hpp delete mode 100644 utility/special_members.hpp delete mode 100644 utility/stream_support.hpp diff --git a/Jamroot.jam b/Jamroot.jam index 08d12d6..9b9afab 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -44,12 +44,12 @@ generators.register-standard embed.glsl : GL_FRAGMENT_SHADER : CPP(fs-%) H(fs-%) actions embed.glsl { - m4 -DNAME=$(2:B) -DTYPE=$(2:S) > $(1[2]) utility/embed-glsl.h.m4 - m4 -DSOURCE=$(2) -DNAME=$(2:B) -DTYPE=$(2:S) -DGLTYPE=$(OPTIONS) > $(1[1]) utility/embed-glsl.cpp.m4 + m4 -DNAME=$(2:B) -DTYPE=$(2:S) > $(1[2]) lib/embed-glsl.h.m4 + m4 -DSOURCE=$(2) -DNAME=$(2:B) -DTYPE=$(2:S) -DGLTYPE=$(OPTIONS) > $(1[1]) lib/embed-glsl.cpp.m4 } rule embed.glsl ( targets * : sources * : properties * ) { - DEPENDS $(targets) : utility/embed-glsl.h.m4 utility/embed-glsl.cpp.m4 ; + DEPENDS $(targets) : lib/embed-glsl.h.m4 lib/embed-glsl.cpp.m4 ; OPTIONS on $(targets) = [ type.type $(sources) ] ; } IMPORT $(__name__) : embed.glsl : : embed.glsl ; @@ -72,7 +72,6 @@ lib ilt : : release:static . - utility lib sdl2/shared glew/shared @@ -80,7 +79,6 @@ lib ilt : stb : : . - utility lib ; diff --git a/lib/collection.hpp b/lib/collection.hpp new file mode 100644 index 0000000..79c331a --- /dev/null +++ b/lib/collection.hpp @@ -0,0 +1,71 @@ +#ifndef COLLECTION_H +#define COLLECTION_H + +#include +#include +#include + +template class Collection { +public: + using Ptr = std::conditional_t, std::unique_ptr>; + using Objects = std::vector; + Objects objects; + + template + auto + create(Params &&... params) + { + if constexpr (shared) { + auto obj = std::make_shared(std::forward(params)...); + objects.emplace_back(obj); + return obj; + } + else { + return static_cast(objects.emplace_back(std::make_unique(std::forward(params)...)).get()); + } + } + + template + auto + apply(const M & m, Params &&... params) const + { + return std::count_if(objects.begin(), objects.end(), [&m, ¶ms...](auto && op) { + if (auto o = dynamic_cast(op.get())) { + std::invoke(m, o, std::forward(params)...); + return true; + } + return false; + }); + } + + template + auto + applyOne(const M & m, Params &&... params) const + { + return std::find_if(objects.begin(), objects.end(), [&m, ¶ms...](auto && op) { + if (auto o = dynamic_cast(op.get())) { + return std::invoke(m, o, std::forward(params)...); + } + return false; + }); + } + + template + void + removeAll() + { + objects.erase(std::remove_if(objects.begin(), objects.end(), + [](auto && op) { + return dynamic_cast(op.get()); + }), + objects.end()); + } + + auto + end() const + { + return objects.end(); + } +}; + +#endif diff --git a/lib/embed-glsl.cpp.m4 b/lib/embed-glsl.cpp.m4 new file mode 100644 index 0000000..9e4c6d4 --- /dev/null +++ b/lib/embed-glsl.cpp.m4 @@ -0,0 +1,11 @@ +changecom()dnl +// NAME +#include "substr(TYPE,1)-NAME.h" +#include +#include "gfx/gl/shader-source.h" + +constexpr const GLchar * src { R"GLSL-EMBED(dnl +include(SOURCE))GLSL-EMBED" }; +constexpr auto len { constexpr_strlen (src) }; + +const GLsource NAME`_'substr(TYPE,1) { src, len, GLTYPE }; diff --git a/lib/embed-glsl.h.m4 b/lib/embed-glsl.h.m4 new file mode 100644 index 0000000..918007b --- /dev/null +++ b/lib/embed-glsl.h.m4 @@ -0,0 +1,4 @@ +// NAME +#include + +extern const GLsource NAME`_'substr(TYPE,1); diff --git a/lib/glRef.hpp b/lib/glRef.hpp new file mode 100644 index 0000000..8596bd3 --- /dev/null +++ b/lib/glRef.hpp @@ -0,0 +1,56 @@ +#ifndef GLREF_H +#define GLREF_H + +#include +#include + +template class glRef { +public: + template explicit glRef(Args &&... args) : id {get(fixed..., std::forward(args)...)} + { + if (!id) { + throw std::runtime_error("Get function failed"); + } + } + + glRef(glRef && other) : id {other.id} + { + other.id = {}; + } + + ~glRef() + { + if (id) { + release(id); + } + } + + NO_COPY(glRef); + + const auto & + operator=(glRef && other) + { + if (id) { + release(id); + } + id = other.id; + other.id = {}; + return *this; + } + + auto + operator*() const + { + return id; + } + + operator IdType() const + { + return id; + } + +private: + IdType id; +}; + +#endif diff --git a/lib/maths.cpp b/lib/maths.cpp new file mode 100644 index 0000000..543c887 --- /dev/null +++ b/lib/maths.cpp @@ -0,0 +1,128 @@ +#include "maths.h" +#include +#include +#include +#include +#include + +glm::mat4 +flat_orientation(const glm::vec3 & diff) +{ + static const auto oneeighty {glm::rotate(pi, up)}; + const auto flatdiff {glm::normalize(glm::vec3 {diff.x, 0, diff.z})}; + auto e {glm::orientation(flatdiff, north)}; + // Handle if diff is exactly opposite to north + return (std::isnan(e[0][0])) ? oneeighty : e; +} + +float +vector_yaw(const glm::vec3 & diff) +{ + return std::atan2(diff.x, diff.z); +} + +float +vector_pitch(const glm::vec3 & diff) +{ + return std::atan(diff.y); +} + +float +round_frac(const float & v, const float & frac) +{ + return std::round(v / frac) * frac; +} + +float +normalize(float ang) +{ + while (ang > pi) { + ang -= two_pi; + } + while (ang <= -pi) { + ang += two_pi; + } + return ang; +} + +Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p) : + Arc([&]() -> Arc { + const auto diffa = e0p - centre3; + const auto diffb = e1p - centre3; + const auto anga = vector_yaw(diffa); + const auto angb = [&diffb, &anga]() { + const auto angb = vector_yaw(diffb); + return (angb < anga) ? angb + two_pi : angb; + }(); + return {anga, angb}; + }()) +{ +} + +std::pair +find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye) +{ + if (as == bs) { + return {as, false}; + } + const auto perps = entrys + half_pi; + const auto perpe = entrye - half_pi; + const glm::vec2 ad {std::sin(perps), std::cos(perps)}; + const glm::vec2 bd {std::sin(perpe), std::cos(perpe)}; + return find_arc_centre(as, ad, bs, bd); +} + +std::pair +find_arc_centre(glm::vec2 as, glm::vec2 ad, glm::vec2 bs, glm::vec2 bd) +{ + const auto det = bd.x * ad.y - bd.y * ad.x; + if (det != 0) { // near parallel line will yield noisy results + const auto d = bs - as; + const auto u = (d.y * bd.x - d.x * bd.y) / det; + return {as + ad * u, u < 0}; + } + throw std::runtime_error("no intersection"); +} + +std::pair +find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye) +{ + const auto getrad = [&](float leftOrRight) { + const auto perps = entrys + leftOrRight; + const auto perpe = entrye + leftOrRight; + const glm::vec2 ad {std::sin(perps), std::cos(perps)}; + const glm::vec2 bd {std::sin(perpe), std::cos(perpe)}; + return find_arcs_radius(start, ad, end, bd); + }; + return {getrad(-half_pi), getrad(half_pi)}; +} + +float +find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd) +{ + // Short name functions for big forula + auto sq = [](auto v) { + return v * v; + }; + auto sqrt = [](float v) { + return std::sqrt(v); + }; + + // Calculates path across both arcs along the normals... pythagorean theorem... for some known radius r + // (2r)^2 = ((m + (X*r)) - (o + (Z*r)))^2 + ((n + (Y*r)) - (p + (W*r)))^2 + // According to symbolabs.com equation tool, that solves for r to give: + // r=(-2 m X+2 X o+2 m Z-2 o Z-2 n Y+2 Y p+2 n W-2 p W-sqrt((2 m X-2 X o-2 m Z+2 o Z+2 n Y-2 Y p-2 n W+2 p W)^(2)-4 + // (X^(2)-2 X Z+Z^(2)+Y^(2)-2 Y W+W^(2)-4) (m^(2)-2 m o+o^(2)+n^(2)-2 n p+p^(2))))/(2 (X^(2)-2 X Z+Z^(2)+Y^(2)-2 Y + // W+W^(2)-4)) + + // These exist cos limitations of online formula rearrangement, and I'm OK with that. + const auto &m {start.x}, &n {start.y}, &o {end.x}, &p {end.y}; + const auto &X {ad.x}, &Y {ad.y}, &Z {bd.x}, &W {bd.y}; + + return (2 * m * X - 2 * X * o - 2 * m * Z + 2 * o * Z + 2 * n * Y - 2 * Y * p - 2 * n * W + 2 * p * W + - sqrt(sq(-2 * m * X + 2 * X * o + 2 * m * Z - 2 * o * Z - 2 * n * Y + 2 * Y * p + 2 * n * W + - 2 * p * W) + - (4 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4) + * (sq(m) - 2 * m * o + sq(o) + sq(n) - 2 * n * p + sq(p))))) + / (2 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4)); +} diff --git a/lib/maths.h b/lib/maths.h new file mode 100644 index 0000000..89cb7cb --- /dev/null +++ b/lib/maths.h @@ -0,0 +1,61 @@ +#ifndef MATH_H +#define MATH_H + +#include +#include +#include + +struct Arc : public std::pair { + using std::pair::pair; + + Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p); + + float + operator[](unsigned int i) const + { + return i ? second : first; + } +}; + +constexpr const glm::vec3 up {0, 1, 0}; +constexpr const glm::vec3 north {0, 0, 1}; +constexpr const glm::vec3 south {0, 0, -1}; +constexpr const glm::vec3 east {-1, 0, 0}; +constexpr const glm::vec3 west {1, 0, 0}; +constexpr auto half_pi {glm::half_pi()}; +constexpr auto pi {glm::pi()}; +constexpr auto two_pi {glm::two_pi()}; + +glm::mat4 flat_orientation(const glm::vec3 & diff); + +float vector_yaw(const glm::vec3 & diff); +float vector_pitch(const glm::vec3 & diff); + +float round_frac(const float & v, const float & frac); + +constexpr inline glm::vec2 +operator!(const glm::vec3 & v) +{ + return {v.x, v.z}; +} + +constexpr inline glm::vec3 +operator!(const glm::vec2 & v) +{ + return {v.x, 0, v.y}; +} + +constexpr inline float +arc_length(const Arc & arc) +{ + return arc.second - arc.first; +} + +float normalize(float ang); + +std::pair find_arc_centre(glm::vec2 start, float entrys, glm::vec2 end, float entrye); +std::pair find_arc_centre(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd); +std::pair find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye); +float find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd); + +#endif diff --git a/lib/ptr.hpp b/lib/ptr.hpp new file mode 100644 index 0000000..b92b63e --- /dev/null +++ b/lib/ptr.hpp @@ -0,0 +1,25 @@ +#ifndef PTR_H +#define PTR_H + +#include + +template class wrapped_ptr : public std::unique_ptr { +public: + using std::unique_ptr::unique_ptr; + wrapped_ptr() : std::unique_ptr {{}, {}} { } + + inline + operator Obj *() const + { + return this->get(); + } + + template + static auto + create(Obj * (*factory)(Args...), void (*deleter)(Obj *), Params &&... params) + { + return wrapped_ptr {factory(std::forward(params)...), deleter}; + } +}; + +#endif diff --git a/lib/sorting.hpp b/lib/sorting.hpp new file mode 100644 index 0000000..0cb0eaf --- /dev/null +++ b/lib/sorting.hpp @@ -0,0 +1,12 @@ +#ifndef SORTING_H +#define SORTING_H + +template struct PtrSorter { + bool + operator()(const T & a, const T & b) const + { + return *a < *b; + } +}; + +#endif diff --git a/lib/special_members.hpp b/lib/special_members.hpp new file mode 100644 index 0000000..0d63f58 --- /dev/null +++ b/lib/special_members.hpp @@ -0,0 +1,18 @@ +#ifndef SPECIAL_MEMBERS_H +#define SPECIAL_MEMBERS_H + +#define NO_COPY(TYPE) \ + TYPE(const TYPE &) = delete; \ + void operator=(const TYPE &) = delete + +#define NO_MOVE(TYPE) \ + TYPE(TYPE &&) = delete; \ + void operator=(TYPE &&) = delete + +#define DEFAULT_MOVE_COPY(TYPE) \ + TYPE(const TYPE &) = default; \ + TYPE(TYPE &&) = default; \ + TYPE & operator=(const TYPE &) = default; \ + TYPE & operator=(TYPE &&) = default + +#endif diff --git a/lib/stream_support.hpp b/lib/stream_support.hpp new file mode 100644 index 0000000..1ee1661 --- /dev/null +++ b/lib/stream_support.hpp @@ -0,0 +1,42 @@ +#ifndef STREAM_SUPPORT_H +#define STREAM_SUPPORT_H + +#include +#include +#include + +namespace std { + template + std::ostream & + operator<<(std::ostream & s, const glm::mat & m) + { + for (int y = 0; y < m.length(); y++) { + const auto & col = m[y]; + for (int x = 0; x < col.length(); x++) { + s << col[x] << ", "; + } + s << "\n"; + } + return s; + } + + template + std::ostream & + operator<<(std::ostream & s, const glm::vec & v) + { + for (int x = 0; x < L; x++) { + s << v[x] << ", "; + } + return s; + } + + inline std::ostream & + operator<<(std::ostream & s, const Arc & arc) + { + return s << arc.first << " ↺ " << arc.second; + } +} + +#define CLOG(x) std::clog << #x " : " << x << "\n"; + +#endif diff --git a/utility/collection.hpp b/utility/collection.hpp deleted file mode 100644 index 79c331a..0000000 --- a/utility/collection.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef COLLECTION_H -#define COLLECTION_H - -#include -#include -#include - -template class Collection { -public: - using Ptr = std::conditional_t, std::unique_ptr>; - using Objects = std::vector; - Objects objects; - - template - auto - create(Params &&... params) - { - if constexpr (shared) { - auto obj = std::make_shared(std::forward(params)...); - objects.emplace_back(obj); - return obj; - } - else { - return static_cast(objects.emplace_back(std::make_unique(std::forward(params)...)).get()); - } - } - - template - auto - apply(const M & m, Params &&... params) const - { - return std::count_if(objects.begin(), objects.end(), [&m, ¶ms...](auto && op) { - if (auto o = dynamic_cast(op.get())) { - std::invoke(m, o, std::forward(params)...); - return true; - } - return false; - }); - } - - template - auto - applyOne(const M & m, Params &&... params) const - { - return std::find_if(objects.begin(), objects.end(), [&m, ¶ms...](auto && op) { - if (auto o = dynamic_cast(op.get())) { - return std::invoke(m, o, std::forward(params)...); - } - return false; - }); - } - - template - void - removeAll() - { - objects.erase(std::remove_if(objects.begin(), objects.end(), - [](auto && op) { - return dynamic_cast(op.get()); - }), - objects.end()); - } - - auto - end() const - { - return objects.end(); - } -}; - -#endif diff --git a/utility/embed-glsl.cpp.m4 b/utility/embed-glsl.cpp.m4 deleted file mode 100644 index 9e4c6d4..0000000 --- a/utility/embed-glsl.cpp.m4 +++ /dev/null @@ -1,11 +0,0 @@ -changecom()dnl -// NAME -#include "substr(TYPE,1)-NAME.h" -#include -#include "gfx/gl/shader-source.h" - -constexpr const GLchar * src { R"GLSL-EMBED(dnl -include(SOURCE))GLSL-EMBED" }; -constexpr auto len { constexpr_strlen (src) }; - -const GLsource NAME`_'substr(TYPE,1) { src, len, GLTYPE }; diff --git a/utility/embed-glsl.h.m4 b/utility/embed-glsl.h.m4 deleted file mode 100644 index 918007b..0000000 --- a/utility/embed-glsl.h.m4 +++ /dev/null @@ -1,4 +0,0 @@ -// NAME -#include - -extern const GLsource NAME`_'substr(TYPE,1); diff --git a/utility/glRef.hpp b/utility/glRef.hpp deleted file mode 100644 index 8596bd3..0000000 --- a/utility/glRef.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef GLREF_H -#define GLREF_H - -#include -#include - -template class glRef { -public: - template explicit glRef(Args &&... args) : id {get(fixed..., std::forward(args)...)} - { - if (!id) { - throw std::runtime_error("Get function failed"); - } - } - - glRef(glRef && other) : id {other.id} - { - other.id = {}; - } - - ~glRef() - { - if (id) { - release(id); - } - } - - NO_COPY(glRef); - - const auto & - operator=(glRef && other) - { - if (id) { - release(id); - } - id = other.id; - other.id = {}; - return *this; - } - - auto - operator*() const - { - return id; - } - - operator IdType() const - { - return id; - } - -private: - IdType id; -}; - -#endif diff --git a/utility/maths.cpp b/utility/maths.cpp deleted file mode 100644 index 543c887..0000000 --- a/utility/maths.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "maths.h" -#include -#include -#include -#include -#include - -glm::mat4 -flat_orientation(const glm::vec3 & diff) -{ - static const auto oneeighty {glm::rotate(pi, up)}; - const auto flatdiff {glm::normalize(glm::vec3 {diff.x, 0, diff.z})}; - auto e {glm::orientation(flatdiff, north)}; - // Handle if diff is exactly opposite to north - return (std::isnan(e[0][0])) ? oneeighty : e; -} - -float -vector_yaw(const glm::vec3 & diff) -{ - return std::atan2(diff.x, diff.z); -} - -float -vector_pitch(const glm::vec3 & diff) -{ - return std::atan(diff.y); -} - -float -round_frac(const float & v, const float & frac) -{ - return std::round(v / frac) * frac; -} - -float -normalize(float ang) -{ - while (ang > pi) { - ang -= two_pi; - } - while (ang <= -pi) { - ang += two_pi; - } - return ang; -} - -Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p) : - Arc([&]() -> Arc { - const auto diffa = e0p - centre3; - const auto diffb = e1p - centre3; - const auto anga = vector_yaw(diffa); - const auto angb = [&diffb, &anga]() { - const auto angb = vector_yaw(diffb); - return (angb < anga) ? angb + two_pi : angb; - }(); - return {anga, angb}; - }()) -{ -} - -std::pair -find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye) -{ - if (as == bs) { - return {as, false}; - } - const auto perps = entrys + half_pi; - const auto perpe = entrye - half_pi; - const glm::vec2 ad {std::sin(perps), std::cos(perps)}; - const glm::vec2 bd {std::sin(perpe), std::cos(perpe)}; - return find_arc_centre(as, ad, bs, bd); -} - -std::pair -find_arc_centre(glm::vec2 as, glm::vec2 ad, glm::vec2 bs, glm::vec2 bd) -{ - const auto det = bd.x * ad.y - bd.y * ad.x; - if (det != 0) { // near parallel line will yield noisy results - const auto d = bs - as; - const auto u = (d.y * bd.x - d.x * bd.y) / det; - return {as + ad * u, u < 0}; - } - throw std::runtime_error("no intersection"); -} - -std::pair -find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye) -{ - const auto getrad = [&](float leftOrRight) { - const auto perps = entrys + leftOrRight; - const auto perpe = entrye + leftOrRight; - const glm::vec2 ad {std::sin(perps), std::cos(perps)}; - const glm::vec2 bd {std::sin(perpe), std::cos(perpe)}; - return find_arcs_radius(start, ad, end, bd); - }; - return {getrad(-half_pi), getrad(half_pi)}; -} - -float -find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd) -{ - // Short name functions for big forula - auto sq = [](auto v) { - return v * v; - }; - auto sqrt = [](float v) { - return std::sqrt(v); - }; - - // Calculates path across both arcs along the normals... pythagorean theorem... for some known radius r - // (2r)^2 = ((m + (X*r)) - (o + (Z*r)))^2 + ((n + (Y*r)) - (p + (W*r)))^2 - // According to symbolabs.com equation tool, that solves for r to give: - // r=(-2 m X+2 X o+2 m Z-2 o Z-2 n Y+2 Y p+2 n W-2 p W-sqrt((2 m X-2 X o-2 m Z+2 o Z+2 n Y-2 Y p-2 n W+2 p W)^(2)-4 - // (X^(2)-2 X Z+Z^(2)+Y^(2)-2 Y W+W^(2)-4) (m^(2)-2 m o+o^(2)+n^(2)-2 n p+p^(2))))/(2 (X^(2)-2 X Z+Z^(2)+Y^(2)-2 Y - // W+W^(2)-4)) - - // These exist cos limitations of online formula rearrangement, and I'm OK with that. - const auto &m {start.x}, &n {start.y}, &o {end.x}, &p {end.y}; - const auto &X {ad.x}, &Y {ad.y}, &Z {bd.x}, &W {bd.y}; - - return (2 * m * X - 2 * X * o - 2 * m * Z + 2 * o * Z + 2 * n * Y - 2 * Y * p - 2 * n * W + 2 * p * W - - sqrt(sq(-2 * m * X + 2 * X * o + 2 * m * Z - 2 * o * Z - 2 * n * Y + 2 * Y * p + 2 * n * W - - 2 * p * W) - - (4 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4) - * (sq(m) - 2 * m * o + sq(o) + sq(n) - 2 * n * p + sq(p))))) - / (2 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4)); -} diff --git a/utility/maths.h b/utility/maths.h deleted file mode 100644 index 89cb7cb..0000000 --- a/utility/maths.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef MATH_H -#define MATH_H - -#include -#include -#include - -struct Arc : public std::pair { - using std::pair::pair; - - Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p); - - float - operator[](unsigned int i) const - { - return i ? second : first; - } -}; - -constexpr const glm::vec3 up {0, 1, 0}; -constexpr const glm::vec3 north {0, 0, 1}; -constexpr const glm::vec3 south {0, 0, -1}; -constexpr const glm::vec3 east {-1, 0, 0}; -constexpr const glm::vec3 west {1, 0, 0}; -constexpr auto half_pi {glm::half_pi()}; -constexpr auto pi {glm::pi()}; -constexpr auto two_pi {glm::two_pi()}; - -glm::mat4 flat_orientation(const glm::vec3 & diff); - -float vector_yaw(const glm::vec3 & diff); -float vector_pitch(const glm::vec3 & diff); - -float round_frac(const float & v, const float & frac); - -constexpr inline glm::vec2 -operator!(const glm::vec3 & v) -{ - return {v.x, v.z}; -} - -constexpr inline glm::vec3 -operator!(const glm::vec2 & v) -{ - return {v.x, 0, v.y}; -} - -constexpr inline float -arc_length(const Arc & arc) -{ - return arc.second - arc.first; -} - -float normalize(float ang); - -std::pair find_arc_centre(glm::vec2 start, float entrys, glm::vec2 end, float entrye); -std::pair find_arc_centre(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd); -std::pair find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye); -float find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd); - -#endif diff --git a/utility/ptr.hpp b/utility/ptr.hpp deleted file mode 100644 index b92b63e..0000000 --- a/utility/ptr.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef PTR_H -#define PTR_H - -#include - -template class wrapped_ptr : public std::unique_ptr { -public: - using std::unique_ptr::unique_ptr; - wrapped_ptr() : std::unique_ptr {{}, {}} { } - - inline - operator Obj *() const - { - return this->get(); - } - - template - static auto - create(Obj * (*factory)(Args...), void (*deleter)(Obj *), Params &&... params) - { - return wrapped_ptr {factory(std::forward(params)...), deleter}; - } -}; - -#endif diff --git a/utility/sorting.hpp b/utility/sorting.hpp deleted file mode 100644 index 0cb0eaf..0000000 --- a/utility/sorting.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef SORTING_H -#define SORTING_H - -template struct PtrSorter { - bool - operator()(const T & a, const T & b) const - { - return *a < *b; - } -}; - -#endif diff --git a/utility/special_members.hpp b/utility/special_members.hpp deleted file mode 100644 index 0d63f58..0000000 --- a/utility/special_members.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SPECIAL_MEMBERS_H -#define SPECIAL_MEMBERS_H - -#define NO_COPY(TYPE) \ - TYPE(const TYPE &) = delete; \ - void operator=(const TYPE &) = delete - -#define NO_MOVE(TYPE) \ - TYPE(TYPE &&) = delete; \ - void operator=(TYPE &&) = delete - -#define DEFAULT_MOVE_COPY(TYPE) \ - TYPE(const TYPE &) = default; \ - TYPE(TYPE &&) = default; \ - TYPE & operator=(const TYPE &) = default; \ - TYPE & operator=(TYPE &&) = default - -#endif diff --git a/utility/stream_support.hpp b/utility/stream_support.hpp deleted file mode 100644 index 1ee1661..0000000 --- a/utility/stream_support.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef STREAM_SUPPORT_H -#define STREAM_SUPPORT_H - -#include -#include -#include - -namespace std { - template - std::ostream & - operator<<(std::ostream & s, const glm::mat & m) - { - for (int y = 0; y < m.length(); y++) { - const auto & col = m[y]; - for (int x = 0; x < col.length(); x++) { - s << col[x] << ", "; - } - s << "\n"; - } - return s; - } - - template - std::ostream & - operator<<(std::ostream & s, const glm::vec & v) - { - for (int x = 0; x < L; x++) { - s << v[x] << ", "; - } - return s; - } - - inline std::ostream & - operator<<(std::ostream & s, const Arc & arc) - { - return s << arc.first << " ↺ " << arc.second; - } -} - -#define CLOG(x) std::clog << #x " : " << x << "\n"; - -#endif -- cgit v1.2.3