ZLab.Discrete ZLab.Discrete
ZLab.Discrete ZLab.Discrete
Developed by Zeke Zhang

Search Results for

    Edit this page

    Method TryGetLinearIndex

    | Edit this page View Source

    TryGetLinearIndex((int x, int y, int z), out int)

    Converts a 3D grid index to a flat array index.

    Declaration
    public bool TryGetLinearIndex((int x, int y, int z) index, out int linear)
    Parameters
    Type Name Description
    (int x, int y, int z) index

    The 3D index (x, y, z) to convert.

    int linear

    Output flat array index.

    Returns
    Type Description
    bool

    True if successful.

    Remarks

    Use this method to map 3D indices to a 1D array for internal storage. Example:

    public Color GetValue((int x, int y, int z) index)
    {
        if (!TryGetLinearIndex(index, out int linear))
            throw new IndexOutOfRangeException($"Index {index} is out of grid bounds.");
        return _buffer[linear];
    }
    Exceptions
    Type Condition
    IndexOutOfRangeException

    Thrown if the index is out of grid bounds.