// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2025 lacklustr@protonmail.com https://github.com/eadf

#![deny(
    rust_2018_compatibility,
    rust_2018_idioms,
    nonstandard_style,
    unused,
    future_incompatible,
    non_camel_case_types,
    unused_parens,
    non_upper_case_globals,
    unused_qualifications,
    unused_results,
    unused_imports,
    unused_variables,
    bare_trait_objects,
    ellipsis_inclusive_range_patterns,
    elided_lifetimes_in_paths
)]
#![allow(uncommon_codepoints)]

//! # `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()?;
//! ```
mod bvh;
mod common;
mod corner_table;
mod isotropic_remesh;
mod util;

pub mod prelude {
    pub use crate::common::remesh_error::RemeshError;
    pub use crate::isotropic_remesh::common::IsotropicRemesh;
    pub use crate::isotropic_remesh::{CollapseStrategy, FlipStrategy, SplitStrategy};
}
