package com.savvasdalkitsis.gameframe.draw.model;

import com.savvasdalkitsis.gameframe.grid.model.ColorGrid;
import com.savvasdalkitsis.gameframe.grid.model.Grid;

class LineTool extends ScratchTool {

    private static final int STEP = ColorGrid.SIDE * 2;

    @Override
    void drawOnScratch(Grid scratch, int startColumn, int startRow, int column, int row, int color) {
        float stepX = (column - startColumn) / (float) STEP;
        float stepY = (row - startRow) / (float) STEP;
        for (int i = 0; i < STEP; i++) {
            float x = startColumn + i * stepX;
            float y = startRow + i * stepY;
            scratch.setColor(color, (int) x, (int) y);
        }
        scratch.setColor(color, column, row);
    }
}

@@ -96,167 +96,51 @@
 del.
-ColorGrid;%0Aimport com.savvasdalkitsis.gameframe.grid.model.Grid;%0A%0Aclass LineTool extends ScratchTool %7B%0A%0A    private static final int STEP = ColorGrid.SIDE * 2;
+Grid;%0A%0Aclass LineTool extends ScratchTool %7B
 %0A%0A  
@@ -265,115 +265,55 @@
     
-float stepX = (column - startColumn) / (float) STEP;%0A        float stepY = (row - startRow) / (float) STEP;
+int x = startColumn;%0A        int y = startRow;%0A
 %0A   
@@ -321,53 +321,84 @@
     
-for (
 int 
-i = 0; i %3C STEP; i++) %7B%0A    
+dx = Math.abs(column - x);%0A        int dy = Math.abs(row - y);%0A%0A
         
 floa
@@ -397,197 +397,505 @@
     
-floa
+in
 t 
+s
 x = 
-startColumn + i * stepX;%0A            float y = startRow + i * stepY;%0A            scratch.setColor(color, (int) x, (int) y);%0A        %7D%0A        scratch.setColor(color, column, row);
+x %3C column ? 1 : -1;%0A        int sy = y %3C row ? 1 : -1;%0A%0A        int err = dx - dy;%0A        int e2;%0A%0A        while (true) %7B%0A            scratch.setColor(color, x, y);%0A%0A            if (x == column && y == row) %7B%0A                break;%0A            %7D%0A%0A            e2 = 2 * err;%0A            if (e2 %3E -dy) %7B%0A                err = err - dy;%0A                x = x + sx;%0A            %7D%0A%0A            if (e2 %3C dx) %7B%0A                err = err + dx;%0A                y = y + sy;%0A            %7D%0A        %7D
 %0A   

Implementing better line algorithm