delaunay-test.cc 951 Bytes
Newer Older
Philip Trettner's avatar
Philip Trettner committed
1
#include <doctest.hh>
Philip Trettner's avatar
Philip Trettner committed
2 3

#include <polymesh/Mesh.hh>
4 5
#include <polymesh/algorithms/delaunay.hh>
#include <polymesh/algorithms/triangulate.hh>
Philip Trettner's avatar
Philip Trettner committed
6 7 8 9 10
#include <polymesh/formats.hh>
#include <polymesh/objects/quad.hh>

#include <glm/glm.hpp>

Philip Trettner's avatar
Philip Trettner committed
11
#include <typed-geometry/tg.hh>
Philip Trettner's avatar
Philip Trettner committed
12

13
TEST_CASE("Algorithms.Delaunay")
Philip Trettner's avatar
Philip Trettner committed
14
{
Philip Trettner's avatar
Philip Trettner committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    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);
Philip Trettner's avatar
Philip Trettner committed
43
}