getMatrix method
Retrieves a specific Matrix for a given character.
This method fetches a character definition and returns the matrix at the specified index. If the character definition doesn't exist or the index is out of bounds, an empty matrix is returned.
Parameters:
character
: A String representing the character for which to retrieve the matrix. This should be a single character, typically.matricesIndex
: An int specifying the index of the desired matrix within the character's definition. Different indices may represent variations or different representations of the character.
Returns:
- A Matrix object representing the character at the specified index.
- Returns an empty Matrix if:
- No definition is found for the character.
- The matricesIndex is negative.
- The matricesIndex is out of bounds for the character's matrices.
Example:
final Matrix aMatrix = getMatrix('A', 0);
final Matrix emptyMatrix = getMatrix('?', 5); // Assuming '?' is undefined or index 5 is out of bounds
Implementation
Matrix getMatrix(
final String character,
final int matricesIndex,
) {
final CharacterDefinition? definition = getDefinition(character);
if (definition == null ||
matricesIndex < 0 ||
matricesIndex >= definition.matrices.length) {
return Matrix();
}
return definition.matrices[matricesIndex];
}