dedup_mesh 0.2.0

Deduplicates vertices in a 3d mesh
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2025 lacklustr@protonmail.com https://github.com/eadf

use crate::IndexType;
use std::fmt::Debug;
use std::hash::Hash;

pub trait IndexKernel: Copy + Debug + Eq + Ord + Hash + 'static + Sync + Send {
    const MAX: Self;
    /// SAFETY: In vertex deduplication, indices are remapped, not expanded.
    /// Thus, converting `usize` to `Self` is safe if the input was originally `Self`.
    fn from_usize(value: usize) -> Self;
    fn to_usize(self) -> usize;
}

impl IndexKernel for usize {
    const MAX: usize = usize::MAX;
    #[inline(always)]
    fn from_usize(value: usize) -> Self {
        value
    }

    #[inline(always)]
    fn to_usize(self) -> usize {
        self
    }
}

impl IndexKernel for u32 {
    const MAX: u32 = u32::MAX;
    #[inline(always)]
    fn from_usize(value: usize) -> Self {
        value as u32 // infallible (since input was u32)
    }
    #[inline(always)]
    fn to_usize(self) -> usize {
        self as usize
    }
}

impl IndexKernel for u16 {
    const MAX: u16 = u16::MAX;
    #[inline(always)]
    fn from_usize(value: usize) -> Self {
        value as u16 // infallible (since input was u16)
    }
    #[inline(always)]
    fn to_usize(self) -> usize {
        self as usize
    }
}

impl<T: IndexKernel> IndexType for T {}