JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / javajs / util / T4.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 /**\r
20  * A generic 4 element tuple that is represented by single precision floating\r
21  * point x,y,z and w coordinates.\r
22  * \r
23  * @version specification 1.1, implementation $Revision: 1.9 $, $Date:\r
24  *          2006/07/28 17:01:32 $\r
25  * @author Kenji hiranabe\r
26  * \r
27  * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012\r
28  * for unique constructor and method names\r
29  * for the optimization of compiled JavaScript using Java2Script\r
30  */\r
31 public abstract class T4 extends T3 {\r
32 \r
33   /**\r
34    * The w coordinate.\r
35    */\r
36   public float w;\r
37 \r
38   /**\r
39    * Constructs and initializes a Tuple4f to (0,0,0,0).\r
40    * \r
41    * @j2sIgnore   * \r
42    */\r
43   public T4() {\r
44   }\r
45 \r
46   /**\r
47    * Sets the value of this tuple to the specified xyzw coordinates.\r
48    * \r
49    * @param x\r
50    *        the x coordinate\r
51    * @param y\r
52    *        the y coordinate\r
53    * @param z\r
54    *        the z coordinate\r
55    * @param w\r
56    *        the w coordinate\r
57    */\r
58   public final void set4(float x, float y, float z, float w) {\r
59     this.x = x;\r
60     this.y = y;\r
61     this.z = z;\r
62     this.w = w;\r
63   }\r
64 \r
65   /**\r
66    * Sets the value of this tuple to the scalar multiplication of itself.\r
67    * \r
68    * @param s\r
69    *        the scalar value\r
70    */\r
71   public final void scale4(float s) {\r
72     scale(s);\r
73     w *= s;\r
74   }\r
75 \r
76   /**\r
77    * Returns a hash number based on the data values in this object. Two\r
78    * different Tuple4f objects with identical data values (ie, returns true for\r
79    * equals(Tuple4f) ) will return the same hash number. Two vectors with\r
80    * different data members may return the same hash value, although this is not\r
81    * likely.\r
82    */\r
83   @Override\r
84   public int hashCode() {\r
85     return floatToIntBits0(x) ^ floatToIntBits0(y)\r
86         ^ floatToIntBits0(z) ^ floatToIntBits0(w);\r
87   }\r
88 \r
89   /**\r
90    * Returns true if all of the data members of Object are equal to the\r
91    * corresponding data members in this\r
92    * \r
93    * @param o\r
94    *        the vector with which the comparison is made.\r
95    */\r
96   @Override\r
97   public boolean equals(Object o) {\r
98     if (!(o instanceof T4))\r
99       return false;\r
100     T4 t = (T4) o;\r
101     return (this.x == t.x && this.y == t.y && this.z == t.z && this.w == t.w);\r
102   }\r
103 \r
104   /**\r
105    * Returns a string that contains the values of this Tuple4f. The form is\r
106    * (x,y,z,w).\r
107    * \r
108    * @return the String representation\r
109    */\r
110   @Override\r
111   public String toString() {\r
112     return "(" + x + ", " + y + ", " + z + ", " + w + ")";\r
113   }\r
114 \r
115   @Override\r
116   public String toJSON() {\r
117     return "[" + x + ", " + y + ", " + z + ", " + w + "]";\r
118   }\r
119 \r
120 }\r