Skip to content

Commit ffc6d9c

Browse files
committed
fix(NegativeElements): Test elements in exact if possible (tetrahedra in solid, triangles in surface).
1 parent a84dd65 commit ffc6d9c

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/geode/inspector/criterion/negative_elements/solid_negative_elements.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <geode/basic/pimpl_impl.hpp>
2828
#include <geode/basic/uuid.hpp>
2929

30+
#include <geode/geometry/basic_objects/tetrahedron.hpp>
31+
#include <geode/geometry/information.hpp>
32+
#include <geode/geometry/sign.hpp>
33+
3034
#include <geode/mesh/core/solid_mesh.hpp>
3135

3236
namespace geode
@@ -41,7 +45,7 @@ namespace geode
4145
{
4246
for( const auto polyhedron_id : Range{ mesh_.nb_polyhedra() } )
4347
{
44-
if( mesh_.polyhedron_volume( polyhedron_id ) < 0 )
48+
if( polyhedron_has_negative_volume( polyhedron_id ) )
4549
{
4650
return true;
4751
}
@@ -56,7 +60,7 @@ namespace geode
5660
};
5761
for( const auto polyhedron_id : Range{ mesh_.nb_polyhedra() } )
5862
{
59-
if( mesh_.polyhedron_volume( polyhedron_id ) < 0 )
63+
if( polyhedron_has_negative_volume( polyhedron_id ) )
6064
{
6165
wrong_polyhedra.add_issue( polyhedron_id,
6266
absl::StrCat( "Polyhedron ", polyhedron_id,
@@ -67,6 +71,24 @@ namespace geode
6771
return wrong_polyhedra;
6872
}
6973

74+
private:
75+
bool polyhedron_has_negative_volume( index_t polyhedron_id ) const
76+
{
77+
if( mesh_.nb_polyhedron_vertices( polyhedron_id ) == 4 )
78+
{
79+
Tetrahedron tetrahedron{ mesh_.point( mesh_.polyhedron_vertex(
80+
{ polyhedron_id, 0 } ) ),
81+
mesh_.point(
82+
mesh_.polyhedron_vertex( { polyhedron_id, 1 } ) ),
83+
mesh_.point(
84+
mesh_.polyhedron_vertex( { polyhedron_id, 2 } ) ),
85+
mesh_.point(
86+
mesh_.polyhedron_vertex( { polyhedron_id, 3 } ) ) };
87+
return tetrahedron_volume_sign( tetrahedron ) == SIDE::negative;
88+
}
89+
return mesh_.polyhedron_volume( polyhedron_id ) < 0;
90+
}
91+
7092
private:
7193
const SolidMesh< dimension >& mesh_;
7294
};

src/geode/inspector/criterion/negative_elements/surface_negative_elements.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <geode/basic/pimpl_impl.hpp>
2828
#include <geode/basic/uuid.hpp>
2929

30+
#include <geode/geometry/basic_objects/triangle.hpp>
31+
#include <geode/geometry/information.hpp>
32+
#include <geode/geometry/sign.hpp>
33+
3034
#include <geode/mesh/core/surface_mesh.hpp>
3135

3236
namespace geode
@@ -41,7 +45,7 @@ namespace geode
4145
{
4246
for( const auto polygon_id : Range{ mesh_.nb_polygons() } )
4347
{
44-
if( mesh_.polygon_area( polygon_id ) < 0 )
48+
if( polygon_has_negative_area( polygon_id ) )
4549
{
4650
return true;
4751
}
@@ -54,7 +58,7 @@ namespace geode
5458
InspectionIssues< index_t > wrong_polygons{ "Negative Polygons." };
5559
for( const auto polygon_id : Range{ mesh_.nb_polygons() } )
5660
{
57-
if( mesh_.polygon_area( polygon_id ) < 0 )
61+
if( polygon_has_negative_area( polygon_id ) )
5862
{
5963
wrong_polygons.add_issue( polygon_id,
6064
absl::StrCat( "Polygon ", polygon_id, " of Surface ",
@@ -64,6 +68,21 @@ namespace geode
6468
return wrong_polygons;
6569
}
6670

71+
private:
72+
bool polygon_has_negative_area( index_t polygon_id ) const
73+
{
74+
if( mesh_.nb_polygon_vertices( polygon_id ) == 4 )
75+
{
76+
Triangle< dimension > triangle{
77+
mesh_.point( mesh_.polygon_vertex( { polygon_id, 0 } ) ),
78+
mesh_.point( mesh_.polygon_vertex( { polygon_id, 1 } ) ),
79+
mesh_.point( mesh_.polygon_vertex( { polygon_id, 2 } ) )
80+
};
81+
return triangle_area_sign( triangle ) == SIDE::negative;
82+
}
83+
return mesh_.polygon_area( polygon_id ) < 0;
84+
}
85+
6786
private:
6887
const SurfaceMesh< dimension >& mesh_;
6988
};

0 commit comments

Comments
 (0)