Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update Rectanglei to match test cases for #24

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,6 @@ public boolean isValid() {
return minX < maxX && minY < maxY;
}

private Rectanglei validate() {
if (!isValid()) {
minX = Integer.MAX_VALUE;
minY = Integer.MAX_VALUE;
maxX = Integer.MIN_VALUE;
maxY = Integer.MIN_VALUE;
}
return this;
}

/**
* Set <code>this</code> to the union of <code>this</code> and the given point <code>p</code>.
*
Expand Down Expand Up @@ -540,19 +530,19 @@ public Rectanglei scale(int sx, int sy, Vector2ic anchor, Rectanglei dest) {
@Override
public boolean containsRectangle(Rectangledc rectangle) {
return rectangle.minX() >= minX && rectangle.maxX() <= maxX &&
rectangle.minY() >= minY && rectangle.maxY() <= maxY;
rectangle.minY() >= minY && rectangle.maxY() <= maxY && isValid() && rectangle.isValid();
}

@Override
public boolean containsRectangle(Rectanglefc rectangle) {
return rectangle.minX() >= minX && rectangle.maxX() <= maxX &&
rectangle.minY() >= minY && rectangle.maxY() <= maxY;
rectangle.minY() >= minY && rectangle.maxY() <= maxY && isValid() && rectangle.isValid();
}

@Override
public boolean containsRectangle(Rectangleic rectangle) {
return rectangle.minX() >= minX && rectangle.maxX() <= maxX &&
rectangle.minY() >= minY && rectangle.maxY() <= maxY;
rectangle.minY() >= minY && rectangle.maxY() <= maxY && isValid() && rectangle.isValid();
}

@Override
Expand All @@ -562,7 +552,7 @@ public boolean containsPoint(Vector2ic point) {

@Override
public boolean containsPoint(float x, float y) {
return x >= this.minX && y >= this.minY && x <= this.maxX && y <= this.maxY;
return x >= this.minX && y >= this.minY && x <= this.maxX && y <= this.maxY && isValid();
}

@Override
Expand All @@ -572,7 +562,7 @@ public boolean containsPoint(Vector2fc point) {

@Override
public boolean containsPoint(int x, int y) {
return x >= minX && y >= minY && x <= maxX && y <= maxY;
return x >= minX && y >= minY && x <= maxX && y <= maxY && isValid();
}

@Override
Expand All @@ -582,25 +572,25 @@ public boolean containsPoint(Vector2dc point) {

@Override
public boolean containsPoint(double x, double y) {
return x >= this.minX && y >= this.minY && x <= this.maxX && y <= this.maxY;
return x >= this.minX && y >= this.minY && x <= this.maxX && y <= this.maxY && isValid();
}

@Override
public boolean intersectsRectangle(Rectangledc other) {
return minX <= other.maxX() && maxX >= other.minX() &&
maxY >= other.minY() && minY <= other.maxY();
maxY >= other.minY() && minY <= other.maxY() && other.isValid() && isValid();
}

@Override
public boolean intersectsRectangle(Rectanglefc other) {
return minX <= other.maxX() && maxX >= other.minX() &&
maxY >= other.minY() && minY <= other.maxY();
maxY >= other.minY() && minY <= other.maxY() && other.isValid() && isValid();
}

@Override
public boolean intersectsRectangle(Rectangleic other) {
return minX <= other.maxX() && maxX >= other.minX() &&
maxY >= other.minY() && minY <= other.maxY();
maxY >= other.minY() && minY <= other.maxY() && other.isValid() && isValid();
}

@Override
Expand All @@ -609,7 +599,7 @@ public Rectanglei intersection(Rectangleic other, Rectanglei dest) {
dest.minY = Math.max(minY, other.minY());
dest.maxX = Math.min(maxX, other.maxX());
dest.maxY = Math.min(maxY, other.maxY());
return dest.validate();
return dest;
}

/**
Expand Down