2 * $RCSfile: Tuple4b.java,v $
4 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation. Sun designates this
10 * particular file as subject to the "Classpath" exception as provided
11 * by Sun in the LICENSE file that accompanied this code.
13 * This code is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * version 2 for more details (a copy is included in the LICENSE file that
17 * accompanied this code).
19 * You should have received a copy of the GNU General Public License version
20 * 2 along with this work; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
28 * $Date: 2008/02/28 20:18:51 $
32 package javax.vecmath;
34 import java.lang.Math;
37 * A four byte tuple. Note that Java defines a byte as a signed integer
38 * in the range [-128, 127]. However, colors are more typically
39 * represented by values in the range [0, 255]. Java 3D recognizes this
40 * and, in those cases where Tuple4b is used to represent color, treats
41 * the bytes as if the range were [0, 255]---in other words, as if the
42 * bytes were unsigned.
43 * Values greater than 127 can be assigned to a byte variable using a
44 * type cast. For example:
45 * <ul>byteVariable = (byte) intValue; // intValue can be > 127</ul>
46 * If intValue is greater than 127, then byteVariable will be negative. The
47 * correct value will be extracted when it is used (by masking off the upper
50 public abstract class Tuple4b implements java.io.Serializable, Cloneable {
52 static final long serialVersionUID = -8226727741811898211L;
76 * Constructs and initializes a Tuple4b from the specified four values.
77 * @param b1 the first value
78 * @param b2 the second value
79 * @param b3 the third value
80 * @param b4 the fourth value
82 public Tuple4b(byte b1, byte b2, byte b3, byte b4)
92 * Constructs and initializes a Tuple4b from the array of length 4.
93 * @param t the array of length 4 containing b1 b2 b3 b4 in order
95 public Tuple4b(byte[] t)
105 * Constructs and initializes a Tuple4b from the specified Tuple4b.
106 * @param t1 the Tuple4b containing the initialization x y z w data
108 public Tuple4b(Tuple4b t1)
118 * Constructs and initializes a Tuple4b to (0,0,0,0).
130 * Returns a string that contains the values of this Tuple4b.
131 * @return the String representation
133 public String toString()
135 return("(" + ((int)this.x & 0xff) +
136 ", " + ((int)this.y & 0xff) +
137 ", " + ((int)this.z & 0xff) +
138 ", " + ((int)this.w & 0xff) + ")");
143 * Places the value of the x,y,z,w components of this Tuple4b
144 * into the array of length 4.
145 * @param b array of length 4 into which the values are placed
147 public final void get(byte[] b)
157 * Places the value of the x,y,z,w components of this
158 * Tuple4b into the tuple t1.
159 * @param t1 tuple into which the values are placed
161 public final void get(Tuple4b t1)
171 * Sets the value of the data members of this tuple to the value
172 * of the argument tuple t1.
173 * @param t1 the source tuple
175 public final void set(Tuple4b t1)
185 * Sets the value of the data members of this tuple to the value
186 * of the array b of length 4.
187 * @param b the source array of length 4
189 public final void set(byte[] b)
199 * Returns true if all of the data members of tuple t1 are equal to
200 * the corresponding data members in this tuple.
201 * @param t1 the tuple with which the comparison is made
203 public boolean equals(Tuple4b t1)
206 return(this.x == t1.x && this.y == t1.y &&
207 this.z == t1.z && this.w == t1.w);
209 catch (NullPointerException e2) {return false;}
214 * Returns true if the Object t1 is of type Tuple4b and all of the
215 * data members of t1 are equal to the corresponding data members in
217 * @param t1 the object with which the comparison is made
219 public boolean equals(Object t1)
222 Tuple4b t2 = (Tuple4b) t1;
223 return(this.x == t2.x && this.y == t2.y &&
224 this.z == t2.z && this.w == t2.w);
226 catch (NullPointerException e2) {return false;}
227 catch (ClassCastException e1) {return false;}
233 * Returns a hash code value based on the data values in this
234 * object. Two different Tuple4b objects with identical data values
235 * (i.e., Tuple4b.equals returns true) will return the same hash
236 * code value. Two objects with different data members may return the
237 * same hash value, although this is not likely.
238 * @return the integer hash code value
240 public int hashCode() {
241 return ((((int)x & 0xff) << 0) |
242 (((int)y & 0xff) << 8) |
243 (((int)z & 0xff) << 16) |
244 (((int)w & 0xff) << 24));
248 * Creates a new object of the same class as this object.
250 * @return a clone of this instance.
251 * @exception OutOfMemoryError if there is not enough memory.
252 * @see java.lang.Cloneable
255 public Object clone() {
256 // Since there are no arrays we can just use Object.clone()
258 return super.clone();
259 } catch (CloneNotSupportedException e) {
260 // this shouldn't happen, since we are Cloneable
261 throw new InternalError();
267 * Get <i>x</i>, the first value.
269 * @return Returns <i>x</i>, the first value.
273 public final byte getX() {
279 * Set <i>x</i>, the first value.
281 * @param x the first value.
285 public final void setX(byte x) {
291 * Get <i>y</i>, the second value.
293 * @return Returns <i>y</i>, the second value.
297 public final byte getY() {
303 * Set <i>y</i>, the second value.
305 * @param y the second value.
309 public final void setY(byte y) {
314 * Get <i>z</i>, the third value.
316 * @return Returns <i>z</i>, the third value.
320 public final byte getZ() {
326 * Set <i>z</i>, the third value.
328 * @param z the third value.
332 public final void setZ(byte z) {
338 * Get <i>w</i>, the fourth value.
340 * @return Returns <i>w</i> - the fourth value.
344 public final byte getW() {
350 * Set <i>w</i>, the fourth value.
352 * @param w the fourth value.
356 public final void setW(byte w) {