Skip to content

Commit be410e1

Browse files
Merge pull request #1158 from Geode-solutions/fix/update_polygon_sign_info
fix(polygon_sign): Updated code now that polygons are available as ba…
2 parents dea2692 + 0b2c099 commit be410e1

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

include/geode/geometry/sign.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
namespace geode
2929
{
3030
FORWARD_DECLARATION_DIMENSION_CLASS( Triangle );
31+
FORWARD_DECLARATION_DIMENSION_CLASS( Polygon );
3132
ALIAS_2D_AND_3D( Triangle );
33+
ALIAS_2D( Polygon );
3234
class Tetrahedron;
3335
enum struct SIDE;
3436
using Sign = SIDE;
@@ -48,6 +50,9 @@ namespace geode
4850
[[nodiscard]] Sign opengeode_geometry_api triangle_area_sign(
4951
const Triangle2D& triangle );
5052

53+
[[nodiscard]] Sign opengeode_geometry_api polygon_area_sign(
54+
const Polygon2D& polygon );
55+
5156
/*!
5257
* Return the sign of a 3D triangle area aligned on X- Y- or Z-axis.
5358
*/

src/geode/geometry/sign.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <geode/geometry/sign.hpp>
2525

26+
#include <geode/geometry/basic_objects/polygon.hpp>
2627
#include <geode/geometry/basic_objects/tetrahedron.hpp>
2728
#include <geode/geometry/basic_objects/triangle.hpp>
2829
#include <geode/geometry/internal/position_from_sides.hpp>
@@ -53,6 +54,24 @@ namespace geode
5354
GEO::PCK::orient_2d( vertices[0], vertices[1], vertices[2] ) );
5455
}
5556

57+
Sign polygon_area_sign( const Polygon2D& polygon )
58+
{
59+
const auto& polygon_vertices = polygon.vertices();
60+
const auto& p1 = polygon_vertices[0];
61+
for( const auto other_index : LRange{ 1, polygon_vertices.size() - 1 } )
62+
{
63+
const auto& p2 = polygon_vertices[other_index];
64+
const auto& p3 = polygon_vertices[static_cast< local_index_t >(
65+
other_index + 1 )];
66+
const auto sign = triangle_area_sign( { p1, p2, p3 } );
67+
if( sign != Sign::zero )
68+
{
69+
return sign;
70+
}
71+
}
72+
return geode::Sign::zero;
73+
}
74+
5675
Sign triangle_area_sign( const Triangle3D& triangle, local_index_t axis )
5776
{
5877
const auto axis1 = new_axis[axis][0];

src/geode/mesh/helpers/repair_polygon_orientations.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <geode/basic/logger.hpp>
3131

32+
#include <geode/geometry/basic_objects/polygon.hpp>
3233
#include <geode/geometry/basic_objects/triangle.hpp>
3334
#include <geode/geometry/information.hpp>
3435
#include <geode/geometry/sign.hpp>
@@ -143,31 +144,13 @@ namespace
143144
geode::Sign::zero };
144145
for( const auto polygon_id : geode::Range{ mesh.nb_polygons() } )
145146
{
146-
const auto& p1 =
147-
mesh.point( mesh.polygon_vertex( { polygon_id, 0 } ) );
148-
for( const auto i :
149-
geode::LRange{ 1, mesh.nb_polygon_vertices( polygon_id ) - 1 } )
147+
area_sign_info.area_sign[polygon_id] =
148+
geode::polygon_area_sign( mesh.polygon( polygon_id ) );
149+
if( area_sign_info.area_sign[polygon_id] == geode::Sign::negative )
150150
{
151-
const auto& p2 =
152-
mesh.point( mesh.polygon_vertex( { polygon_id, i } ) );
153-
const auto& p3 = mesh.point( mesh.polygon_vertex( { polygon_id,
154-
static_cast< geode::local_index_t >( i + 1 ) } ) );
155-
const auto sign = geode::triangle_area_sign( { p1, p2, p3 } );
156-
if( sign == geode::Sign::positive )
157-
{
158-
area_sign_info.area_sign[polygon_id] =
159-
geode::Sign::positive;
160-
break;
161-
}
162-
if( sign == geode::Sign::negative )
163-
{
164-
area_sign_info.area_sign[polygon_id] =
165-
geode::Sign::negative;
166-
area_sign_info.nb_bad_polygons++;
167-
break;
168-
}
151+
area_sign_info.nb_bad_polygons++;
169152
}
170-
if( area_sign_info.area_sign[polygon_id] == geode::Sign::zero )
153+
else if( area_sign_info.area_sign[polygon_id] == geode::Sign::zero )
171154
{
172155
area_sign_info.queue.emplace( polygon_id );
173156
}

tests/mesh/test-repair-polygon-orientations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ void test()
163163
auto wrong_surface = build_bad_orientation_surface();
164164
wrong_surface->enable_edges();
165165
const auto edges_before = get_edges( *wrong_surface );
166-
geode::repair_polygon_orientations( *wrong_surface );
166+
auto builder = geode::SurfaceMeshBuilder2D::create( *wrong_surface );
167+
geode::repair_polygon_orientations( *wrong_surface, *builder );
167168
check_repaired_surface( *wrong_surface );
168169
const auto edges_after = get_edges( *wrong_surface );
169170
compare_edges( edges_before, edges_after );

0 commit comments

Comments
 (0)