Add getter and setter methods for wrapper
!!Need testing
This commit is contained in:
parent
27ef72014e
commit
b0e67d9f85
1 changed files with 21 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
|
@ -19,4 +20,24 @@ class Grid<E> extends DelegatingList<E> {
|
||||||
width = w,
|
width = w,
|
||||||
height = h,
|
height = h,
|
||||||
super(l);
|
super(l);
|
||||||
|
|
||||||
|
E elementAtPos(int x, int y) {
|
||||||
|
int i = toIndex(x, y);
|
||||||
|
if (i >= length) throw RangeError.index(i, this);
|
||||||
|
_internal[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void setElement(int x, int y, E value) {
|
||||||
|
int i = toIndex(x, y);
|
||||||
|
if (i >= length) throw RangeError.index(i, this);
|
||||||
|
_internal[i] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
E get(int x, int y) => elementAtPos(x, y);
|
||||||
|
|
||||||
|
void set(int x, int y, E value) => setElement(x, y, value);
|
||||||
|
|
||||||
|
int toIndex(int x, int y) => y * width + x;
|
||||||
|
|
||||||
|
Point<int> toCoords(int index) => Point<int>(index % width, index ~/ width);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue