|
24 | 24 | #include <geode/basic/assert.h> |
25 | 25 | #include <geode/basic/logger.h> |
26 | 26 |
|
| 27 | +#include <geode/model/helpers/detail/mappings_merger.h> |
27 | 28 | #include <geode/model/mixin/core/corner.h> |
28 | 29 | #include <geode/model/mixin/core/line.h> |
29 | 30 | #include <geode/model/mixin/core/surface.h> |
@@ -179,6 +180,59 @@ void test_components_mapping() |
179 | 180 | } |
180 | 181 | } |
181 | 182 |
|
| 183 | +void test_merge_mappings() |
| 184 | +{ |
| 185 | + std::vector< geode::uuid > uuids_in( 3 ); |
| 186 | + std::vector< geode::uuid > uuids_mid( 3 ); |
| 187 | + std::vector< geode::uuid > uuids_out( 3 ); |
| 188 | + |
| 189 | + geode::ModelGenericMapping generic_mapping; |
| 190 | + geode::GenericMapping< geode::uuid > first_mapping; |
| 191 | + for( const auto i : geode::LRange{ 3 } ) |
| 192 | + { |
| 193 | + for( const auto j : geode::Range{ i, 3 } ) |
| 194 | + { |
| 195 | + first_mapping.map( uuids_in[i], uuids_mid[j] ); |
| 196 | + } |
| 197 | + } |
| 198 | + generic_mapping.emplace( |
| 199 | + geode::Corner3D::component_type_static(), std::move( first_mapping ) ); |
| 200 | + |
| 201 | + geode::ModelCopyMapping copy_mapping; |
| 202 | + geode::BijectiveMapping< geode::uuid > second_mapping; |
| 203 | + for( const auto i : geode::LRange{ 3 } ) |
| 204 | + { |
| 205 | + second_mapping.map( uuids_mid[i], uuids_out[i] ); |
| 206 | + } |
| 207 | + copy_mapping.emplace( |
| 208 | + geode::Corner3D::component_type_static(), std::move( second_mapping ) ); |
| 209 | + |
| 210 | + const auto merged_mapping = |
| 211 | + geode::detail::merge_mappings( generic_mapping, copy_mapping ); |
| 212 | + OPENGEODE_EXCEPTION( !merged_mapping.has_mapping_type( |
| 213 | + geode::Surface3D::component_type_static() ), |
| 214 | + "[Test] Generic mappings should not exist for Surfaces" ); |
| 215 | + OPENGEODE_EXCEPTION( generic_mapping.has_mapping_type( |
| 216 | + geode::Corner3D::component_type_static() ), |
| 217 | + "[Test] Generic mappings should exist for Corners" ); |
| 218 | + const auto& corner_merged_mappings = |
| 219 | + merged_mapping.at( geode::Corner3D::component_type_static() ); |
| 220 | + OPENGEODE_EXCEPTION( corner_merged_mappings.size_in() == 3, |
| 221 | + "[Test] Wrong size for CopyMapping Corners in" ); |
| 222 | + OPENGEODE_EXCEPTION( corner_merged_mappings.size_out() == 3, |
| 223 | + "[Test] Wrong size for CopyMapping Corners out" ); |
| 224 | + for( const auto i : geode::LRange{ 3 } ) |
| 225 | + { |
| 226 | + OPENGEODE_EXCEPTION( corner_merged_mappings.in2out( uuids_in[i] ).size() |
| 227 | + == static_cast< geode::index_t >( 3 - i ), |
| 228 | + "[Test] Wrong mapping for CopyMapping Corners (in2out)" ); |
| 229 | + OPENGEODE_EXCEPTION( |
| 230 | + corner_merged_mappings.out2in( uuids_out[i] ).size() |
| 231 | + == static_cast< geode::index_t >( i + 1 ), |
| 232 | + "[Test] Wrong mapping for CopyMapping Corners (out2in)" ); |
| 233 | + } |
| 234 | +} |
| 235 | + |
182 | 236 | void test() |
183 | 237 | { |
184 | 238 | test_copy_mapping(); |
|
0 commit comments