Commit ec106e52 authored by Philip Trettner's avatar Philip Trettner
Browse files

new types

parent 155d8595
......@@ -7,9 +7,16 @@ namespace tg
// software emulation of 16bit math
struct half
{
constexpr half() = default;
constexpr half(float f)
{
// TODO
data = 0;
}
// TODO
private:
uint16_t data;
std::uint16_t data = 0;
};
// TODO
......
......@@ -5,11 +5,15 @@
namespace tg
{
// software emulation of a 8bit float, i.e. 0..1 normalized
// see vulkan 2.9.1
struct quarter
{
constexpr quarter() = default;
constexpr quarter(float f) { data = f < 0 ? 0 : f >= 1 ? 255 : static_cast<int>(f * 256); }
// TODO
private:
std::uint8_t data;
std::uint8_t data = 0;
};
// TODO
......
......@@ -43,5 +43,82 @@ struct size
{
};
template <class ScalarT>
struct size<1, ScalarT>
{
using scalar_t = ScalarT;
static constexpr shape<1> shape = make_shape(1);
scalar_t width = static_cast<scalar_t>(0);
constexpr scalar_t& operator[](int i) { return (&width)[i]; }
constexpr scalar_t const& operator[](int i) const { return (&width)[i]; }
constexpr size() = default;
constexpr explicit size(scalar_t v) : width(v) {}
template <int D, class T, class = std::enable_if_t<D >= 1>>
constexpr explicit size(size<D, T> const& v) : width(ScalarT(v.width))
{
}
template <int D, class T, class = std::enable_if_t<D <= 1>>
constexpr explicit operator size<D, T>() const
{
return size<D, T>(*this);
}
};
template <class ScalarT>
struct size<2, ScalarT>
{
using scalar_t = ScalarT;
static constexpr shape<1> shape = make_shape(2);
scalar_t width = static_cast<scalar_t>(0);
scalar_t height = static_cast<scalar_t>(0);
constexpr scalar_t& operator[](int i) { return (&width)[i]; }
constexpr scalar_t const& operator[](int i) const { return (&width)[i]; }
constexpr size() = default;
constexpr explicit size(scalar_t v) : width(v), height(v) {}
constexpr size(scalar_t width, scalar_t height) : width(width), height(height) {}
template <int D, class T, class = std::enable_if_t<D >= 2>>
constexpr explicit size(size<D, T> const& v) : width(ScalarT(v.width)), height(ScalarT(v.height))
{
}
template <int D, class T, class = std::enable_if_t<D <= 2>>
constexpr explicit operator size<D, T>() const
{
return size<D, T>(*this);
}
};
template <class ScalarT>
struct size<3, ScalarT>
{
using scalar_t = ScalarT;
static constexpr shape<1> shape = make_shape(3);
scalar_t width = static_cast<scalar_t>(0);
scalar_t height = static_cast<scalar_t>(0);
scalar_t depth = static_cast<scalar_t>(0);
constexpr scalar_t& operator[](int i) { return (&width)[i]; }
constexpr scalar_t const& operator[](int i) const { return (&width)[i]; }
constexpr size() = default;
constexpr explicit size(scalar_t v) : width(v), height(v), depth(v) {}
constexpr size(scalar_t width, scalar_t height, scalar_t depth) : width(width), height(height), depth(depth) {}
template <int D, class T, class = std::enable_if_t<D >= 3>>
constexpr explicit size(size<D, T> const& v) : width(ScalarT(v.width)), height(ScalarT(v.height)), depth(ScalarT(v.depth))
{
}
template <int D, class T, class = std::enable_if_t<D <= 3>>
constexpr explicit operator size<D, T>() const
{
return size<D, T>(*this);
}
};
// TODO
} // namespace tg
\ No newline at end of file
......@@ -7,11 +7,18 @@
#include "size.hh"
#include "vec.hh"
#include "quadric.hh"
#include "box.hh"
#include "cylinder.hh"
#include "frustum.hh"
#include "line.hh"
#include "mat.hh"
#include "polygon.hh"
#include "polyline.hh"
#include "quat.hh"
#include "ray.hh"
#include "sphere.hh"
#include "transform.hh"
#include "triangle.hh"
#include "tube.hh"
......@@ -136,10 +136,10 @@ struct vec<1, ScalarT>
constexpr vec() = default;
constexpr explicit vec(scalar_t v) : x(v) {}
template <int D, class T, class = std::enable_if_t<D >= 1>>
constexpr explicit vec(vec<D, T> const& v) : x(ScalarT(v.x))
constexpr explicit vec(vec<D, T> const& v, scalar_t = ScalarT(0)) : x(ScalarT(v.x))
{
}
template <int D, class T, class = std::enable_if_t<D <= 1>>
template <int D, class T>
constexpr explicit operator vec<D, T>() const
{
return vec<D, T>(*this);
......@@ -173,10 +173,14 @@ struct vec<2, ScalarT>
constexpr explicit vec(scalar_t v) : x(v), y(v) {}
constexpr vec(scalar_t x, scalar_t y) : x(x), y(y) {}
template <int D, class T, class = std::enable_if_t<D >= 2>>
constexpr explicit vec(vec<D, T> const& v) : x(ScalarT(v.x)), y(ScalarT(v.y))
constexpr explicit vec(vec<D, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(ScalarT(v.y))
{
}
template <int D, class T, class = std::enable_if_t<D <= 2>>
template <class T>
constexpr explicit vec(vec<1, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(fill)
{
}
template <int D, class T>
constexpr explicit operator vec<D, T>() const
{
return vec<D, T>(*this);
......@@ -214,7 +218,15 @@ struct vec<3, ScalarT>
constexpr explicit vec(scalar_t v) : x(v), y(v), z(v) {}
constexpr vec(scalar_t x, scalar_t y, scalar_t z) : x(x), y(y), z(z) {}
template <int D, class T, class = std::enable_if_t<D >= 3>>
constexpr explicit vec(vec<D, T> const& v) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(ScalarT(v.z))
constexpr explicit vec(vec<D, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(ScalarT(v.z))
{
}
template <class T>
constexpr explicit vec(vec<2, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(fill)
{
}
template <class T>
constexpr explicit vec(vec<1, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(fill), z(fill)
{
}
template <int D, class T, class = std::enable_if_t<D <= 3>>
......@@ -259,7 +271,19 @@ struct vec<4, ScalarT>
constexpr explicit vec(scalar_t v) : x(v), y(v), z(v), w(v) {}
constexpr vec(scalar_t x, scalar_t y, scalar_t z, scalar_t w) : x(x), y(y), z(z), w(w) {}
template <int D, class T, class = std::enable_if_t<D >= 4>>
constexpr explicit vec(vec<D, T> const& v) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(ScalarT(v.z)), w(ScalarT(v.w))
constexpr explicit vec(vec<D, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(ScalarT(v.z)), w(ScalarT(v.w))
{
}
template <class T>
constexpr explicit vec(vec<3, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(ScalarT(v.z)), w(fill)
{
}
template <class T>
constexpr explicit vec(vec<2, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(ScalarT(v.y)), z(fill), w(fill)
{
}
template <class T>
constexpr explicit vec(vec<1, T> const& v, scalar_t fill = ScalarT(0)) : x(ScalarT(v.x)), y(fill), z(fill), w(fill)
{
}
template <int D, class T, class = std::enable_if_t<D <= 4>>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment