From a51d1c614f22fdd960d0cf83415df85ecfee59ec Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Wed, 29 Jul 2026 10:45:08 +0200 Subject: [PATCH] fix(LightRegularGrid): Added clone function --- .../geode/mesh/core/light_regular_grid.hpp | 2 ++ src/geode/mesh/core/light_regular_grid.cpp | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/geode/mesh/core/light_regular_grid.hpp b/include/geode/mesh/core/light_regular_grid.hpp index 8ef76c03b..c91dc4b68 100644 --- a/include/geode/mesh/core/light_regular_grid.hpp +++ b/include/geode/mesh/core/light_regular_grid.hpp @@ -94,6 +94,8 @@ namespace geode [[nodiscard]] BoundingBox< dimension > bounding_box() const; + [[nodiscard]] LightRegularGrid< dimension > clone() const; + private: friend class bitsery::Access; template < typename Archive > diff --git a/src/geode/mesh/core/light_regular_grid.cpp b/src/geode/mesh/core/light_regular_grid.cpp index b1a664681..030febbdd 100644 --- a/src/geode/mesh/core/light_regular_grid.cpp +++ b/src/geode/mesh/core/light_regular_grid.cpp @@ -195,6 +195,29 @@ namespace geode return this->grid_bounding_box(); } + template < index_t dimension > + LightRegularGrid< dimension > LightRegularGrid< dimension >::clone() const + { + auto origin_position = this->vertex_indices( 0 ); + auto origin = this->grid_point( origin_position ); + std::array< index_t, dimension > cells_number; + std::array< Vector< dimension >, dimension > directions; + for( const auto axis : LRange{ dimension } ) + { + cells_number[axis] = this->nb_cells_in_direction( axis ); + directions[axis] = Vector< dimension >{ origin, + this->grid_point( + this->next_vertex( origin_position, axis ).value() ) }; + } + LightRegularGrid< dimension > clone{ origin, cells_number, directions }; + IdentifierBuilder builder{ clone }; + builder.copy_identifier( *this ); + clone.grid_vertex_attribute_manager().copy( + this->grid_vertex_attribute_manager() ); + clone.cell_attribute_manager().copy( this->cell_attribute_manager() ); + return clone; + } + template < index_t dimension > template < typename Archive > void LightRegularGrid< dimension >::serialize( Archive& serializer )