2020-12-12 23:22:57 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "catch.hpp"
|
|
|
|
#include "sconvcol.h"
|
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
bool simd4f_equal(simd4f a, simd4f b) {
|
|
|
|
return (simd4f_get_x(simd4f_length4_squared(simd4f_sub(a, b))) == 0.f);
|
|
|
|
}
|
|
|
|
|
2020-12-12 23:22:57 +01:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
TEST_CASE("Plane Distance", "[sconvcol]") {
|
2021-05-26 11:33:54 +02:00
|
|
|
sch_plane plane = {
|
|
|
|
simd4f_create(0.f, 0.f, 0.f, 0.f),
|
|
|
|
simd4f_create(0.f, 1.f, 0.f, 0.f)};
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
simd4f point = simd4f_create(0.f, 0.23f, 0.f, 0.f);
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
float dist = sch_plane_distance(&plane, &point);
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
REQUIRE(dist == 0.23f);
|
2020-12-12 23:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Edge Get Direction", "[sconvcol]") {
|
2021-05-26 11:33:54 +02:00
|
|
|
simd4f vertices[4] = {
|
|
|
|
simd4f_create(-1.f, -1.f, 0.f, 0.f),
|
|
|
|
simd4f_create(1.f, -1.f, 0.f, 0.f),
|
|
|
|
simd4f_create(1.f, 1.f, 0.f, 0.f),
|
|
|
|
simd4f_create(-1.f, 1.f, 0.f, 0.f)};
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
sch_face face = {nullptr};
|
|
|
|
sch_create_face(4, vertices, &face);
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
simd4f dir;
|
|
|
|
sch_edge_get_dir(face.edge, &dir);
|
|
|
|
|
|
|
|
simd4f dir_ref = simd4f_create(1.f, 0.f, 0.f, 0.f);
|
|
|
|
REQUIRE(1.f == simd4f_dot3_scalar(dir, dir_ref));
|
|
|
|
}
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-26 11:33:54 +02:00
|
|
|
TEST_CASE("ManualCubeHull", "[sconvcol]") {}
|
|
|
|
|
|
|
|
TEST_CASE("HullBuilder", "[sconvcol]") {
|
|
|
|
sch_hull_builder builder;
|
|
|
|
|
|
|
|
builder.num_vertices = 3;
|
|
|
|
|
|
|
|
GIVEN("A builder") {
|
|
|
|
WHEN("is reset") {
|
|
|
|
sch_builder_reset(&builder);
|
|
|
|
|
|
|
|
THEN("number of vertices and faces is set to 0") {
|
|
|
|
REQUIRE(builder.num_vertices == 0);
|
|
|
|
REQUIRE(builder.num_faces == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("adding a vertex") {
|
|
|
|
int num_vertices = builder.num_vertices;
|
|
|
|
|
|
|
|
simd4f vertex = simd4f_create(1.f, 0.f, 0.f, 1.f);
|
|
|
|
sch_builder_face_begin(&builder);
|
|
|
|
sch_builder_face_vertex(&builder, vertex);
|
|
|
|
THEN("number of vertices increased") {
|
|
|
|
REQUIRE(builder.num_vertices > num_vertices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GIVEN("An empty builder") {
|
|
|
|
sch_builder_reset(&builder);
|
|
|
|
|
|
|
|
WHEN("adding two vertices ") {
|
2021-05-27 14:18:21 +02:00
|
|
|
simd4f vertex0 = simd4f_create(0.f, 0.f, 0.f, 1.f);
|
2021-05-26 11:33:54 +02:00
|
|
|
sch_builder_face_begin(&builder);
|
|
|
|
sch_builder_face_vertex(&builder, vertex0);
|
|
|
|
|
2021-05-27 14:18:21 +02:00
|
|
|
simd4f vertex1 = simd4f_create(1.f, 0.f, 0.f, 1.f);
|
2021-05-26 11:33:54 +02:00
|
|
|
sch_builder_face_vertex(&builder, vertex1);
|
|
|
|
|
|
|
|
WHEN("ending the face") {
|
|
|
|
sch_builder_face_end(&builder);
|
|
|
|
THEN("face idx range goes from 0 to 1") {
|
|
|
|
REQUIRE(builder.num_faces == 1);
|
|
|
|
REQUIRE(builder.num_vertices == 2);
|
|
|
|
REQUIRE(builder.face_vert_idx_start[0] == 0);
|
|
|
|
REQUIRE(builder.face_vert_idx_end[0] == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("creating a triangle") {
|
|
|
|
simd4f vertex2 = simd4f_create(0.5f, 1.f, 0.f, 1.f);
|
|
|
|
sch_builder_face_vertex(&builder, vertex2);
|
|
|
|
sch_builder_face_end(&builder);
|
|
|
|
|
|
|
|
THEN("face idx range goes from 0 to 2") {
|
|
|
|
REQUIRE(builder.num_faces == 1);
|
|
|
|
REQUIRE(builder.num_vertices == 3);
|
|
|
|
REQUIRE(builder.face_vert_idx_start[0] == 0);
|
|
|
|
REQUIRE(builder.face_vert_idx_end[0] == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("creating a hull") {
|
|
|
|
sch_hull hull;
|
2021-05-27 14:18:21 +02:00
|
|
|
SchHullResult result = sch_builder_create_hull(&builder, &hull);
|
2021-05-26 11:33:54 +02:00
|
|
|
|
|
|
|
THEN("verify triangle hull") {
|
2021-05-27 14:18:21 +02:00
|
|
|
REQUIRE(result == SchHullResultOK);
|
2021-05-26 11:33:54 +02:00
|
|
|
REQUIRE(hull.num_faces == 1);
|
|
|
|
sch_face* face = &hull.faces[0];
|
|
|
|
|
|
|
|
sch_vert* hull_vert0 = face->edge->vert;
|
|
|
|
sch_vert* hull_vert1 = face->edge->next->vert;
|
|
|
|
sch_vert* hull_vert2 = face->edge->next->next->vert;
|
|
|
|
|
|
|
|
REQUIRE(simd4f_equal(hull_vert0->p, vertex0));
|
|
|
|
REQUIRE(simd4f_equal(hull_vert1->p, vertex1));
|
|
|
|
REQUIRE(simd4f_equal(hull_vert2->p, vertex2));
|
|
|
|
|
|
|
|
REQUIRE(face->edge->next->next->next == face->edge);
|
|
|
|
}
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-27 14:18:21 +02:00
|
|
|
sch_hull_free_memory(&hull);
|
|
|
|
}
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-27 14:18:21 +02:00
|
|
|
WHEN("adding concave face") {
|
|
|
|
sch_hull hull;
|
|
|
|
SchHullResult result = sch_builder_create_hull(&builder, &hull);
|
|
|
|
|
|
|
|
simd4f vertex3 = simd4f_create(0.5f, 0.25f, 0.1337f, 1.f);
|
|
|
|
|
|
|
|
sch_builder_face_begin(&builder);
|
|
|
|
sch_builder_face_vertex(&builder, vertex0);
|
|
|
|
sch_builder_face_vertex(&builder, vertex1);
|
|
|
|
sch_builder_face_vertex(&builder, vertex3);
|
|
|
|
sch_builder_face_end(&builder);
|
|
|
|
|
|
|
|
THEN("check face and vertex definitions") {
|
|
|
|
REQUIRE(builder.num_faces == 2);
|
|
|
|
REQUIRE(builder.num_vertices == 4);
|
|
|
|
REQUIRE(builder.face_vert_idx_start[0] == 0);
|
|
|
|
REQUIRE(builder.face_vert_idx_end[0] == 2);
|
|
|
|
REQUIRE(builder.face_vert_idx_start[1] == 3);
|
|
|
|
REQUIRE(builder.face_vert_idx_end[1] == 5);
|
|
|
|
}
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-27 14:18:21 +02:00
|
|
|
THEN("hull creation fails") {
|
|
|
|
SchHullResult result = sch_builder_create_hull(&builder, &hull);
|
|
|
|
REQUIRE(result == SchHullResultConcaveVertex);
|
|
|
|
}
|
2020-12-12 23:22:57 +01:00
|
|
|
|
2021-05-27 14:18:21 +02:00
|
|
|
sch_hull_free_memory(&hull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-12 23:22:57 +01:00
|
|
|
}
|