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
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2025 lacklustr@protonmail.com https://github.com/eadf
//! # `remesh`
//!
//! A type-agnostic isotropic remeshing library for triangle meshes.
//!
//! `remesh` provides mesh refinement with a flexible, builder-style API that works
//! seamlessly with *any* vertex type—whether you're using `glam`, `nalgebra`, `cgmath`
//! or your own custom types.
//!
//! ## Features
//!
//! - **Type-agnostic**: Works with any vertex format convertible to/from `[S; 3]`
//! - **High precision**: Supports both `f32` and `f64` scalar types: `S`
//! - **Ergonomic API**: Builder pattern with sensible defaults
//!
//! ## Quick Start
//!
//! ```rust
//! use remesh::prelude::*;
//!
//! let vertices = vec![
//! [0.0, 0.0, 0.0],
//! [0.0, 0.0, 1.0],
//! [0.0, 0.5, 0.0],
//! [1.0, 0.0, 0.0],
//! [0.5, 0.0, 0.5],
//! ];
//!
//! let indices = vec![0, 1, 2, 1, 4, 2, 2, 3, 0, 1, 0, 4, 2, 4, 3, 0, 3, 4];
//!
//! // Remesh with a target edge length of 0.7
//! let (result_vertices, result_indices) = IsotropicRemesh::<f64, _>::new(&vertices, &indices)?
//! .with_target_edge_length(0.7)?
//! .with_default_collapse_edges()?
//! .run(10)?;
//! # Ok::<(), RemeshError>(())
//! ```
//! ### Use with third party vertex types:
//! ```rust
//! # use vector_traits::glam;
//! use remesh::prelude::*;
//!
//! let vertices = vec![
//! glam::vec3(0.0, 0.0, 0.0),
//! glam::vec3(0.0, 0.0, 1.0),
//! glam::vec3(0.0, 0.5, 0.0),
//! glam::vec3(1.0, 0.0, 0.0),
//! glam::vec3(0.5, 0.0, 0.5),
//! ];
//!
//! let indices = vec![0, 1, 2, 1, 4, 2, 2, 3, 0, 1, 0, 4, 2, 4, 3, 0, 3, 4];
//!
//! let (result_vertices, result_indices) = IsotropicRemesh::<f32, _>::new(&vertices, &indices)?
//! .with_target_edge_length(0.5)?
//! .with_default_flip_edges()?
//! .run(20)?;
//! # Ok::<(), RemeshError>(())
//! ```
//!
//!
//! ### Available Operations
//!
//! - **Edge splitting**: Subdivide long edges (controlled by `target_edge_length`*`split_multiplier`)
//! - **Edge collapsing**: Merge short edges (controlled by `target_edge_length`*`collapse_multiplier`)
//! - **Edge flipping**: Improve triangle quality (via `flip_edges`)
//! - **Vertex smoothing**: Smooth vertex positions (via `smooth_weight`)
//!
//! ## Working with Different Math Libraries
//!
//! The library internally uses `glam` for computations but preserves your original vertex type in the results:
//!
//! ```rust,ignore
//! use remesh::prelude::*;
//! // Works with glam
//! let verts: Vec<glam::Vec3> = vec![/* ... */];
//! let (out_verts, indices) = IsotropicRemesh::<f32, _>::new(&verts, &indices)?.run()?;
//!
//! // Works with nalgebra
//! let verts: Vec<nalgebra::Vector3<f64>> = vec![/* ... */];
//! let (out_verts, indices) = IsotropicRemesh::<f64, _>::new(&verts, &indices)?.run()?;
//!
//! // Works with custom types or any other type that implements `From<[S; 3]>` and `Into<[S; 3]>`
//! #[derive(Copy, Clone)]
//! struct MyVec3 { x: f32, y: f32, z: f32 }
//! impl From<[f32; 3]> for MyVec3 { /* ... */ }
//! impl Into<[f32; 3]> for MyVec3 { /* ... */ }
//!
//! let vertices: Vec<MyVec3> = vec![/* ... */];
//! let (out_vertices, out_indices):(Vec<MyVec3>,Vec<usize>) = IsotropicRemesh::<f32, _>::new(&vertices, &indices)?.run()?;
//! ```