2 * $RCSfile: Tuple4i.java,v $
4 * Copyright 1999-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 4-element tuple represented by signed integer x,y,z,w
42 public abstract class Tuple4i implements java.io.Serializable, Cloneable {
44 static final long serialVersionUID = 8064614250942616720L;
68 * Constructs and initializes a Tuple4i from the specified
69 * x, y, z, and w coordinates.
70 * @param x the x coordinate
71 * @param y the y coordinate
72 * @param z the z coordinate
73 * @param w the w coordinate
75 public Tuple4i(int x, int y, int z, int w) {
84 * Constructs and initializes a Tuple4i from the array of length 4.
85 * @param t the array of length 4 containing x, y, z, and w in order.
87 public Tuple4i(int[] t) {
96 * Constructs and initializes a Tuple4i from the specified Tuple4i.
97 * @param t1 the Tuple4i containing the initialization x, y, z,
100 public Tuple4i(Tuple4i t1) {
109 * Constructs and initializes a Tuple4i to (0,0,0,0).
120 * Sets the value of this tuple to the specified x, y, z, and w
122 * @param x the x coordinate
123 * @param y the y coordinate
124 * @param z the z coordinate
125 * @param w the w coordinate
127 public final void set(int x, int y, int z, int w) {
136 * Sets the value of this tuple to the specified coordinates in the
138 * @param t the array of length 4 containing x, y, z, and w in order.
140 public final void set(int[] t) {
149 * Sets the value of this tuple to the value of tuple t1.
150 * @param t1 the tuple to be copied
152 public final void set(Tuple4i t1) {
161 * Copies the values of this tuple into the array t.
164 public final void get(int[] t) {
173 * Copies the values of this tuple into the tuple t.
174 * @param t the target tuple
176 public final void get(Tuple4i t) {
185 * Sets the value of this tuple to the sum of tuples t1 and t2.
186 * @param t1 the first tuple
187 * @param t2 the second tuple
189 public final void add(Tuple4i t1, Tuple4i t2) {
190 this.x = t1.x + t2.x;
191 this.y = t1.y + t2.y;
192 this.z = t1.z + t2.z;
193 this.w = t1.w + t2.w;
198 * Sets the value of this tuple to the sum of itself and t1.
199 * @param t1 the other tuple
201 public final void add(Tuple4i t1) {
210 * Sets the value of this tuple to the difference
211 * of tuples t1 and t2 (this = t1 - t2).
212 * @param t1 the first tuple
213 * @param t2 the second tuple
215 public final void sub(Tuple4i t1, Tuple4i t2) {
216 this.x = t1.x - t2.x;
217 this.y = t1.y - t2.y;
218 this.z = t1.z - t2.z;
219 this.w = t1.w - t2.w;
224 * Sets the value of this tuple to the difference
225 * of itself and t1 (this = this - t1).
226 * @param t1 the other tuple
228 public final void sub(Tuple4i t1) {
237 * Sets the value of this tuple to the negation of tuple t1.
238 * @param t1 the source tuple
240 public final void negate(Tuple4i t1) {
249 * Negates the value of this tuple in place.
251 public final void negate() {
260 * Sets the value of this tuple to the scalar multiplication
262 * @param s the scalar value
263 * @param t1 the source tuple
265 public final void scale(int s, Tuple4i t1) {
274 * Sets the value of this tuple to the scalar multiplication
275 * of the scale factor with this.
276 * @param s the scalar value
278 public final void scale(int s) {
287 * Sets the value of this tuple to the scalar multiplication
288 * of tuple t1 plus tuple t2 (this = s*t1 + t2).
289 * @param s the scalar value
290 * @param t1 the tuple to be multipled
291 * @param t2 the tuple to be added
293 public final void scaleAdd(int s, Tuple4i t1, Tuple4i t2) {
294 this.x = s*t1.x + t2.x;
295 this.y = s*t1.y + t2.y;
296 this.z = s*t1.z + t2.z;
297 this.w = s*t1.w + t2.w;
302 * Sets the value of this tuple to the scalar multiplication
303 * of itself and then adds tuple t1 (this = s*this + t1).
304 * @param s the scalar value
305 * @param t1 the tuple to be added
307 public final void scaleAdd(int s, Tuple4i t1) {
308 this.x = s*this.x + t1.x;
309 this.y = s*this.y + t1.y;
310 this.z = s*this.z + t1.z;
311 this.w = s*this.w + t1.w;
316 * Returns a string that contains the values of this Tuple4i.
317 * The form is (x,y,z,w).
318 * @return the String representation
320 public String toString() {
321 return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")";
326 * Returns true if the Object t1 is of type Tuple4i and all of the
327 * data members of t1 are equal to the corresponding data members in
329 * @param t1 the object with which the comparison is made
330 * @return true or false
332 public boolean equals(Object t1) {
334 Tuple4i t2 = (Tuple4i) t1;
335 return(this.x == t2.x && this.y == t2.y &&
336 this.z == t2.z && this.w == t2.w);
338 catch (NullPointerException e2) {
341 catch (ClassCastException e1) {
348 * Returns a hash code value based on the data values in this
349 * object. Two different Tuple4i objects with identical data values
350 * (i.e., Tuple4i.equals returns true) will return the same hash
351 * code value. Two objects with different data members may return the
352 * same hash value, although this is not likely.
353 * @return the integer hash code value
355 public int hashCode() {
357 bits = 31L * bits + (long)x;
358 bits = 31L * bits + (long)y;
359 bits = 31L * bits + (long)z;
360 bits = 31L * bits + (long)w;
361 return (int) (bits ^ (bits >> 32));
366 * Clamps the tuple parameter to the range [low, high] and
367 * places the values into this tuple.
368 * @param min the lowest value in the tuple after clamping
369 * @param max the highest value in the tuple after clamping
370 * @param t the source tuple, which will not be modified
372 public final void clamp(int min, int max, Tuple4i t) {
375 } else if( t.x < min ) {
383 } else if( t.y < min ) {
391 } else if( t.z < min ) {
399 } else if( t.w < min ) {
408 * Clamps the minimum value of the tuple parameter to the min
409 * parameter and places the values into this tuple.
410 * @param min the lowest value in the tuple after clamping
411 * @param t the source tuple, which will not be modified
413 public final void clampMin(int min, Tuple4i t) {
443 * Clamps the maximum value of the tuple parameter to the max
444 * parameter and places the values into this tuple.
445 * @param max the highest value in the tuple after clamping
446 * @param t the source tuple, which will not be modified
448 public final void clampMax(int max, Tuple4i t) {
476 * Sets each component of the tuple parameter to its absolute
477 * value and places the modified values into this tuple.
478 * @param t the source tuple, which will not be modified
480 public final void absolute(Tuple4i t) {
489 * Clamps this tuple to the range [low, high].
490 * @param min the lowest value in this tuple after clamping
491 * @param max the highest value in this tuple after clamping
493 public final void clamp(int min, int max) {
496 } else if( x < min ) {
502 } else if( y < min ) {
508 } else if( z < min ) {
514 } else if( w < min ) {
521 * Clamps the minimum value of this tuple to the min parameter.
522 * @param min the lowest value in this tuple after clamping
524 public final void clampMin(int min) {
540 * Clamps the maximum value of this tuple to the max parameter.
541 * @param max the highest value in the tuple after clamping
543 public final void clampMax(int max) {
559 * Sets each component of this tuple to its absolute value.
561 public final void absolute() {
569 * Creates a new object of the same class as this object.
571 * @return a clone of this instance.
572 * @exception OutOfMemoryError if there is not enough memory.
573 * @see java.lang.Cloneable
576 public Object clone() {
577 // Since there are no arrays we can just use Object.clone()
579 return super.clone();
580 } catch (CloneNotSupportedException e) {
581 // this shouldn't happen, since we are Cloneable
582 throw new InternalError();
589 * Get the <i>x</i> coordinate.
591 * @return the <i>x</i> coordinate.
595 public final int getX() {
601 * Set the <i>x</i> coordinate.
603 * @param x value to <i>x</i> coordinate.
607 public final void setX(int x) {
613 * Get the <i>y</i> coordinate.
615 * @return the <i>y</i> coordinate.
619 public final int getY() {
625 * Set the <i>y</i> coordinate.
627 * @param y value to <i>y</i> coordinate.
631 public final void setY(int y) {
636 * Get the <i>z</i> coordinate.
638 * @return the <i>z</i> coordinate.
642 public final int getZ() {
648 * Set the <i>z</i> coordinate.
650 * @param z value to <i>z</i> coordinate.
654 public final void setZ(int z) {
660 * Get the <i>w</i> coordinate.
661 * @return the <i>w</i> coordinate.
664 public final int getW() {
670 * Set the <i>w</i> coordinate.
672 * @param w value to <i>w</i> coordinate.
676 public final void setW(int w) {