2 * $RCSfile: Tuple3b.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 three 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 Tuple3b 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 Tuple3b implements java.io.Serializable, Cloneable {
52 static final long serialVersionUID = -483782685323607044L;
71 * Constructs and initializes a Tuple3b from the specified three values.
72 * @param b1 the first value
73 * @param b2 the second value
74 * @param b3 the third value
76 public Tuple3b(byte b1, byte b2, byte b3)
85 * Constructs and initializes a Tuple3b from input array of length 3.
86 * @param t the array of length 3 containing b1 b2 b3 in order
88 public Tuple3b(byte[] t)
97 * Constructs and initializes a Tuple3b from the specified Tuple3b.
98 * @param t1 the Tuple3b containing the initialization x y z data
100 public Tuple3b(Tuple3b t1)
109 * Constructs and initializes a Tuple3b to (0,0,0).
120 * Returns a string that contains the values of this Tuple3b.
121 * @return a String with the values
123 public String toString()
125 return("(" + ((int)this.x & 0xff) +
126 ", " + ((int)this.y & 0xff) +
127 ", " + ((int)this.z & 0xff) + ")");
132 * Places the value of the x,y,z components of this Tuple3b
133 * into the array of length 3.
134 * @param t array of length 3 into which the component values are copied
136 public final void get(byte[] t)
146 * Places the value of the x,y,z components of this tuple into
148 * @param t1 the tuple into which the values are placed
150 public final void get(Tuple3b t1)
159 * Sets the value of the data members of this tuple to the value
160 * of the argument tuple t1.
161 * @param t1 the source tuple for the memberwise copy
163 public final void set(Tuple3b t1)
172 * Sets the value of the x,y,z, data members of this tuple to the
173 * values in the array t of length 3.
174 * @param t array of length 3 which is the source for the memberwise copy
176 public final void set(byte[] t)
185 * Returns true if all of the data members of tuple t1 are equal to
186 * the corresponding data members in this tuple.
187 * @param t1 the tuple with which the comparison is made
188 * @return true or false
190 public boolean equals(Tuple3b t1)
193 return(this.x == t1.x && this.y == t1.y && this.z == t1.z);
195 catch (NullPointerException e2) {return false;}
200 * Returns true if the Object t1 is of type Tuple3b and all of the
201 * data members of t1 are equal to the corresponding data members in
203 * @param t1 the object with which the comparison is made
205 public boolean equals(Object t1)
208 Tuple3b t2 = (Tuple3b) t1;
209 return(this.x == t2.x && this.y == t2.y && this.z == t2.z);
211 catch (NullPointerException e2) {return false;}
212 catch (ClassCastException e1) {return false;}
217 * Returns a hash code value based on the data values in this
218 * object. Two different Tuple3b objects with identical data values
219 * (i.e., Tuple3b.equals returns true) will return the same hash
220 * code value. Two objects with different data members may return the
221 * same hash value, although this is not likely.
222 * @return the integer hash code value
224 public int hashCode() {
225 return ((((int)x & 0xff) << 0) |
226 (((int)y & 0xff) << 8) |
227 (((int)z & 0xff) << 16));
231 * Creates a new object of the same class as this object.
233 * @return a clone of this instance.
234 * @exception OutOfMemoryError if there is not enough memory.
235 * @see java.lang.Cloneable
238 public Object clone() {
239 // Since there are no arrays we can just use Object.clone()
241 return super.clone();
242 } catch (CloneNotSupportedException e) {
243 // this shouldn't happen, since we are Cloneable
244 throw new InternalError();
250 * Get <i>x</i>, the first value.
252 * @return the first value.
256 public final byte getX() {
262 * Set <i>x</i>, the first value.
264 * @param x the first value to set.
268 public final void setX(byte x) {
274 * Get <i>y</i>, the second value.
276 * @return the second value.
280 public final byte getY() {
286 * Set <i>y</i>, the second value.
288 * @param y the second value to set.
292 public final void setY(byte y) {
297 * Get <i>z</i>, the third value.
299 * @return the third value.
303 public final byte getZ() {
309 * Set <i>z</i>, the third value.
311 * @param z the third value to set.
315 public final void setZ(byte z) {