core: empty() for Rect/Size templates

Check for empty objects via .area() is not a good practice due overflows
This commit is contained in:
Alexander Alekhin
2017-08-01 17:19:18 +03:00
parent 4ad45af53f
commit 321c0ec533
4 changed files with 31 additions and 2 deletions
@@ -65,6 +65,10 @@ public class Rect {
return width * height;
}
public boolean empty() {
return width <= 0 || height <= 0;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@@ -65,6 +65,10 @@ public class Rect2d {
return width * height;
}
public boolean empty() {
return width <= 0 || height <= 0;
}
public boolean contains(Point p) {
return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
}
@@ -37,6 +37,10 @@ public class Size {
return width * height;
}
public boolean empty() {
return width <= 0 || height <= 0;
}
public Size clone() {
return new Size(width, height);
}