1+ /*
2+ * Copyright (c) 2019 - 2022 Geode-solutions
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+ * SOFTWARE.
21+ *
22+ */
23+
24+ #pragma once
25+
26+ #include < geode/basic/uuid.h>
27+
28+ #include < geode/mesh/common.h>
29+
30+ namespace geode
31+ {
32+ struct MeshElement
33+ {
34+ MeshElement ( uuid mesh_id_in, index_t element_id_in )
35+ : mesh_id( std::move( mesh_id_in ) ), element_id( element_id_in )
36+ {
37+ }
38+
39+ bool operator ==( const MeshElement& other ) const
40+ {
41+ return mesh_id == other.mesh_id && element_id == other.element_id ;
42+ }
43+
44+ bool operator !=( const MeshElement& other ) const
45+ {
46+ return mesh_id != other.mesh_id || element_id != other.element_id ;
47+ }
48+
49+ template < typename Archive >
50+ void serialize ( Archive& archive )
51+ {
52+ archive.ext ( *this , DefaultGrowable< Archive, MeshElement >{},
53+ []( Archive& a, MeshElement& mesh_element ) {
54+ a.object ( mesh_element.mesh_id );
55+ a.value4b ( mesh_element.element_id );
56+ } );
57+ }
58+
59+ uuid mesh_id;
60+ index_t element_id;
61+
62+ private:
63+ friend class bitsery ::Access;
64+ MeshElement () = default ;
65+ };
66+
67+ struct MeshVertex : public MeshElement
68+ {
69+ using MeshElement::MeshElement;
70+ };
71+
72+ struct MeshEdge : public MeshElement
73+ {
74+ using MeshElement::MeshElement;
75+ };
76+
77+ struct MeshPolygon : public MeshElement
78+ {
79+ using MeshElement::MeshElement;
80+ };
81+ } // namespace geode
82+
83+ namespace std
84+ {
85+ template <>
86+ struct hash < geode::MeshElement >
87+ {
88+ public:
89+ size_t operator ()( const geode::MeshElement& mesh_element ) const
90+ {
91+ return absl::Hash< geode::uuid >()( mesh_element.mesh_id )
92+ ^ absl::Hash< geode::index_t >()( mesh_element.element_id );
93+ }
94+ };
95+ } // namespace std
0 commit comments