Select Git revision
ShapeWriter.java
Forked from
COUETOUX Basile / graphic-2020
Source project has a limited visibility.
-
COUETOUX Basile authoredCOUETOUX Basile authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
CoordinateIterator.java 814 B
package datastruct;
import java.util.Iterator;
import java.util.NoSuchElementException;
class CoordinateIterator implements Iterator<Coordinate> {
private final int width;
private final int height;
private int x = 0;
private int y = 0;
public CoordinateIterator(int width, int height) {
this.width = width;
this.height = height;
}
@Override
public boolean hasNext() {
return y < this.height;
}
@Override
public Coordinate next() {
if (!this.hasNext()) {
throw new NoSuchElementException();
}
Coordinate coord = new Coordinate(this.x, this.y);
this.x = this.x + 1;
if (this.x == this.width) {
this.x = 0;
this.y = this.y + 1;
}
return coord;
}
}