]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/VecMathUtil.java
Fix enabled state of wall thickness
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / VecMathUtil.java
1 /*
2  * $RCSfile: VecMathUtil.java,v $
3  *
4  * Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
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.
12  *
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).
18  *
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.
22  *
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
25  * have any questions.
26  *
27  * $Revision: 1.5 $
28  * $Date: 2008/02/28 20:18:51 $
29  * $State: Exp $
30  */
31
32 package javax.vecmath;
33
34 /**
35  * Utility vecmath class used when computing the hash code for vecmath
36  * objects containing float or double values. This fixes Issue 36.
37  */
38 class VecMathUtil {
39     /**
40      * Returns the representation of the specified floating-point
41      * value according to the IEEE 754 floating-point "single format"
42      * bit layout, after first mapping -0.0 to 0.0. This method is
43      * identical to Float.floatToIntBits(float) except that an integer
44      * value of 0 is returned for a floating-point value of
45      * -0.0f. This is done for the purpose of computing a hash code
46      * that satisfies the contract of hashCode() and equals(). The
47      * equals() method in each vecmath class does a pair-wise "=="
48      * test on each floating-point field in the class (e.g., x, y, and
49      * z for a Tuple3f). Since 0.0f == -0.0f returns true,
50      * we must also return the same hash code for two objects, one of
51      * which has a field with a value of -0.0f and the other of which
52      * has a cooresponding field with a value of 0.0f.
53      *
54      * @param f an input floating-point number
55      * @return the integer bits representing that floating-point
56      * number, after first mapping -0.0f to 0.0f
57      */
58     static int floatToIntBits(float f) {
59         // Check for +0 or -0
60         if (f == 0.0f) {
61             return 0;
62         }
63         else {
64             return Float.floatToIntBits(f);
65         }
66     }
67
68     /**
69      * Returns the representation of the specified floating-point
70      * value according to the IEEE 754 floating-point "double format"
71      * bit layout, after first mapping -0.0 to 0.0. This method is
72      * identical to Double.doubleToLongBits(double) except that an
73      * integer value of 0L is returned for a floating-point value of
74      * -0.0. This is done for the purpose of computing a hash code
75      * that satisfies the contract of hashCode() and equals(). The
76      * equals() method in each vecmath class does a pair-wise "=="
77      * test on each floating-point field in the class (e.g., x, y, and
78      * z for a Tuple3d). Since 0.0 == -0.0 returns true, we
79      * must also return the same hash code for two objects, one of
80      * which has a field with a value of -0.0 and the other of which
81      * has a cooresponding field with a value of 0.0.
82      *
83      * @param d an input double precision floating-point number
84      * @return the integer bits representing that floating-point
85      * number, after first mapping -0.0f to 0.0f
86      */
87     static long doubleToLongBits(double d) {
88         // Check for +0 or -0
89         if (d == 0.0) {
90             return 0L;
91         }
92         else {
93             return Double.doubleToLongBits(d);
94         }
95     }
96
97
98     /**
99      * Do not construct an instance of this class.
100      */
101     private VecMathUtil() {
102     }
103 }