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

use crate::corner_table::{CornerIndex, TriangleIndex};
use std::fmt::Debug;
impl Debug for TriangleIndex {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        if self.is_valid() {
            write!(f, "T{}", self.0)
        } else {
            write!(f, "T∅")
        }
    }
}

impl Debug for CornerIndex {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        if self.is_valid() {
            write!(f, "C{}T{}", self.0, self.0 / 3)
        } else {
            write!(f, "C∅")
        }
    }
}

impl From<CornerIndex> for TriangleIndex {
    #[inline(always)]
    fn from(corner: CornerIndex) -> Self {
        corner.triangle()
    }
}

impl From<usize> for TriangleIndex {
    #[inline(always)]
    fn from(index: usize) -> Self {
        Self(index as u32)
    }
}

impl From<TriangleIndex> for usize {
    #[inline(always)]
    fn from(index: TriangleIndex) -> usize {
        index.0 as usize
    }
}
