Skip to content

Grid class getNode or getNodeAt? #3

Description

@BrayFlex

Examples use getNode(x, y) in README.md but code has been modified to getNodeAt(x, y), we should decide what to go with.

  /// Gets the [Node] instance at the specified grid coordinates.
  ///
  /// Throws a [RangeError] if the coordinates `(x, y)` are outside the
  /// valid grid bounds (0 <= x < width, 0 <= y < height).
  ///
  /// [x] The column index (0-based).
  /// [y] The row index (0-based).
  /// Returns the [Node] at the given coordinates.
  Node getNodeAt(int x, int y) {
    // isInside check is implicitly handled by List bounds checking,
    // but explicit check provides clearer error for user.
    if (!isInside(x, y)) {
      // Consider throwing ArgumentError instead of RangeError for consistency?
      // RangeError seems appropriate for index access.
      throw RangeError('Coordinates ($x, $y) are outside grid bounds ($width x $height).');
    }
    // Note: Access is _nodes[y][x] due to List<List<Node>> structure (rows outer, cols inner)
    return _nodes[y][x];
  }

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions