src/model/world/World.java
public void computeLine(int startX, int startY, int endX, int endY, Function<Cell, Boolean> callback) {
        if (!withinBounds(startX, startY) || !withinBounds(endX, endY)) {
            return;
        }
        int x = startX;
        int y = startY;

        int deltaX = endX - startX;
        int deltaY = endY - startY;

        int dx1 = deltaX < 0 ? -1 : deltaX > 0 ? 1 : 0;
        int dy1 = deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0;

        int dx2 = deltaX < 0 ? -1 : deltaX > 0 ? 1 : 0;
        int dy2 = 0;

        if (!(Math.abs(deltaX) > Math.abs(deltaY))) {
            dy2 = deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0;
            dx2 = 0;
        }

        int longest = Math.max(Math.abs(deltaX), Math.abs(deltaY));
        int shortest = Math.min(Math.abs(deltaX), Math.abs(deltaY));
        int numerator = longest >> 1;

        for (int i = 0; i <= longest; i++) {
            if (!callback.apply(grid[x][y])) {
                return;
            }
            numerator += shortest;
            if (!(numerator < longest)) {
                numerator -= longest;
                x += dx1;
                y += dy1;
            } else {
                x += dx2;
                y += dy2;
            }
        }
    }
/**
     * Computes the line of cells which connects the specified start and end
     * points. Each cell along the path is passed to the callback before the
     * next cell is computed. If the callback returns false, the method returns
     * immediately without computing the rest of the path.
     * 
     * This is a full 8 octant implementation of Bresenham's line algorithm,
     * adapted from:
     * http://tech-algorithm.com/articles/drawing-line-using-bresenham-algorithm/
     */
Computes the line of cells which connects the specified start and end
points. Each cell along the path is passed to the callback before the
next cell is computed. If the callback returns false, the method returns
immediately without computing the rest of the path.


Computes the line of cells which connects the specified start and end points . Each cell along the path is passed to the callback before the next cell is computed . If the callback returns false the method returns immediately without computing the rest of the path .
public void computeLine(int startX, int startY, int endX, int endY, Function<Cell, Boolean> callback) {
        if (!withinBounds(startX, startY) || !withinBounds(endX, endY)) {
            return;
        }
        int x = startX;
        int y = startY;
        int deltaX = endX - startX;
        int deltaY = endY - startY;
        int dx1 = deltaX < 0 ? -1 : deltaX > 0 ? 1 : 0;
        int dy1 = deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0;
        int dx2 = deltaX < 0 ? -1 : deltaX > 0 ? 1 : 0;
        int dy2 = 0;
        if (!(Math.abs(deltaX) > Math.abs(deltaY))) {
            dy2 = deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0;
            dx2 = 0;
        }
        int longest = Math.max(Math.abs(deltaX), Math.abs(deltaY));
        int shortest = Math.min(Math.abs(deltaX), Math.abs(deltaY));
        int numerator = longest >> 1;
        for (int i = 0; i <= longest; i++) {
            if (!callback.apply(grid[x][y])) {
                return;
            }
            numerator += shortest;
            if (!(numerator < longest)) {
                numerator -= longest;
                x += dx1;
                y += dy1;
            } else {
                x += dx2;
                y += dy2;
            }
        }
    }
public void computeLine ( int startX , int startY , int endX , int endY , Function < Cell , Boolean > callback ) { if ( ! withinBounds ( startX , startY ) || ! withinBounds ( endX , endY ) ) { return ; } int x = startX ; int y = startY ; int deltaX = endX - startX ; int deltaY = endY - startY ; int dx1 = deltaX < 0 ? - 1 : deltaX > 0 ? 1 : 0 ; int dy1 = deltaY < 0 ? - 1 : deltaY > 0 ? 1 : 0 ; int dx2 = deltaX < 0 ? - 1 : deltaX > 0 ? 1 : 0 ; int dy2 = 0 ; if ( ! ( Math . abs ( deltaX ) > Math . abs ( deltaY ) ) ) { dy2 = deltaY < 0 ? - 1 : deltaY > 0 ? 1 : 0 ; dx2 = 0 ; } int longest = Math . max ( Math . abs ( deltaX ) , Math . abs ( deltaY ) ) ; int shortest = Math . min ( Math . abs ( deltaX ) , Math . abs ( deltaY ) ) ; int numerator = longest >> 1 ; for ( int i = 0 ; i <= longest ; i ++ ) { if ( ! callback . apply ( grid [ x ] [ y ] ) ) { return ; } numerator += shortest ; if ( ! ( numerator < longest ) ) { numerator -= longest ; x += dx1 ; y += dy1 ; } else { x += dx2 ; y += dy2 ; } } }
Computes the line of cells which connects the specified start and end
 points.
Computes the line of cells which connects the specified start and end points .