Skip to content

Commit 73efd5f

Browse files
committed
fix(VertexCycle): allow comparison of different containers
1 parent 68c768d commit 73efd5f

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

include/geode/mesh/core/detail/vertex_cycle.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ namespace geode
9696
return vertices_;
9797
}
9898

99+
template < typename OtherContainer >
99100
[[nodiscard]] bool is_opposite(
100-
const OrientedVertexCycle& other ) const
101+
const OrientedVertexCycle< OtherContainer >& other ) const
101102
{
102103
const auto& other_vertices = other.vertices();
103104
if( vertices().size() != other_vertices.size()
@@ -117,20 +118,23 @@ namespace geode
117118
return true;
118119
}
119120

121+
template < typename OtherContainer >
120122
[[nodiscard]] bool operator==(
121-
const OrientedVertexCycle& other ) const
123+
const OrientedVertexCycle< OtherContainer >& other ) const
122124
{
123-
return this->vertices() == other.vertices();
125+
return absl::c_equal( this->vertices(), other.vertices() );
124126
}
125127

128+
template < typename OtherContainer >
126129
[[nodiscard]] bool operator!=(
127-
const OrientedVertexCycle& other ) const
130+
const OrientedVertexCycle< OtherContainer >& other ) const
128131
{
129132
return !operator==( other );
130133
}
131134

135+
template < typename OtherContainer >
132136
[[nodiscard]] bool operator<(
133-
const OrientedVertexCycle& other ) const
137+
const OrientedVertexCycle< OtherContainer >& other ) const
134138
{
135139
return this->vertices() < other.vertices();
136140
}

tests/mesh/test-vertex-cycle.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,29 @@ void test_oriented_vertex_cycle()
110110
"[Test] Wrong result for operator!= with cycle5 and cycle7" );
111111
}
112112

113+
void test_several_containers()
114+
{
115+
const geode::detail::VertexCycle< std::vector< geode::index_t > > cycle1{
116+
{ 0, 1, 2, 3 }
117+
};
118+
const geode::detail::VertexCycle< absl::InlinedVector< geode::index_t, 4 > >
119+
cycle2{ { 2, 3, 0, 1 } };
120+
const geode::detail::VertexCycle< std::array< geode::index_t, 3 > > cycle3{
121+
{ 2, 3, 1 }
122+
};
123+
124+
OPENGEODE_EXCEPTION( cycle1 == cycle2,
125+
"[Test] Wrong result for operator== with cycle1 and cycle2" );
126+
OPENGEODE_EXCEPTION( cycle1 != cycle3,
127+
"[Test] Wrong result for operator!= with cycle1 and cycle3" );
128+
}
129+
113130
void test()
114131
{
115132
test_vertex_cycle();
116133
test_oriented_vertex_cycle();
117134
test_single_vertex_cycle();
135+
test_several_containers();
118136
}
119137

120138
OPENGEODE_TEST( "vertex-cycle" )

0 commit comments

Comments
 (0)