Skip to content

Commit

Permalink
handle case where start and end points are same
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jul 7, 2024
1 parent fba81b3 commit f79da38
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ private LineCalculator() {
* x-coordinates and the second element is the array of y-coordinates.
*/
public static int[][] dda(int x0, int y0, int x1, int y1) {
if (x0 == x1 && y0 == y1)
return new int[][] { { x0 }, { y0 } };

final int dx = x1 - x0;
final int dy = y1 - y0;
final int steps = Math.max(Math.abs(dx), Math.abs(dy));
Expand Down Expand Up @@ -59,6 +62,9 @@ public static int[][] dda(int x0, int y0, int x1, int y1) {
* x-coordinates and the second element is the array of y-coordinates.
*/
public static int[][] bresenham(int x0, int y0, int x1, int y1) {
if (x0 == x1 && y0 == y1)
return new int[][] { { x0 }, { y0 } };

int dx = Math.abs(x1 - x0);
int dy = Math.abs(y1 - y0);

Expand Down Expand Up @@ -102,6 +108,9 @@ public static int[][] bresenham(int x0, int y0, int x1, int y1) {
* @return
*/
public static int[][] bresenham2(int x0, int y0, int x1, int y1) {
if (x0 == x1 && y0 == y1)
return new int[][] { { x0 }, { y0 } };

List<Integer> xpoints = new ArrayList<>();
List<Integer> ypoints = new ArrayList<>();

Expand Down

0 comments on commit f79da38

Please sign in to comment.