Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / src / javajs / util / T4.java
1 /*
2    Copyright (C) 1997,1998,1999
3    Kenji Hiranabe, Eiwa System Management, Inc.
4
5    This program is free software.
6    Implemented by Kenji Hiranabe(hiranabe@esm.co.jp),
7    conforming to the Java(TM) 3D API specification by Sun Microsystems.
8
9    Permission to use, copy, modify, distribute and sell this software
10    and its documentation for any purpose is hereby granted without fee,
11    provided that the above copyright notice appear in all copies and
12    that both that copyright notice and this permission notice appear
13    in supporting documentation. Kenji Hiranabe and Eiwa System Management,Inc.
14    makes no representations about the suitability of this software for any
15    purpose.  It is provided "AS IS" with NO WARRANTY.
16 */
17 package javajs.util;
18
19 /**
20  * A generic 4 element tuple that is represented by single precision floating
21  * point x,y,z and w coordinates.
22  * 
23  * @version specification 1.1, implementation $Revision: 1.9 $, $Date:
24  *          2006/07/28 17:01:32 $
25  * @author Kenji hiranabe
26  * 
27  * additions by Bob Hanson hansonr@stolaf.edu 9/30/2012
28  * for unique constructor and method names
29  * for the optimization of compiled JavaScript using Java2Script
30  */
31 public abstract class T4 extends T3 {
32
33   /**
34    * The w coordinate.
35    */
36   public float w;
37
38   /**
39    * Constructs and initializes a Tuple4f to (0,0,0,0).
40    * 
41    * @j2sIgnore   * 
42    */
43   public T4() {
44   }
45
46   /**
47    * Sets the value of this tuple to the specified xyzw coordinates.
48    * 
49    * @param x
50    *        the x coordinate
51    * @param y
52    *        the y coordinate
53    * @param z
54    *        the z coordinate
55    * @param w
56    *        the w coordinate
57    */
58   public final void set4(float x, float y, float z, float w) {
59     this.x = x;
60     this.y = y;
61     this.z = z;
62     this.w = w;
63   }
64
65   /**
66    * Sets the value of this tuple to the scalar multiplication of itself.
67    * 
68    * @param s
69    *        the scalar value
70    */
71   public final void scale4(float s) {
72     scale(s);
73     w *= s;
74   }
75
76   /**
77    * Returns a hash number based on the data values in this object. Two
78    * different Tuple4f objects with identical data values (ie, returns true for
79    * equals(Tuple4f) ) will return the same hash number. Two vectors with
80    * different data members may return the same hash value, although this is not
81    * likely.
82    */
83   @Override
84   public int hashCode() {
85     return floatToIntBits0(x) ^ floatToIntBits0(y)
86         ^ floatToIntBits0(z) ^ floatToIntBits0(w);
87   }
88
89   /**
90    * Returns true if all of the data members of Object are equal to the
91    * corresponding data members in this
92    * 
93    * @param o
94    *        the vector with which the comparison is made.
95    */
96   @Override
97   public boolean equals(Object o) {
98     if (!(o instanceof T4))
99       return false;
100     T4 t = (T4) o;
101     return (this.x == t.x && this.y == t.y && this.z == t.z && this.w == t.w);
102   }
103
104   /**
105    * Returns a string that contains the values of this Tuple4f. The form is
106    * (x,y,z,w).
107    * 
108    * @return the String representation
109    */
110   @Override
111   public String toString() {
112     return "(" + x + ", " + y + ", " + z + ", " + w + ")";
113   }
114
115   @Override
116   public String toJSON() {
117     return "[" + x + ", " + y + ", " + z + ", " + w + "]";
118   }
119
120 }