Skip to content

Commit

Permalink
Merge pull request #942 from Geode-solutions/fix/missing_cmake_includ…
Browse files Browse the repository at this point in the history
…e_for_merge_mappings

fix(merge_mappings): Added missing cmake include and test.
  • Loading branch information
panquez authored Jun 21, 2024
2 parents 8a5a225 + bc394c5 commit 6d3bf35
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/geode/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_geode_library(
"helpers/surface_radial_sort.cpp"
"helpers/ray_tracing.cpp"
"helpers/detail/build_model_boundaries.cpp"
"helpers/detail/mappings_merger.cpp"
"helpers/detail/split_along_surface_mesh_borders.cpp"
"helpers/detail/split_along_block_mesh_borders.cpp"
"mixin/builder/blocks_builder.cpp"
Expand Down Expand Up @@ -163,6 +164,7 @@ add_geode_library(
"representation/io/geode/geode_section_output.h"
ADVANCED_HEADERS
"helpers/detail/build_model_boundaries.h"
"helpers/detail/mappings_merger.h"
"helpers/detail/split_along_surface_mesh_borders.h"
"helpers/detail/split_along_block_mesh_borders.h"
"mixin/core/detail/components_storage.h"
Expand Down
1 change: 1 addition & 0 deletions src/geode/model/helpers/detail/mappings_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ namespace geode
result.mesh_vertices_mapping.surfaces =
merge_vertex_mappings( mappings1.mesh_vertices_mapping.surfaces,
mappings2.mesh_vertices_mapping.surfaces );
return result;
}
} // namespace detail
} // namespace geode
54 changes: 54 additions & 0 deletions tests/model/test-model-mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <geode/basic/assert.h>
#include <geode/basic/logger.h>

#include <geode/model/helpers/detail/mappings_merger.h>
#include <geode/model/mixin/core/corner.h>
#include <geode/model/mixin/core/line.h>
#include <geode/model/mixin/core/surface.h>
Expand Down Expand Up @@ -179,6 +180,59 @@ void test_components_mapping()
}
}

void test_merge_mappings()
{
std::vector< geode::uuid > uuids_in( 3 );
std::vector< geode::uuid > uuids_mid( 3 );
std::vector< geode::uuid > uuids_out( 3 );

geode::ModelGenericMapping generic_mapping;
geode::GenericMapping< geode::uuid > first_mapping;
for( const auto i : geode::LRange{ 3 } )
{
for( const auto j : geode::Range{ i, 3 } )
{
first_mapping.map( uuids_in[i], uuids_mid[j] );
}
}
generic_mapping.emplace(
geode::Corner3D::component_type_static(), std::move( first_mapping ) );

geode::ModelCopyMapping copy_mapping;
geode::BijectiveMapping< geode::uuid > second_mapping;
for( const auto i : geode::LRange{ 3 } )
{
second_mapping.map( uuids_mid[i], uuids_out[i] );
}
copy_mapping.emplace(
geode::Corner3D::component_type_static(), std::move( second_mapping ) );

const auto merged_mapping =
geode::detail::merge_mappings( generic_mapping, copy_mapping );
OPENGEODE_EXCEPTION( !merged_mapping.has_mapping_type(
geode::Surface3D::component_type_static() ),
"[Test] Generic mappings should not exist for Surfaces" );
OPENGEODE_EXCEPTION( generic_mapping.has_mapping_type(
geode::Corner3D::component_type_static() ),
"[Test] Generic mappings should exist for Corners" );
const auto& corner_merged_mappings =
merged_mapping.at( geode::Corner3D::component_type_static() );
OPENGEODE_EXCEPTION( corner_merged_mappings.size_in() == 3,
"[Test] Wrong size for CopyMapping Corners in" );
OPENGEODE_EXCEPTION( corner_merged_mappings.size_out() == 3,
"[Test] Wrong size for CopyMapping Corners out" );
for( const auto i : geode::LRange{ 3 } )
{
OPENGEODE_EXCEPTION( corner_merged_mappings.in2out( uuids_in[i] ).size()
== static_cast< geode::index_t >( 3 - i ),
"[Test] Wrong mapping for CopyMapping Corners (in2out)" );
OPENGEODE_EXCEPTION(
corner_merged_mappings.out2in( uuids_out[i] ).size()
== static_cast< geode::index_t >( i + 1 ),
"[Test] Wrong mapping for CopyMapping Corners (out2in)" );
}
}

void test()
{
test_copy_mapping();
Expand Down

0 comments on commit 6d3bf35

Please sign in to comment.