diff --git a/.clang-tidy b/.clang-tidy index b0398498e..566fa5b22 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,7 +19,8 @@ Checks: > -readability-use-anyofallof, -readability-redundant-access-specifiers, -readability-convert-member-functions-to-static, - -cppcoreguidelines-avoid-const-or-ref-data-members + -cppcoreguidelines-avoid-const-or-ref-data-members, + -cppcoreguidelines-pro-bounds-constant-array-index CheckOptions: - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic diff --git a/include/geode/basic/mapping.hpp b/include/geode/basic/mapping.hpp index fb520cb3b..afbfa8dd1 100644 --- a/include/geode/basic/mapping.hpp +++ b/include/geode/basic/mapping.hpp @@ -23,7 +23,8 @@ #pragma once -#include +#include +#include #include #include @@ -39,7 +40,7 @@ namespace geode template < typename T > using Storage = typename StorageType< T >::Type; - void reserve( index_t capacity ) + [[deprecated]] void reserve( index_t capacity ) { in2out_.reserve( capacity ); out2in_.reserve( capacity ); @@ -71,13 +72,13 @@ namespace geode return out2in_.at( out ); } - [[nodiscard]] const absl::flat_hash_map< T1, Storage< T2 > >& + [[nodiscard]] const absl::btree_map< T1, Storage< T2 > >& in2out_map() const { return in2out_; } - [[nodiscard]] const absl::flat_hash_map< T2, Storage< T1 > >& + [[nodiscard]] const absl::btree_map< T2, Storage< T1 > >& out2in_map() const { return out2in_; @@ -100,19 +101,19 @@ namespace geode return static_cast< index_t >( out2in_.size() ); } - [[nodiscard]] absl::flat_hash_map< T1, Storage< T2 > >& in2out_mapping() + [[nodiscard]] absl::btree_map< T1, Storage< T2 > >& in2out_mapping() { return in2out_; } - [[nodiscard]] absl::flat_hash_map< T2, Storage< T1 > >& out2in_mapping() + [[nodiscard]] absl::btree_map< T2, Storage< T1 > >& out2in_mapping() { return out2in_; } private: - absl::flat_hash_map< T1, Storage< T2 > > in2out_; - absl::flat_hash_map< T2, Storage< T1 > > out2in_; + absl::btree_map< T1, Storage< T2 > > in2out_; + absl::btree_map< T2, Storage< T1 > > out2in_; }; template < typename T > @@ -225,6 +226,10 @@ namespace geode } auto& out_map = this->out2in_mapping().at( out ); const auto itr2 = absl::c_find( out_map, in ); + if( itr2 == out_map.end() ) + { + return; + } out_map.erase( itr2 ); if( this->out2in( out ).empty() ) { diff --git a/include/geode/model/mixin/core/component_type.hpp b/include/geode/model/mixin/core/component_type.hpp index 41b99333e..0a27d659b 100644 --- a/include/geode/model/mixin/core/component_type.hpp +++ b/include/geode/model/mixin/core/component_type.hpp @@ -84,6 +84,15 @@ namespace geode return type_.get() == other.type_.get() && id_ == other.id_; } + [[nodiscard]] bool operator<( const ComponentID& other ) const + { + if( type_.get() != other.type_.get() ) + { + return type_.get() < other.type_.get(); + } + return id_ < other.id_; + } + [[nodiscard]] std::string string() const { return absl::StrCat( type_.get(), " ", id_.string() ); diff --git a/include/geode/model/mixin/core/vertex_identifier.hpp b/include/geode/model/mixin/core/vertex_identifier.hpp index 5d7e03be3..324408fe9 100644 --- a/include/geode/model/mixin/core/vertex_identifier.hpp +++ b/include/geode/model/mixin/core/vertex_identifier.hpp @@ -57,6 +57,8 @@ namespace geode [[nodiscard]] bool operator==( const ComponentMeshVertex& other ) const; + [[nodiscard]] bool operator<( const ComponentMeshVertex& other ) const; + template < typename Archive > void serialize( Archive& archive ); diff --git a/src/geode/mesh/helpers/convert_surface_mesh.cpp b/src/geode/mesh/helpers/convert_surface_mesh.cpp index 645948cc3..8da322e02 100644 --- a/src/geode/mesh/helpers/convert_surface_mesh.cpp +++ b/src/geode/mesh/helpers/convert_surface_mesh.cpp @@ -23,6 +23,8 @@ #include +#include + #include #include diff --git a/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp b/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp index e458e109a..bde7de751 100644 --- a/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp +++ b/src/geode/mesh/helpers/detail/split_along_solid_facets.cpp @@ -139,7 +139,6 @@ namespace geode ElementsMapping duplicate_points( const SolidInfo& solid_info ) { ElementsMapping vertices_mapping; - vertices_mapping.reserve( solid_.nb_vertices() ); for( const auto vertex_id : Range{ solid_.nb_vertices() } ) { vertices_mapping.map( vertex_id, vertex_id ); diff --git a/src/geode/model/mixin/core/vertex_identifier.cpp b/src/geode/model/mixin/core/vertex_identifier.cpp index 152ca4282..a698b9e5d 100644 --- a/src/geode/model/mixin/core/vertex_identifier.cpp +++ b/src/geode/model/mixin/core/vertex_identifier.cpp @@ -78,6 +78,16 @@ namespace geode return component_id == other.component_id && vertex == other.vertex; } + bool ComponentMeshVertex::operator<( + const ComponentMeshVertex& other ) const + { + if( component_id != other.component_id ) + { + return component_id < other.component_id; + } + return vertex < other.vertex; + } + template < typename Archive > void ComponentMeshVertex::serialize( Archive& archive ) {