@@ -4,7 +4,6 @@ import "package:interpreter/src/models/basic_shape.dart";
44
55/// It's a class that allows you to color a shape
66class BasicColoring {
7-
87 /// Creating a constructor for the class BasicColoring.
98 BasicColoring (BasicShape shape) : _shape = shape;
109
@@ -263,9 +262,12 @@ class BasicColoring {
263262 /// Returns:
264263 /// A boolean value.
265264 bool fillEmpty (int color) {
266- for (final List <int > line in _shape.grid) {
267- for (int i = 0 ; i < 6 ; i++ ) {
268- line[i] = line[i] == _defaultColor ? color : line[i];
265+ for (int i = 0 ; i < _shape.grid.length; i++ ) {
266+ for (int j = 0 ; j < _shape.grid[i].length; j++ ) {
267+ if (_shape.validatePosition (i, j)) {
268+ _shape.grid[i][j] =
269+ _shape.grid[i][j] == _defaultColor ? color : _shape.grid[i][j];
270+ }
269271 }
270272 }
271273
@@ -403,7 +405,7 @@ class BasicColoring {
403405 bool mirrorHorizontalUpDown () {
404406 for (final int i in 0. rangeTo (2 )) {
405407 for (final int j in 0. rangeTo (5 )) {
406- if (_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0 ){
408+ if (_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0 ) {
407409 _shape.grid[5 - i][j] = _shape.grid[i][j];
408410 }
409411 }
@@ -419,7 +421,7 @@ class BasicColoring {
419421 bool mirrorHorizontalDownUp () {
420422 for (final int i in 3. rangeTo (5 )) {
421423 for (final int j in 0. rangeTo (5 )) {
422- if (_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0 ) {
424+ if (_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0 ) {
423425 _shape.grid[5 - i][j] = _shape.grid[i][j];
424426 }
425427 }
@@ -436,7 +438,7 @@ class BasicColoring {
436438 bool mirrorVerticalLeftRight () {
437439 for (final int i in 0. rangeTo (2 )) {
438440 for (final int j in 0. rangeTo (5 )) {
439- if (_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0 ) {
441+ if (_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0 ) {
440442 _shape.grid[j][5 - i] = _shape.grid[j][i];
441443 }
442444 }
@@ -453,7 +455,7 @@ class BasicColoring {
453455 bool mirrorVerticalRightLeft () {
454456 for (final int i in 3. rangeTo (5 )) {
455457 for (final int j in 0. rangeTo (5 )) {
456- if (_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0 ) {
458+ if (_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0 ) {
457459 _shape.grid[j][5 - i] = _shape.grid[j][i];
458460 }
459461 }
0 commit comments