Skip to content
Snippets Groups Projects
Commit e74b7ca2 authored by Philip Trettner's avatar Philip Trettner
Browse files

added mat io, fixed some small problems

parent ddb7ee2c
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ Some functions take optional `eps` tolerances, such as `contains` and `intersect
* Declare `using`s for common cases (e.g. `pos3` for `pos<3, f32>`)
* Do not include `std`-headers, only use `tg` ones.
* Add support for `std::hash` and `std::less` in `tg/std/`
* Add unit tests (at least an interface check in `tests/geometry/objects.cc`)
* Add unit tests (at least an interface check in `tests/geometry/objects.cc`), add to test list in `tests/geometry/std.cc`
### Implementation
......
#pragma once
#include "../../types/objects/box.hh"
#include "../../types/objects/segment.hh"
#include "../../types/objects/triangle.hh"
#include "../scalar_traits.hh"
#include "../special_values.hh"
......@@ -29,4 +30,10 @@ pos<D, fractional_result<ScalarT>> centroid(triangle<D, ScalarT> const& p)
auto z = tg::zero<pos<D, ScalarT>>();
return z + ((p.v0 - z) + (p.v1 - z) + (p.v2 - z)) / ScalarT(3);
}
template <int D, class ScalarT>
pos<D, fractional_result<ScalarT>> centroid(segment<D, ScalarT> const& p)
{
return mix(p.a, p.b, fractional_result<ScalarT>(0.5));
}
} // namespace tg
......@@ -31,6 +31,11 @@ struct type_name_t<triangle<D, ScalarT>>
{
static constexpr char const* value = "triangle";
};
template <int C, int R, class ScalarT>
struct type_name_t<mat<C, R, ScalarT>>
{
static constexpr char const* value = "mat";
};
// type suffix
template <int D, class ScalarT, template <int, class> class Type>
......
......@@ -8,9 +8,9 @@ namespace tg
{
namespace detail
{
size_t hash_combine(size_t a, size_t b) { return a * 6364136223846793005ULL + b + 0xda3e39cb94b95bdbULL; }
size_t hash_combine(size_t a, size_t b, size_t c) { return hash_combine(hash_combine(a, b), c); }
size_t hash_combine(size_t a, size_t b, size_t c, size_t d) { return hash_combine(hash_combine(a, b), hash_combine(c, d)); }
inline size_t hash_combine(size_t a, size_t b) { return a * 6364136223846793005ULL + b + 0xda3e39cb94b95bdbULL; }
inline size_t hash_combine(size_t a, size_t b, size_t c) { return hash_combine(hash_combine(a, b), c); }
inline size_t hash_combine(size_t a, size_t b, size_t c, size_t d) { return hash_combine(hash_combine(a, b), hash_combine(c, d)); }
template <class T>
size_t hash(T const& a)
......
......@@ -9,8 +9,8 @@
namespace tg
{
template <int D, class ScalarT, template <int, class> class Type>
std::string to_string(Type<D, ScalarT> const& v)
template <class T>
std::string to_string(T const& v)
{
std::ostringstream ss;
ss << v;
......@@ -42,7 +42,7 @@ std::ostream& operator<<(std::ostream& out, vec<D, ScalarT> const& v)
return out;
}
template <int D, class ScalarT>
std::ostream& operator<<(std::ostream& out, pos<D, ScalarT> const& v)
std::ostream& operator<<(std::ostream& out, pos<D, ScalarT> const& p)
{
using T = vec<D, ScalarT>;
out << type_name_prefix<T>;
......@@ -50,12 +50,12 @@ std::ostream& operator<<(std::ostream& out, pos<D, ScalarT> const& v)
out << type_name_suffix<T>;
out << "(";
for (auto i = 0; i < D; ++i)
out << (i > 0 ? ", " : "") << v[i];
out << (i > 0 ? ", " : "") << p[i];
out << ")";
return out;
}
template <int D, class ScalarT>
std::ostream& operator<<(std::ostream& out, size<D, ScalarT> const& v)
std::ostream& operator<<(std::ostream& out, size<D, ScalarT> const& s)
{
using T = vec<D, ScalarT>;
out << type_name_prefix<T>;
......@@ -63,30 +63,44 @@ std::ostream& operator<<(std::ostream& out, size<D, ScalarT> const& v)
out << type_name_suffix<T>;
out << "(";
for (auto i = 0; i < D; ++i)
out << (i > 0 ? ", " : "") << v[i];
out << (i > 0 ? ", " : "") << s[i];
out << ")";
return out;
}
template <int D, class ScalarT>
std::ostream& operator<<(std::ostream& out, box<D, ScalarT> const& v)
std::ostream& operator<<(std::ostream& out, box<D, ScalarT> const& b)
{
using T = box<D, ScalarT>;
out << type_name_prefix<T>;
out << type_name<T>;
out << type_name_suffix<T>;
out << "(" << v.min << ", " << v.max << ")";
out << "(" << b.min << ", " << b.max << ")";
return out;
}
template <int D, class ScalarT>
std::ostream& operator<<(std::ostream& out, triangle<D, ScalarT> const& v)
std::ostream& operator<<(std::ostream& out, triangle<D, ScalarT> const& t)
{
using T = triangle<D, ScalarT>;
out << type_name_prefix<T>;
out << type_name<T>;
out << type_name_suffix<T>;
out << "(" << v.v0 << ", " << v.v1 << ", " << v.v2 << ")";
out << "(" << t.v0 << ", " << t.v1 << ", " << t.v2 << ")";
return out;
}
template <int C, int R, class ScalarT>
std::ostream& operator<<(std::ostream& out, mat<C, R, ScalarT> const& m)
{
using T = mat<C, R, ScalarT>;
out << type_name_prefix<T>;
out << type_name<T>;
out << type_name_suffix<T>;
out << "(";
for (auto i = 0; i < C; ++i)
out << (i > 0 ? ", " : "") << m[i];
out << ")";
return out;
}
} // namespace tg
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment