1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
//! Polygon mesh data structures for storing connectivity information
//! (the "core" of a mesh).
//!
//! This module contains different data structures for the representation of
//! triangle or polygon meshes, as well as traits for abstracting over them.
//! Note that these data structures are *only* concerned with connectivity
//! information and cannot store additional properties, like face normals or
//! even vertex positions. Use [prop maps][crate::map] for that purpose.
//!
//!
//! # Introduction
//!
//! To algorithmically work with polygon meshes, we need a way to represent the
//! meshes. Usually, we require certain adjacency information from the mesh to
//! do something with it. As the most basic example, if we want to render a
//! triangle mesh, we usually iterate over all faces and then need to obtain
//! the three vertices of that face. But more advanced algorithms require all
//! kinds of adjacency information about a mesh, like for example: "all faces
//! around this vertex", "is this face on a boundary?" and "what is the valence
//! of this vertex?"
//!
//! To answer these questions, the mesh data structure has to store and
//! maintain some kind of adjacency information. Unfortunately, the more
//! adjacency information we store, the slower the data structure becomes and
//! the more memory it consumes. Thus, existing data structures roughly fall on
//! a spectrum from "small and fast, but not powerful" to "large and slower,
//! but powerful".
//!
//! For each situation, you should use the fastest data structure that is able
//! to satisfy all your algorithmic requirements. For example, if you only want
//! to render triangle meshes, it does not make sense to use a complex half
//! edge mesh. The mesh traits abstract over the different capabilities of the
//! different data structures.
//!
//!
//! # Available data structures
//!
//! The following table shows the data structures that are currently implemented
//! in `lox`. Refer to their documentation to learn more about how these data
//! structures work internall.
//!
//!
//! | Name | Memory | Face kind | [`BasicAdj`] | [`FullAdj`] | [`EdgeAdj`] | [`EdgeMesh`] |
//! | ------------ | ------ | --------- | ------------ | ----------- | ----------- | ------------ |
//! | [`SharedVertexMesh`] | 24 | Triangles | ✅ | ❌ | ❌ | ❌ |
//! | [`DirectedEdgeMesh`] | 52 – 100 | Triangles | ✅ | ✅ | ❌ | ❌ |
//! | [`HalfEdgeMesh`] | 84 – 108 | *configurable* | ✅ | ✅ | ✅ | ✅ |
//!
//!
//! *Note about the "memory" column*: this value is given in bytes and is
//! calculated assuming that handles have a size of 4 bytes (which is the case
//! without the `large-handle` feature). Furthermore, the value represents the
//! memory usage per vertex in a standard triangle mesh. In such a typical
//! triangle mesh, the number of faces is roughly equal to twice the number of
//! vertices; there are also roughly three times as many edges than vertices.
//! As such, the memory value is calculated as `⟨bytes per vertex⟩ + 2 ⋅ ⟨bytes
//! per face⟩ + 3 ⋅ ⟨bytes per full edge⟩`. A range is given if the mesh has
//! optional fields.
//!
//! More data structures will be added in the future.
//!
//!
//! # Compile time configurations
//!
//! Many data structures can be configured at compile time. Some allow you to
//! enable or disable optional fields. Enabling these fields increases memory
//! consumption, but can speed up certain operations.
//!
//! Other configurations allow you to decide what mesh features the data
//! structure supports. For example, the `HalfEdgeMesh` can be configured to
//! only support triangular faces *or* to support mixed faces of arbitrary
//! valence. Only supporting triangular meshes speeds up some operations.
//!
//! The configuration is done at compile time by passing it as a generic
//! parameter. That parameter is a type that implements the `Config` trait of
//! that particular data structure. In order to create your own configuration,
//! create a new enum type without any variants (e.g. `enum MyConfig {}`) and
//! then implement `Config` for it.
//!
//!
//! # Mesh Traits
//!
//! There are various traits that describe different capabilities of mesh data
//! structures. The most important ones are the three basic ones [`Mesh`],
//! [`MeshMut`] and [`EdgeMesh`], plus the three adjacency-related ones
//! [`BasicAdj`], [`FullAdj`] and [`EdgeAdj`]. These six traits are connected
//! via super trait bounds like so:
//!
//! ```text
//! ┌──────── EdgeMesh ◄─────────────────────┐
//! │ │
//! ▼ │
//! Mesh ◄──── BasicAdj ◄──── FullAdj ◄──── EdgeAdj
//! ▲
//! │
//! └──────── MeshMut
//! ```
//!
//! Further, there are:
//!
//! - [`PolyMesh`] and [`TriMesh`] are trait aliases/shorthands for `Mesh` with
//! a fixed [`FaceKind`][Mesh::FaceKind].
//! - [`Orientable`] and [`NonOrientable`] are trait aliases/shorthands for
//! `Mesh` with a fixed [`Orientable`][Mesh::Orientable] value.
//! - [`SupportsMultiBlade`] is a marker trait for data structures that support
//! multi fan-blade vertices.
//!
use crate::;
pub use ;
pub use Checked;
// ===========================================================================
// ===== `FaceKind`
// ===========================================================================
/// A kind of faces a mesh data structure can store. Either [`TriFaces`] or
/// [`PolyFaces`].
///
/// This is a sealed trait, meaning you cannot implement it for your own types.
/// This library provides exactly two types that implement this trait.
/// Only triangular faces are supported.
/// Arbitrary polygons are allowed as faces.
// ===========================================================================
// ===== Iterators over handles and refs
// ===========================================================================
/// An iterator over the handles of the elements of a mesh. Yields handles with
/// increasing index value.
///
/// Instances of this type are returned by:
/// - [`Mesh::vertex_handles`]
/// - [`Mesh::face_handles`]
/// - [`Mesh::edge_handles`]
impl_handle_iter!;
impl_handle_iter!;
impl_handle_iter!;
/// An iterator over the handles of the elements of a mesh. Yields handles with
/// increasing index value. Can give mutable access to the underlying mesh.
///
/// Note that using this iterator is a bit tricky and you have to pay attention
/// to not shoot yourself in the foot. This iterator iterates through all
/// existing element handles from handle index 0 to the initial
/// `self.last_{element}_handle` (that is: what this method returned when this
/// iterator was created). That means that:
///
/// - Adding new elements with a handle higher than the "initial last handle"
/// won't affect the iteration.
/// - Adding or removing elements with handle indices lower than the handle
/// that was last yielded by this iterator, won't affect the iteration.
/// - Adding or removing elements with handle indices higher than the handle
/// last yielded by this iterator but smaller than the "initial last handle"
/// *will* affect the iteration. You should avoid doing that.
impl_handle_iter_mut!;
impl_handle_iter_mut!;
impl_handle_iter_mut!;
/// An iterator over elements of a mesh. Yields elements with increasing handle
/// index value.
///
/// Instances of this type are returned by:
/// - [`Mesh::vertices`]
/// - [`Mesh::faces`]
/// - [`Mesh::edges`]
impl_element_iter!;
impl_element_iter!;
impl_element_iter!;
// ===========================================================================
// ===== Other stuff
// ===========================================================================
/// Utility struct, return type of [`MeshMut::split_edge_with_faces`].