tritet 3.1.0

Triangle and tetrahedron mesh generators
Documentation
use crate::StrError;

pub(crate) const TRITET_SUCCESS: i32 = 0;

pub(crate) const TRITET_ERROR_NULL_DATA: i32 = 10;
pub(crate) const TRITET_ERROR_STRING_CONCAT: i32 = 20;

pub(crate) const TRITET_ERROR_NULL_POINT_LIST: i32 = 100;
pub(crate) const TRITET_ERROR_NULL_SEGMENT_LIST: i32 = 200;
pub(crate) const TRITET_ERROR_NULL_FACET_LIST: i32 = 300;
pub(crate) const TRITET_ERROR_NULL_FACET_POLYGON_LIST: i32 = 400;
pub(crate) const TRITET_ERROR_NULL_REGION_LIST: i32 = 500;
pub(crate) const TRITET_ERROR_NULL_HOLE_LIST: i32 = 600;

pub(crate) const TRITET_ERROR_INVALID_POINT_INDEX: i32 = 1000;
pub(crate) const TRITET_ERROR_INVALID_SEGMENT_INDEX: i32 = 2000;
pub(crate) const TRITET_ERROR_INVALID_SEGMENT_POINT_ID: i32 = 3000;
pub(crate) const TRITET_ERROR_INVALID_FACET_INDEX: i32 = 4000;
pub(crate) const TRITET_ERROR_INVALID_FACET_NUM_POLYGON: i32 = 5000;
pub(crate) const TRITET_ERROR_INVALID_FACET_POINT_INDEX: i32 = 6000;
pub(crate) const TRITET_ERROR_INVALID_FACET_POINT_ID: i32 = 7000;
pub(crate) const TRITET_ERROR_INVALID_REGION_INDEX: i32 = 8000;
pub(crate) const TRITET_ERROR_INVALID_HOLE_INDEX: i32 = 9000;

pub(crate) const TRITET_ERROR_TETGEN_FAIL: i32 = 10000;

pub(crate) fn handle_status(status: i32) -> Result<(), StrError> {
    if status == TRITET_SUCCESS {
        return Ok(());
    }

    if status == TRITET_ERROR_NULL_DATA {
        return Err("INTERNAL ERROR: found NULL data");
    }
    if status == TRITET_ERROR_STRING_CONCAT {
        return Err("INTERNAL ERROR: cannot write string with commands for TetGen");
    }

    if status == TRITET_ERROR_NULL_POINT_LIST {
        return Err("INTERNAL ERROR: found NULL point list");
    }
    if status == TRITET_ERROR_NULL_SEGMENT_LIST {
        return Err("INTERNAL ERROR: found NULL segment list");
    }
    if status == TRITET_ERROR_NULL_FACET_LIST {
        return Err("INTERNAL ERROR: found NULL facet list");
    }
    if status == TRITET_ERROR_NULL_FACET_POLYGON_LIST {
        return Err("INTERNAL ERROR: found NULL facet polygon list");
    }
    if status == TRITET_ERROR_NULL_REGION_LIST {
        return Err("INTERNAL ERROR: found NULL region list");
    }
    if status == TRITET_ERROR_NULL_HOLE_LIST {
        return Err("INTERNAL ERROR: found NULL hole list");
    }

    if status == TRITET_ERROR_INVALID_POINT_INDEX {
        return Err("index of point is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_SEGMENT_INDEX {
        return Err("index of segment is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_SEGMENT_POINT_ID {
        return Err("id of segment point is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_FACET_INDEX {
        return Err("index of facet is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_FACET_NUM_POLYGON {
        return Err("INTERNAL ERROR: found invalid facet number of polygon");
    }
    if status == TRITET_ERROR_INVALID_FACET_POINT_INDEX {
        return Err("index of facet point is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_FACET_POINT_ID {
        return Err("id of facet point is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_REGION_INDEX {
        return Err("index of region is out of bounds");
    }
    if status == TRITET_ERROR_INVALID_HOLE_INDEX {
        return Err("index of hole is out of bounds");
    }

    if status == TRITET_ERROR_TETGEN_FAIL {
        return Err("TetGen failed: points are probably coplanar");
    }

    return Err("INTERNAL ERROR: some error occurred");
}

/// Maps indices used in this library (tritet) to indices used in Triangle
///
/// ```text
/// This library (tritet)      Triangle
///         NODES               CORNERS
///           2                    2
///          / \                  / \
///         /   \                /   \
///        5     4              4     3
///       /       \            /       \
///      /         \          /         \
///     0-----3-----1        0-----5-----1
/// ```
pub(crate) const TRITET_TO_TRIANGLE: [usize; 6] = [0, 1, 2, 5, 3, 4];

/// Maps indices used in this library (tritet) to indices used in Tetgen
///
/// ```text
///       This library (tritet)                          Tetgen
///               NODES                                  CORNERS
///             |                                         |
///             3                                         3
///            /|`.                                      /|`.
///            ||  `,                                    ||  `,
///           / |    ',                                 / |    ',
///           | |      \                                | |      \
///          /  |       `.                             /  |       `.
///          |  |         `,                           |  |         `,
///         /   7            9                        /   5            4
///         |   |             \                       |   |             \
///        /    |              `.                    /    |              `.
///        |    |                ',                  |    |                ',
///       8     |                  \                8     |                  \
///       |     0 ,,_               `.              |     0 ,,_               `.
///      |     /     ``'-., 6         `.           |     /     ``'-., 9         `.
///      |    /               `''-.,,_  ',         |    /               `''-.,,_  ',
///     |    /                        ``'2 ,,     |    /                        ``'2 ,,
///     |   '                       ,.-``         |   '                       ,.-``
///    |   4                   _,-'`             |   6                   _,-'`
///    ' /                 ,.'`                  ' /                 ,.'`
///   | /             _ 5 `                     | /             _ 7 `
///   '/          ,-'`                          '/          ,-'`
///  |/      ,.-``                             |/      ,.-``
///  /  _,-``                                  /  _,-``
/// 1 '`                                      1 '`
/// ```
pub(crate) const TRITET_TO_TETGEN: [usize; 10] = [0, 1, 2, 3, 6, 7, 9, 5, 8, 4];

/// Defines a set of "light" colors
pub(crate) const LIGHT_COLORS: [&'static str; 17] = [
    "#cbe4f9", "#cdf5f6", "#eff9da", "#f9ebdf", "#f9d8d6", "#d6cdea", "#acddde", "#caf1de", "#e1f8dc", "#fef8dd",
    "#ffe7c7", "#f7d8ba", "#d0fffe", "#fffddb", "#e4ffde", "#ffd3fd", "#ffe7d3",
];

/// Defines a set of "dark" colors
pub(crate) const DARK_COLORS: [&'static str; 12] = [
    "#2e3d7c", "#282528", "#ba292e", "#e15d3a", "#ffa73c", "#780000", "#540d4d", "#214b14", "#a36032", "#0f4539",
    "#2f3b22", "#152d32",
];

/// Sets the VTK code corresponding to triangles
pub(crate) const VTK_TRIANGLE: i32 = 5;

/// Sets the VTK code corresponding to quadratic triangles
pub(crate) const VTK_QUADRATIC_TRIANGLE: i32 = 22;

/// Sets the VTK code corresponding to tetrahedra
pub(crate) const VTK_TETRA: i32 = 10;

/// Sets the VTK code corresponding to quadratic tetrahedra
pub(crate) const VTK_QUADRATIC_TETRA: i32 = 24;