JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Recti.java
Go to the documentation of this file.
1/**
2 * Copyright 2022-2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.math;
30
31/**
32 * Rectangle with x, y, width and height integer components.
33 */
34public final class Recti {
35 private int x;
36 private int y;
37 private int width;
38 private int height;
39
40 public Recti() {}
41
42 public Recti(final Recti o) {
43 set(o);
44 }
45
46 public Recti copy() {
47 return new Recti(this);
48 }
49
50 public Recti(final int[/*4*/] xywh) {
51 set(xywh);
52 }
53
54 public Recti(final int x, final int y, final int width, final int height) {
55 set(x, y, width, height);
56 }
57
58 /** this = o, returns this. */
59 public void set(final Recti o) {
60 this.x = o.x;
61 this.y = o.y;
62 this.width = o.width;
63 this.height= o.height;
64 }
65
66 /** this = { x, y, width, height }, returns this. */
67 public void set(final int x, final int y, final int width, final int height) {
68 this.x = x;
69 this.y = y;
70 this.width = width;
71 this.height= height;
72 }
73
74 /** this = xywh, returns this. */
75 public Recti set(final int[/*2*/] xywh) {
76 this.x = xywh[0];
77 this.y = xywh[1];
78 this.width = xywh[2];
79 this.height= xywh[3];
80 return this;
81 }
82
83 /** xywh = this, returns xy. */
84 public int[] get(final int[/*4*/] xywh) {
85 xywh[0] = this.x;
86 xywh[1] = this.y;
87 xywh[2] = this.width;
88 xywh[3] = this.height;
89 return xywh;
90 }
91
92 public int x() { return x; }
93 public int y() { return y; }
94 public int width() { return width; }
95 public int height() { return height; }
96
97 public void setX(final int x) { this.x = x; }
98 public void setY(final int y) { this.y = y; }
99 public void setWidth(final int width) { this.width = width; }
100 public void setHeight(final int height) { this.height = height; }
101
102 /** Return true if area is zero. */
103 public boolean isZero() {
104 return 0 == width || 0 == height;
105 }
106
107 /**
108 * Equals check.
109 * @param o comparison value
110 * @return true if all components are equal
111 */
112 public boolean isEqual(final Recti o) {
113 if( this == o ) {
114 return true;
115 } else {
116 return x == o.x && y == o.y &&
117 width == o.width && height == o.height;
118 }
119 }
120
121 @Override
122 public boolean equals(final Object o) {
123 if( o instanceof Recti ) {
124 return isEqual((Recti)o);
125 } else {
126 return false;
127 }
128 }
129
130 @Override
131 public String toString() {
132 return x + " / " + y + " " + width + " x " + height;
133 }
134}
Rectangle with x, y, width and height integer components.
Definition: Recti.java:34
void setWidth(final int width)
Definition: Recti.java:99
Recti(final Recti o)
Definition: Recti.java:42
void setY(final int y)
Definition: Recti.java:98
void setHeight(final int height)
Definition: Recti.java:100
Recti(final int[] xywh)
Definition: Recti.java:50
boolean isZero()
Return true if area is zero.
Definition: Recti.java:103
boolean equals(final Object o)
Definition: Recti.java:122
void setX(final int x)
Definition: Recti.java:97
boolean isEqual(final Recti o)
Equals check.
Definition: Recti.java:112
Recti(final int x, final int y, final int width, final int height)
Definition: Recti.java:54