Remove duplicate functions to set Grid Cells
This commit is contained in:
parent
e840a3e580
commit
c8e2417ab8
2 changed files with 8 additions and 19 deletions
|
@ -48,7 +48,7 @@ class Simulation {
|
|||
for (var i = 0; i < (amount); i++) {
|
||||
sanityCheck++;
|
||||
math.Point cell = _getRandomPoint(rng, spreadFromCenter);
|
||||
getCellState(cell.x, cell.y)
|
||||
map.get(cell.x, cell.y)
|
||||
? i--
|
||||
: changeSet[map.toIndex(cell.x, cell.y)] = true;
|
||||
if (sanityCheck > 100 && sanityCheck > i * 3) break;
|
||||
|
@ -72,24 +72,8 @@ class Simulation {
|
|||
return math.Point<int>(cx.toInt(), cy.toInt());
|
||||
}
|
||||
|
||||
void setCellState(int x, int y, bool state) {
|
||||
if (y >= map.height || x >= map.width) return null;
|
||||
|
||||
state ? map.set(x, y, true) : map.set(x, y, false);
|
||||
}
|
||||
|
||||
bool getCellState(int x, int y) {
|
||||
if (y >= map.height || x >= map.width) return null;
|
||||
|
||||
return map.get(x, y);
|
||||
}
|
||||
|
||||
void toggleCellState(int x, int y) {
|
||||
if (y >= map.height || x >= map.width) return null;
|
||||
|
||||
getCellState(x, y) == null
|
||||
? setCellState(x, y, true)
|
||||
: setCellState(x, y, false);
|
||||
map.get(x, y) == null ? map.set(x, y, true) : map.set(x, y, false);
|
||||
}
|
||||
|
||||
Map<int, bool> update() {
|
||||
|
@ -126,7 +110,7 @@ class Simulation {
|
|||
iy >= 0 &&
|
||||
ix < map.width &&
|
||||
iy < map.height &&
|
||||
getCellState(ix, iy) == true &&
|
||||
map.get(ix, iy) == true &&
|
||||
!(x == ix && y == iy)) count++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,4 +50,9 @@ void main() {
|
|||
expect(sut.loadSnapshot(), isNot(equals(snapshot)));
|
||||
});
|
||||
}, tags: "nobrowser");
|
||||
group("toggleCellState", () {
|
||||
test("throws RangeError if outside the map bounds", () {
|
||||
expect(() => sut.toggleCellState(10, 9), throwsRangeError);
|
||||
}, tags: const ["nobrowser"]);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue