File tree Expand file tree Collapse file tree 3 files changed +29
-23
lines changed Expand file tree Collapse file tree 3 files changed +29
-23
lines changed Original file line number Diff line number Diff line change 2828namespace 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 */
Original file line number Diff line number Diff line change 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 ];
Original file line number Diff line number Diff line change @@ -143,31 +143,13 @@ namespace
143143 geode::Sign::zero };
144144 for ( const auto polygon_id : geode::Range{ mesh.nb_polygons () } )
145145 {
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 } )
146+ area_sign_info.area_sign [polygon_id] =
147+ geode::polygon_area_sign ( mesh.polygon ( polygon_id ) );
148+ if ( area_sign_info.area_sign [polygon_id] == geode::Sign::negative )
150149 {
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- }
150+ area_sign_info.nb_bad_polygons ++;
169151 }
170- if ( area_sign_info.area_sign [polygon_id] == geode::Sign::zero )
152+ else if ( area_sign_info.area_sign [polygon_id] == geode::Sign::zero )
171153 {
172154 area_sign_info.queue .emplace ( polygon_id );
173155 }
You can’t perform that action at this time.
0 commit comments