use super::Surface;
use crate::containers::mesh::Mesh;
use crate::error::{PyrucastError, Result};
use crate::ops::mesh::paving::smooth::{self, Incidence, Patch, Rule};
pub fn regularize(mesh: &Mesh, sweeps: usize, angular: bool, in_place: bool) -> Result<Mesh> {
let mut surf = Surface::read(mesh, "regularize")?;
if surf.pinned() == surf.pts.len() {
return Err(PyrucastError::Message(
"regularize: every node is on the boundary — there is nothing to move. A mesh one \
cell deep has no interior; refine it first."
.into(),
));
}
let patch = Patch {
quads: &surf.quads,
tris: &surf.tris,
movable: &surf.movable,
};
let inc = Incidence::build(&patch, surf.pts.len());
let rule = if angular {
Rule::Angular
} else {
Rule::Laplacian
};
smooth::smooth_with(&mut surf.pts, &patch, &inc, None, sweeps, rule);
if in_place {
surf.write_positions(mesh)
} else {
surf.to_mesh("regularize")
}
}