JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / javajs / util / T3i.java
1 /*\r
2    Copyright (C) 1997,1998,1999\r
3    Kenji Hiranabe, Eiwa System Management, Inc.\r
4 \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
8 \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
16 */\r
17 package javajs.util;\r
18 \r
19 import java.io.Serializable;\r
20 \r
21 /**\r
22  * A 3-element tuple represented by signed integer x,y,z coordinates.\r
23  * \r
24  * @since Java 3D 1.2\r
25  * @version specification 1.2, implementation $Revision: 1.9 $, $Date:\r
26  *          2006/07/28 17:01:32 $\r
27  * @author Kenji hiranabe\r
28  * \r
29  *         additions by Bob Hanson hansonr@stolaf.edu 9/30/2012 for unique\r
30  *         constructor and method names for the optimization of compiled\r
31  *         JavaScript using Java2Script\r
32  */\r
33 public abstract class T3i implements Serializable {\r
34 \r
35   /**\r
36    * The x coordinate.\r
37    */\r
38   public int x;\r
39 \r
40   /**\r
41    * The y coordinate.\r
42    */\r
43   public int y;\r
44 \r
45   /**\r
46    * The z coordinate.\r
47    */\r
48   public int z;\r
49 \r
50   /**\r
51    * Constructs and initializes a Tuple3i to (0,0,0).\r
52    */\r
53   public T3i() {\r
54   }\r
55 \r
56   /**\r
57    * Sets the value of this tuple to to the specified x, y, and z coordinates.\r
58    * \r
59    * @param x\r
60    *        the x coordinate.\r
61    * @param y\r
62    *        the y coordinate.\r
63    * @param z\r
64    *        the z coordinate.\r
65    */\r
66   public final void set(int x, int y, int z) {\r
67     this.x = x;\r
68     this.y = y;\r
69     this.z = z;\r
70   }\r
71 \r
72   /**\r
73    * Sets the value of this tuple to the value of tuple t1.\r
74    * \r
75    * @param t1\r
76    *        the tuple to be copied.\r
77    */\r
78   public final void setT(T3i t1) {\r
79     x = t1.x;\r
80     y = t1.y;\r
81     z = t1.z;\r
82   }\r
83 \r
84   /**\r
85    * Sets the value of this tuple to the sum of itself and t1.\r
86    * \r
87    * @param t\r
88    *        is the other tuple\r
89    */\r
90   public final void add(T3i t) {\r
91     x += t.x;\r
92     y += t.y;\r
93     z += t.z;\r
94   }\r
95 \r
96   /**\r
97    * Sets the value of this tuple to the scalar multiplication of tuple t1 plus\r
98    * tuple t2 (this = s*t1 + t2).\r
99    * \r
100    * @param s\r
101    *        the scalar value\r
102    * @param t1\r
103    *        the tuple to be multipled\r
104    * @param t2\r
105    *        the tuple to be added\r
106    */\r
107   public final void scaleAdd(int s, T3i t1, T3i t2) {\r
108     x = s * t1.x + t2.x;\r
109     y = s * t1.y + t2.y;\r
110     z = s * t1.z + t2.z;\r
111   }\r
112 \r
113   /**\r
114    * Returns a hash number based on the data values in this object. Two\r
115    * different Tuple3i objects with identical data values (ie, returns true for\r
116    * equals(Tuple3i) ) will return the same hash number. Two vectors with\r
117    * different data members may return the same hash value, although this is not\r
118    * likely.\r
119    */\r
120   @Override\r
121   public int hashCode() {\r
122     return x ^ y ^ z;\r
123   }\r
124 \r
125   /**\r
126    * Returns true if the Object o is of type Tuple3i and all of the data members\r
127    * of t are equal to the corresponding data members in this Tuple3i.\r
128    * \r
129    * @param o\r
130    *        the object with which the comparison is made.\r
131    */\r
132   @Override\r
133   public boolean equals(Object o) {\r
134     if (!(o instanceof T3i))\r
135       return false;\r
136     T3i t = (T3i) o;\r
137     return (this.x == t.x && this.y == t.y && this.z == t.z);\r
138   }\r
139 \r
140   /**\r
141    * Returns a string that contains the values of this Tuple3i. The form is\r
142    * (x,y,z).\r
143    * \r
144    * @return the String representation\r
145    */\r
146   @Override\r
147   public String toString() {\r
148     return "(" + x + ", " + y + ", " + z + ")";\r
149   }\r
150 \r
151 }\r