Class FundamentalRegion
A dither bias matrix whose valid entries are shaped by a parallelogram in a lattice.
[Serializable]
public sealed class FundamentalRegion : ISerializationCallbackReceiver
- Inheritance
-
FundamentalRegion
- Implements
-
ISerializationCallbackReceiver
- Inherited Members
Remarks
The fundamental region is the parallelogram spanned by basis vectors A = (x0, 0) and B = (x1, y1). It contains Count = x0 * y1 lattice points, each with a bias value stored in Matrix. The matrix is sized to the axis-aligned bounding rect of those Count points; positions inside the bounding rect but outside the parallelogram are filled with -1.
Call RecomputeBoundsAndReshape() after changing X0 or Point1 to resize the matrix and recompute the lookup dictionary. RebuildDictionaryIfNeeded() is called automatically before any read that requires the dictionary.
Properties
Count
The number of points in the fundamental region. Equal to x0 * y1.
public int Count { get; }
Property Value
Matrix
Gets the bias matrix. Its size equals the bounding rect of the fundamental region.
public FloatMatrix Matrix { get; }
Property Value
NormalizedValues
Returns a copy of Values with all elements normalized to [0, 1]. If all values are equal the array is filled with zeros. The array is allocated once per size; callers should not retain a reference across frames.
public float[] NormalizedValues { get; }
Property Value
- float[]
Offset
The bounding rect origin of the fundamental region in grid space. Matrix position (mx, my) corresponds to grid point (mx + Offset.x, my + Offset.y).
public Vector2Int Offset { get; }
Property Value
Point1
Gets or sets basis vector B = (x1, y1). The y-component must be positive.
public Vector2Int Point1 { get; set; }
Property Value
Values
Returns an array of Count bias values in fundamental-region index order
(i.e. Values[i] is the bias for the i-th lattice point as enumerated by
IndexToGridPoint(int, int, int, int)). The array is allocated once per size and
filled on every call, so callers should not retain a reference across frames.
public float[] Values { get; }
Property Value
- float[]
X0
Gets or sets the x-component of basis vector A = (x0, 0). Must be positive.
public int X0 { get; set; }
Property Value
Methods
GetIndex(Vector2Int)
Returns the fundamental region index (0..Count-1) for a grid point, or -1 if not in the region.
public int GetIndex(Vector2Int gridPoint)
Parameters
gridPointVector2Int
Returns
IsInFundamentalRegion(Vector2Int)
Returns true if the given grid point is one of the Count fundamental region points.
public bool IsInFundamentalRegion(Vector2Int gridPoint)
Parameters
gridPointVector2Int
Returns
RebuildDictionaryIfNeeded()
Restores the lookup dictionary if it is null (e.g. after domain reload). If the serialized matrix dimensions are already correct, only the dictionary is rebuilt. If dimensions are inconsistent, falls back to a full reshape.
public void RebuildDictionaryIfNeeded()
RecomputeBoundsAndReshape()
Recomputes the bounding box from the current params and reshapes the matrix to fit, preserving bias values at grid points that survive the resize. New region cells are set to 0; non-region cells to -1. Also rebuilds the lookup dictionary. Called automatically by the X0 and Point1 setters.
public void RecomputeBoundsAndReshape()
Reset()
Sets all fundamental region cells to 0 and all out-of-region cells to -1.
public void Reset()
SetFrom(FundamentalRegion)
Copies parameters and matrix values from other.
The lookup dictionary is copied directly without a full rebuild.
public void SetFrom(FundamentalRegion other)
Parameters
otherFundamentalRegion