microcad_core/
triangle.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Generic triangle.
5
6/// Triangle
7#[derive(Clone, Copy, Debug)]
8pub struct Triangle<T>(pub T, pub T, pub T);
9
10/// Implementation for indexed triangle.
11impl Triangle<u32> {
12    /// A triangle is generated if it contains any repeated index.
13    pub fn is_degenerated(&self) -> bool {
14        self.0 == self.1 || self.1 == self.2 || self.2 == self.0
15    }
16
17    /// Returns a flipped version of this triangle, by swapping first and third index.
18    pub fn flipped(self) -> Triangle<u32> {
19        Triangle(self.2, self.1, self.0)
20    }
21}