Skip to content

Commit

Permalink
Apply prepare changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BotellaA committed Nov 29, 2024
1 parent 66bb0d7 commit 2303bb6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
32 changes: 31 additions & 1 deletion src/geode/geometry/basic_objects/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ namespace mapbox
} // namespace util
} // namespace mapbox

namespace
{
template < typename PointType >
std::array< std::vector< PointType >, 1 > polygon_points(
const geode::GenericPolygon< PointType, 2 >& polygon )
{
return { { polygon.vertices() } };
}

template < typename PointType >
std::array< absl::FixedArray< geode::Point2D >, 1 > polygon_points(
const geode::GenericPolygon< PointType, 3 >& polygon )
{
const auto& vertices = polygon.vertices();
std::array< absl::FixedArray< geode::Point2D >, 1 > polygons{
absl::FixedArray< geode::Point2D >( vertices.size() )
};
const auto normal =
polygon.normal().value_or( geode::Vector3D{ { 0, 0, 1 } } );
const auto axis_to_remove = normal.most_meaningful_axis();
for( const auto v : geode::LIndices{ vertices } )
{
const geode::Point3D& point = vertices[v];
polygons[0][v] = point.project_point( axis_to_remove );
}
return polygons;
}
} // namespace

namespace geode
{
template < typename PointType, index_t dimension >
Expand Down Expand Up @@ -191,7 +220,8 @@ namespace geode
GenericPolygon< PointType, dimension >::triangulate() const
{
const std::array polygons{ vertices_ };
const auto new_triangles = mapbox::earcut< index_t >( polygons );
const auto new_triangles =
mapbox::earcut< index_t >( polygon_points( *this ) );
const auto nb_new_triangles = new_triangles.size() / 3;
std::vector< std::array< index_t, 3 > > result;
result.reserve( nb_new_triangles );
Expand Down
6 changes: 4 additions & 2 deletions src/geode/mesh/core/surface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,13 @@ namespace geode

public:
Impl( SurfaceMesh& surface )
: polygon_around_vertex_( surface.vertex_attribute_manager()
: polygon_around_vertex_(
surface.vertex_attribute_manager()
.template find_or_create_attribute< VariableAttribute,
PolygonVertex >(
"polygon_around_vertex", PolygonVertex{} ) ),
polygons_around_vertex_( surface.vertex_attribute_manager()
polygons_around_vertex_(
surface.vertex_attribute_manager()
.template find_or_create_attribute< VariableAttribute,
CachedPolygons >(
POLYGONS_AROUND_VERTEX_NAME, CachedPolygons{} ) )
Expand Down

0 comments on commit 2303bb6

Please sign in to comment.