2 Copyright (C) 1997,1998,1999
\r
3 Kenji Hiranabe, Eiwa System Management, Inc.
\r
5 This program is free software.
\r
6 Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
\r
7 conforming to the Java(TM) 3D API specification by Sun Microsystems.
\r
9 Permission to use, copy, modify, distribute and sell this software
\r
10 and its documentation for any purpose is hereby granted without fee,
\r
11 provided that the above copyright notice appear in all copies and
\r
12 that both that copyright notice and this permission notice appear
\r
13 in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
\r
14 makes no representations about the suitability of this software for any
\r
15 purpose. It is provided "AS IS" with NO WARRANTY.
\r
17 package javajs.util;
\r
19 import java.io.Serializable;
\r
22 * A generic 3 element tuple that is represented by double precision floating
\r
23 * point x,y and z coordinates.
\r
25 * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
\r
26 * 2006/07/28 17:01:32 $
\r
27 * @author Kenji hiranabe
\r
29 * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
\r
30 * for unique constructor and method names
\r
31 * for the optimization of compiled JavaScript using Java2Script
\r
33 public abstract class T3d implements Serializable {
\r
50 * Constructs and initializes a Tuple3d to (0,0,0).
\r
56 * Sets the value of this tuple to the specified xyz coordinates.
\r
65 public final void set(double x, double y, double z) {
\r
72 * Sets the value of this tuple from the 3 values specified in the array.
\r
75 * the array of length 3 containing xyz in order
\r
77 public final void setA(double t[]) {
\r
78 // ArrayIndexOutOfBounds is thrown if t.length < 3
\r
85 * Sets the value of this tuple to the value of the Tuple3d argument.
\r
88 * the tuple to be copied
\r
90 public final void setT(T3d t1) {
\r
97 * Sets the value of this tuple to the vector sum of tuples t1 and t2.
\r
104 public final void add2(T3d t1, T3d t2) {
\r
111 * Sets the value of this tuple to the vector sum of itself and tuple t1.
\r
116 public final void add(T3d t1) {
\r
123 * Sets the value of this tuple to the vector difference of tuple t1 and t2
\r
124 * (this = t1 - t2).
\r
131 public final void sub2(T3d t1, T3d t2) {
\r
138 * Sets the value of this tuple to the vector difference of itself and tuple
\r
139 * t1 (this = this - t1).
\r
144 public final void sub(T3d t1) {
\r
151 * Sets the value of this tuple to the scalar multiplication of itself.
\r
156 public final void scale(double s) {
\r
163 * Sets the value of this tuple to the scalar multiplication of tuple t1 and
\r
164 * then adds tuple t2 (this = s*t1 + t2).
\r
169 * the tuple to be multipled
\r
171 * the tuple to be added
\r
173 public final void scaleAdd(double s, T3d t1, T3d t2) {
\r
174 x = s * t1.x + t2.x;
\r
175 y = s * t1.y + t2.y;
\r
176 z = s * t1.z + t2.z;
\r
180 * Returns a hash number based on the data values in this object. Two
\r
181 * different Tuple3d objects with identical data values (ie, returns true for
\r
182 * equals(Tuple3d) ) will return the same hash number. Two vectors with
\r
183 * different data members may return the same hash value, although this is not
\r
187 public int hashCode() {
\r
188 long xbits = doubleToLongBits0(x);
\r
189 long ybits = doubleToLongBits0(y);
\r
190 long zbits = doubleToLongBits0(z);
\r
191 return (int) (xbits ^ (xbits >> 32) ^ ybits ^ (ybits >> 32) ^ zbits ^ (zbits >> 32));
\r
194 static long doubleToLongBits0(double d) {
\r
195 // Check for +0 or -0
\r
196 return (d == 0 ? 0 : Double.doubleToLongBits(d));
\r
200 * Returns true if all of the data members of Tuple3d t1 are equal to the
\r
201 * corresponding data members in this
\r
204 * the vector with which the comparison is made.
\r
207 public boolean equals(Object t1) {
\r
208 if (!(t1 instanceof T3d))
\r
211 return (this.x == t2.x && this.y == t2.y && this.z == t2.z);
\r
215 * Returns a string that contains the values of this Tuple3d. The form is
\r
218 * @return the String representation
\r
221 public String toString() {
\r
222 return "{" + x + ", " + y + ", " + z + "}";
\r