Commit 3bb031eb authored by Philip Trettner's avatar Philip Trettner
Browse files

more tests

parent 7f013dc7
Subproject commit f3621e9e0dc15d0a08a9f313009d115e69742ea6
Subproject commit dd983506bd3bdb277f63c3c6f9ad327dcd7eb47c
#include <gtest/gtest.h>
#include <polymesh/Mesh.hh>
#include <polymesh/algorithms/remeshing/delaunay.hh>
#include <polymesh/algorithms/remeshing/triangulate.hh>
#include <polymesh/formats.hh>
#include <polymesh/objects/quad.hh>
#include <glm/glm.hpp>
#include <tg/typed-geometry.hh>
TEST(Algorithms, Delaunay)
{
//
pm::Mesh m;
auto pos = attribute(m.vertices(), glm::vec3{});
tg::rng rng;
for (auto i = 0; i < 3; ++i)
{
m.clear();
int cx = 20;
int cy = 20;
auto noise = 0.3f;
auto hnoise = 0.3f;
pm::objects::add_quad(
m,
[&](pm::vertex_handle v, float x, float y) {
//
pos[v] = {x * cx + uniform(rng, -noise, noise), uniform(rng, -hnoise, hnoise), y * cy + uniform(rng, -noise, noise)};
},
cx, cy);
triangulate_naive(m);
pm::make_delaunay(m, pos);
}
// save("/tmp/quad.obj", m, pos);
}
......@@ -47,6 +47,88 @@ static_assert(sizeof(pm::vertex_attribute<bool>)
*/
static_assert(sizeof(pm::Mesh) == 120, "mesh is bigger than expected");
TEST(Attributes, Creation)
{
pm::Mesh m;
auto v0 = m.vertices().add();
auto v1 = m.vertices().add();
auto v2 = m.vertices().add();
auto f = m.faces().add(v0, v1, v2);
{
auto a0 = m.vertices().make_attribute<int>();
auto a1 = m.vertices().make_attribute_with_default(3);
auto a2 = m.vertices().make_attribute_from_data(std::vector<int>(3, 5));
auto a3 = m.vertices().make_attribute([](auto) { return 7; });
auto a4 = m.vertices().make_attribute([](auto) { return 11; });
auto a5 = pm::vertex_attribute<int>(m);
// TODO: auto a6 = pm::vertex_attribute(m, 13);
auto a7 = pm::attribute<int>(m.vertices());
auto a8 = attribute(m.vertices(), 15);
for (auto v : {v0, v1, v2})
{
ASSERT_EQ(a0[v], 0);
ASSERT_EQ(a1[v], 3);
ASSERT_EQ(a2[v], 5);
ASSERT_EQ(a3[v], 7);
ASSERT_EQ(a4[v], 11);
ASSERT_EQ(a5[v], 0);
// ASSERT_EQ(a6[v], 13);
ASSERT_EQ(a7[v], 0);
ASSERT_EQ(a8[v], 15);
}
}
{
auto a0 = m.faces().make_attribute<int>();
auto a1 = m.faces().make_attribute_with_default(3);
auto a2 = m.faces().make_attribute_from_data(std::vector<int>(3, 5));
auto a3 = m.faces().make_attribute([](auto) { return 7; });
auto a4 = m.faces().make_attribute([](auto) { return 11; });
auto a5 = pm::face_attribute<int>(m);
// TODO: auto a6 = pm::face_attribute(m, 13);
auto a7 = pm::attribute<int>(m.faces());
auto a8 = attribute(m.faces(), 15);
ASSERT_EQ(a0[f], 0);
ASSERT_EQ(a1[f], 3);
ASSERT_EQ(a2[f], 5);
ASSERT_EQ(a3[f], 7);
ASSERT_EQ(a4[f], 11);
ASSERT_EQ(a5[f], 0);
// ASSERT_EQ(a6[f], 13);
ASSERT_EQ(a7[f], 0);
ASSERT_EQ(a8[f], 15);
}
{
auto a0 = m.edges().make_attribute<int>();
auto a1 = m.edges().make_attribute_with_default(3);
auto a2 = m.edges().make_attribute_from_data(std::vector<int>(3, 5));
auto a3 = m.edges().make_attribute([](auto) { return 7; });
auto a4 = m.edges().make_attribute([](auto) { return 11; });
auto a5 = pm::edge_attribute<int>(m);
// TODO: auto a6 = pm::edge_attribute(m, 13);
auto a7 = pm::attribute<int>(m.edges());
auto a8 = attribute(m.edges(), 15);
}
{
auto a0 = m.halfedges().make_attribute<int>();
auto a1 = m.halfedges().make_attribute_with_default(3);
auto a2 = m.halfedges().make_attribute_from_data(std::vector<int>(3, 5));
auto a3 = m.halfedges().make_attribute([](auto) { return 7; });
auto a4 = m.halfedges().make_attribute([](auto) { return 11; });
auto a5 = pm::halfedge_attribute<int>(m);
// TODO: auto a6 = pm::halfedge_attribute(m, 13);
auto a7 = pm::attribute<int>(m.halfedges());
auto a8 = attribute(m.halfedges(), 15);
}
}
TEST(Attributes, Registry)
{
pm::Mesh m;
......
......@@ -4,5 +4,33 @@
TEST(Interface, Handles)
{
// TODO
pm::Mesh m;
auto v0 = m.vertices().add();
auto v1 = m.vertices().add();
auto v2 = m.vertices().add();
auto i0 = m.vertices()[0];
auto i1 = m.vertices()[1];
auto i2 = m.vertices()[2];
auto j0 = m.vertices()[pm::vertex_index(0)];
auto j1 = m.vertices()[pm::vertex_index(1)];
auto j2 = m.vertices()[pm::vertex_index(2)];
auto k0 = m[pm::vertex_index(0)];
auto k1 = m[pm::vertex_index(1)];
auto k2 = m[pm::vertex_index(2)];
ASSERT_EQ(v0, i0);
ASSERT_EQ(v1, i1);
ASSERT_EQ(v2, i2);
ASSERT_EQ(v0, j0);
ASSERT_EQ(v1, j1);
ASSERT_EQ(v2, j2);
ASSERT_EQ(v0, k0);
ASSERT_EQ(v1, k1);
ASSERT_EQ(v2, k2);
}
Markdown is supported
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