Attempt to fix unit test for 2D convex hull of sinking object on RasperryPi

This commit is contained in:
enricoturri1966 2021-05-21 10:14:13 +02:00
parent ed9c93f85a
commit 90be278d98

View File

@ -30,23 +30,23 @@ SCENARIO("Export+Import geometry to/from 3mf file cycle", "[3mf]") {
load_stl(src_file.c_str(), &src_model); load_stl(src_file.c_str(), &src_model);
src_model.add_default_instances(); src_model.add_default_instances();
ModelObject* src_object = src_model.objects[0]; ModelObject* src_object = src_model.objects.front();
// apply generic transformation to the 1st volume // apply generic transformation to the 1st volume
Geometry::Transformation src_volume_transform; Geometry::Transformation src_volume_transform;
src_volume_transform.set_offset(Vec3d(10.0, 20.0, 0.0)); src_volume_transform.set_offset({ 10.0, 20.0, 0.0 });
src_volume_transform.set_rotation(Vec3d(Geometry::deg2rad(25.0), Geometry::deg2rad(35.0), Geometry::deg2rad(45.0))); src_volume_transform.set_rotation({ Geometry::deg2rad(25.0), Geometry::deg2rad(35.0), Geometry::deg2rad(45.0) });
src_volume_transform.set_scaling_factor(Vec3d(1.1, 1.2, 1.3)); src_volume_transform.set_scaling_factor({ 1.1, 1.2, 1.3 });
src_volume_transform.set_mirror(Vec3d(-1.0, 1.0, -1.0)); src_volume_transform.set_mirror({ -1.0, 1.0, -1.0 });
src_object->volumes[0]->set_transformation(src_volume_transform); src_object->volumes.front()->set_transformation(src_volume_transform);
// apply generic transformation to the 1st instance // apply generic transformation to the 1st instance
Geometry::Transformation src_instance_transform; Geometry::Transformation src_instance_transform;
src_instance_transform.set_offset(Vec3d(5.0, 10.0, 0.0)); src_instance_transform.set_offset({ 5.0, 10.0, 0.0 });
src_instance_transform.set_rotation(Vec3d(Geometry::deg2rad(12.0), Geometry::deg2rad(13.0), Geometry::deg2rad(14.0))); src_instance_transform.set_rotation({ Geometry::deg2rad(12.0), Geometry::deg2rad(13.0), Geometry::deg2rad(14.0) });
src_instance_transform.set_scaling_factor(Vec3d(0.9, 0.8, 0.7)); src_instance_transform.set_scaling_factor({ 0.9, 0.8, 0.7 });
src_instance_transform.set_mirror(Vec3d(1.0, -1.0, -1.0)); src_instance_transform.set_mirror({ 1.0, -1.0, -1.0 });
src_object->instances[0]->set_transformation(src_instance_transform); src_object->instances.front()->set_transformation(src_instance_transform);
WHEN("model is saved+loaded to/from 3mf file") { WHEN("model is saved+loaded to/from 3mf file") {
// save the model to 3mf file // save the model to 3mf file
@ -67,16 +67,9 @@ SCENARIO("Export+Import geometry to/from 3mf file cycle", "[3mf]") {
dst_mesh.repair(); dst_mesh.repair();
bool res = src_mesh.its.vertices.size() == dst_mesh.its.vertices.size(); bool res = src_mesh.its.vertices.size() == dst_mesh.its.vertices.size();
if (res) if (res) {
{ for (size_t i = 0; i < dst_mesh.its.vertices.size(); ++i) {
for (size_t i = 0; i < dst_mesh.its.vertices.size(); ++i)
{
res &= dst_mesh.its.vertices[i].isApprox(src_mesh.its.vertices[i]); res &= dst_mesh.its.vertices[i].isApprox(src_mesh.its.vertices[i]);
if (!res)
{
Vec3f diff = dst_mesh.its.vertices[i] - src_mesh.its.vertices[i];
std::cout << i << ": diff " << to_string((Vec3d)diff.cast<double>()) << "\n";
}
} }
} }
THEN("world vertices coordinates after load match") { THEN("world vertices coordinates after load match") {
@ -95,11 +88,11 @@ SCENARIO("2D convex hull of sinking object", "[3mf]") {
model.add_default_instances(); model.add_default_instances();
WHEN("model is rotated, scaled and set as sinking") { WHEN("model is rotated, scaled and set as sinking") {
ModelObject* object = model.objects[0]; ModelObject* object = model.objects.front();
object->center_around_origin(false); object->center_around_origin(false);
// set instance's attitude so that it is rotated, scaled and sinking // set instance's attitude so that it is rotated, scaled and sinking
ModelInstance* instance = object->instances[0]; ModelInstance* instance = object->instances.front();
instance->set_rotation(Y, -M_PI / 4.0); instance->set_rotation(Y, -M_PI / 4.0);
instance->set_offset(Vec3d::Zero()); instance->set_offset(Vec3d::Zero());
instance->set_scaling_factor({ 2.0, 2.0, 2.0 }); instance->set_scaling_factor({ 2.0, 2.0, 2.0 });
@ -116,7 +109,12 @@ SCENARIO("2D convex hull of sinking object", "[3mf]") {
{ -4244, 19502998 }, { -4244, 19502998 },
{ -4242640, -8537523 } { -4242640, -8537523 }
}; };
bool res = hull_2d.points == result; bool res = hull_2d.points.size() == result.size();
if (res) {
for (size_t i = 0; i < hull_2d.points.size(); ++i) {
res &= hull_2d.points[i].isApprox(result[i]);
}
}
THEN("2D convex hull should match with reference") { THEN("2D convex hull should match with reference") {
REQUIRE(res); REQUIRE(res);