core: empty() for Rect/Size templates
Check for empty objects via .area() is not a good practice due overflows
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user