Table of Contents

Class FloatMatrix

Namespace
Gamelogic.Fx
Assembly
Gamelogic.Fx.dll

A serializable data-driven dither matrix. Stores an array of normalized float values along with matrix dimensions.

[Serializable]
public sealed class FloatMatrix : IFloatMatrix
Inheritance
FloatMatrix
Implements
Inherited Members

Constructors

FloatMatrix(int, int, float[])

Initializes a new instance of the FloatMatrix class.

public FloatMatrix(int width, int height, float[] values = null)

Parameters

width int

The width of the matrix.

height int

The height of the matrix.

values float[]

The values to initialize the matrix with. If null, or omitted, the matrix is initialized with zeros.

Exceptions

ArgumentException

Fields

Empty

Represents a matrix with zero width and height.

public static readonly IFloatMatrix Empty

Field Value

IFloatMatrix

Properties

Height

Gets the height of this matrix.

public int Height { get; }

Property Value

int

this[int, int]

Gets nd sets the value at the specified coordinates.

public float this[int x, int y] { get; set; }

Parameters

x int

The x-coordinate of the matrix.

y int

The y-coordinate of the matrix.

Property Value

float

this[int2]

Gets the value at the specified coordinates.

public float this[int2 index] { get; }

Parameters

index int2

The 2D index into the matrix.

Property Value

float

Length

Gets the number of values in this matrix.

public int Length { get; }

Property Value

int

SizeVersion

A version number that changes when the matrix changes dimensions.

public int SizeVersion { get; }

Property Value

int

Remarks

This is support so that matrices can be set as arrays on materials, and the owner of the material can detect when the material needs to be recrated to support a different size.

Values

Gets the values of this matrix, as a one dimensional array.

public IEnumerable<float> Values { get; }

Property Value

IEnumerable<float>

Width

Gets the width of this matrix.

public int Width { get; }

Property Value

int

Methods

AddColumn()

Adds a column to the matrix at the end.

public void AddColumn()

AddRow()

Adds a row to the matrix at the end.

public void AddRow()

Clear()

Sets all values in the matrix to zero.

public void Clear()

Clone()

Creates a deep copy of this matrix.

public FloatMatrix Clone()

Returns

FloatMatrix

IsConstant()

Returns whether all values in this matrix are effectively the same.

public bool IsConstant()

Returns

bool

Remarks

This can be called before normalization to check if normalization would produce a matrix of zeros.

IsValid()

Returns whether this matrix is in a valid state (dimensions and value array are consistent).

public bool IsValid()

Returns

bool

MoveWrapped(int, int)

Shifts all values one step in the given direction, wrapping values that fall off an edge to the opposite edge.

public void MoveWrapped(int deltaX, int deltaY)

Parameters

deltaX int

Horizontal shift: -1 left, +1 right.

deltaY int

Vertical shift: -1 up, +1 down.

Normalize()

Normalizes the values in this matrix to be between 0 and 1.

public IFloatMatrix Normalize()

Returns

IFloatMatrix

Remarks

If the matrix is empty, an empty matrix is returned.

If all values in the matrix are the same, a matrix of the same dimensions filled with zeros is returned.

Otherwise, a new matrix with the same dimensions is returned, with values normalized between 0 and 1.

RemoveColumn()

Removes the last column from the matrix if there is one.

public void RemoveColumn()

RemoveRow()

Removes the last row from the matrix if there is one.

public void RemoveRow()

SetFrom(IFloatMatrix)

Sets the values and dimensions of this matrix from another matrix.

public void SetFrom(IFloatMatrix other)

Parameters

other IFloatMatrix

The other matrix to copy from.