diff options
author | Sven Gothel <[email protected]> | 2020-01-15 07:45:49 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-01-15 07:45:49 +0100 |
commit | 9bcc384e66e40706225b86e9750c5822cb8f8c57 (patch) | |
tree | fa87be2bc466ba910b55c14b3ac3288b589093cf /src | |
parent | 88cc287a47066c81ee0b385e2e0ca96f027286b3 (diff) |
Nativewindow Rectangle*: Cleanup up union(..), intersection(..): Return a new Rectangle instance (mutable)
Also return 'this' for setter methods for chaining.
Diffstat (limited to 'src')
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java | 31 | ||||
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/util/RectangleImmutable.java | 16 |
2 files changed, 21 insertions, 26 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java b/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java index 9b4d7ec68..0b853b08f 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java @@ -73,35 +73,31 @@ public class Rectangle implements Cloneable, RectangleImmutable { @Override public final int getHeight() { return height; } - public final void set(final int x, final int y, final int width, final int height) { + public final Rectangle set(final int x, final int y, final int width, final int height) { this.x = x; this.y = y; this.width = width; this.height = height; + return this; } - public final void set(final Rectangle s) { - this.x = s.x; - this.y = s.y; - this.width = s.width; - this.height = s.height; - } - public final void set(final RectangleImmutable s) { + public final Rectangle set(final RectangleImmutable s) { this.x = s.getX(); this.y = s.getY(); this.width = s.getWidth(); this.height = s.getHeight(); + return this; } - public final void setX(final int x) { this.x = x; } - public final void setY(final int y) { this.y = y; } - public final void setWidth(final int width) { this.width = width; } - public final void setHeight(final int height) { this.height = height; } + public final Rectangle setX(final int x) { this.x = x; return this; } + public final Rectangle setY(final int y) { this.y = y; return this; } + public final Rectangle setWidth(final int width) { this.width = width; return this; } + public final Rectangle setHeight(final int height) { this.height = height; return this; } @Override - public final RectangleImmutable union(final RectangleImmutable r) { + public final Rectangle union(final RectangleImmutable r) { return union(r.getX(), r.getY(), r.getX() + r.getWidth(), r.getY() + r.getHeight()); } @Override - public final RectangleImmutable union(final int rx1, final int ry1, final int rx2, final int ry2) { + public final Rectangle union(final int rx1, final int ry1, final int rx2, final int ry2) { final int x1 = Math.min(x, rx1); final int y1 = Math.min(y, ry1); final int x2 = Math.max(x + width, rx2); @@ -123,16 +119,15 @@ public class Rectangle implements Cloneable, RectangleImmutable { y1 = Math.min(y1, vp.getY()); y2 = Math.max(y2, vp.getY() + vp.getHeight()); } - set(x1, y1, x2 - x1, y2 - y1); - return this; + return new Rectangle(x1, y1, x2 - x1, y2 - y1); } @Override - public final RectangleImmutable intersection(final RectangleImmutable r) { + public final Rectangle intersection(final RectangleImmutable r) { return intersection(r.getX(), r.getY(), r.getX() + r.getWidth(), r.getY() + r.getHeight()); } @Override - public final RectangleImmutable intersection(final int rx1, final int ry1, final int rx2, final int ry2) { + public final Rectangle intersection(final int rx1, final int ry1, final int rx2, final int ry2) { final int x1 = Math.max(x, rx1); final int y1 = Math.max(y, ry1); final int x2 = Math.min(x + width, rx2); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/util/RectangleImmutable.java b/src/nativewindow/classes/com/jogamp/nativewindow/util/RectangleImmutable.java index ff2209598..a5508c5f6 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/util/RectangleImmutable.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/util/RectangleImmutable.java @@ -41,14 +41,14 @@ public interface RectangleImmutable extends WriteCloneable, Comparable<Rectangle int getY(); - /** Returns the union of this rectangle and the given rectangle. */ - RectangleImmutable union(final RectangleImmutable r); - /** Returns the union of this rectangleand the given coordinates. */ - RectangleImmutable union(final int rx1, final int ry1, final int rx2, final int ry2); - /** Returns the intersection of this rectangleand the given rectangle. */ - RectangleImmutable intersection(RectangleImmutable r); - /** Returns the intersection of this rectangleand the given coordinates. */ - RectangleImmutable intersection(final int rx1, final int ry1, final int rx2, final int ry2); + /** Returns a new {@link Rectangle} instance containing the union of this rectangle and the given rectangle. */ + Rectangle union(final RectangleImmutable r); + /** Returns a new {@link Rectangle} instance containing the union of this rectangle and the given coordinates. */ + Rectangle union(final int rx1, final int ry1, final int rx2, final int ry2); + /** Returns a new {@link Rectangle} instance containing the intersection of this rectangle and the given rectangle. */ + Rectangle intersection(RectangleImmutable r); + /** Returns a new {@link Rectangle} instance containing the intersection of this rectangle and the given coordinates. */ + Rectangle intersection(final int rx1, final int ry1, final int rx2, final int ry2); /** * Returns the coverage of given rectangle w/ this this one, i.e. between <code>0.0</code> and <code>1.0</code>. * <p> |