Under Original/Normal_Java/ one would find the original Labyrinth project ported...
[IRC.git] / Robust / src / Benchmarks / Java-Single / Labyrinth / mlp / rBlocked / Coordinate.java
1 /* =============================================================================
2  *
3  * coordinate.java 
4  *
5  * =============================================================================
6  * 
7  * Copyright (C) Stanford University, 2006.  All Rights Reserved.
8  * Author: Chi Cao Minh
9  * 
10  * =============================================================================
11  * 
12  * For the license of bayes/sort.h and bayes/sort.c, please see the header
13  * of the files.
14  *  
15  * ------------------------------------------------------------------------
16  * 
17  * For the license of kmeans, please see kmeans/LICENSE.kmeans
18  *  
19  * ------------------------------------------------------------------------
20  * 
21  * For the license of ssca2, please see ssca2/COPYRIGHT
22  * 
23  * ------------------------------------------------------------------------
24  * 
25  * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26  * header of the files.
27  * 
28  * ------------------------------------------------------------------------
29  * 
30  * For the license of lib/rbtree.h and lib/rbtree.c, please see
31  * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
32  * 
33  * ------------------------------------------------------------------------
34  * 
35  * Unless otherwise noted, the following license applies to STAMP files:
36  * 
37  * Copyright (c) 2007, Stanford University
38  * All rights reserved.
39  * 
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions are
42  * met:
43  * 
44  *     * Redistributions of source code must retain the above copyright
45  *       notice, this list of conditions and the following disclaimer.
46  * 
47  *     * Redistributions in binary form must reproduce the above copyright
48  *       notice, this list of conditions and the following disclaimer in
49  *       the documentation and/or other materials provided with the
50  *       distribution.
51  * 
52  *     * Neither the name of Stanford University nor the names of its
53  *      contributors may be used to endorse or promote products derived
54  *       from this software without specific prior written permission.
55  * 
56  * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66  * THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  * =============================================================================
69  */
70
71
72
73
74 import java.lang.Math;
75
76 public class Coordinate {
77
78     public int x;
79     public int y;
80     public int z;
81
82     public Coordinate() {}
83
84
85     // coordiate_alloc will be constructor
86     // coordinate_t* coordinate_alloc(long x, long y, long z)
87     public Coordinate(int x,int y,int z) {
88         this.x = x;
89         this.y = y;
90         this.z = z;
91     }
92
93     public Coordinate alloc(int x,int y,int z) {
94         Coordinate c = new Coordinate(x,y,z);
95
96         return c;
97     }
98
99     
100     // deallocate memory
101     // may not need
102     //  coordinate_free
103
104     /*========================================================
105     // coordinate_isEqual
106     ==========================================================*/
107     public static boolean isEqual(Coordinate a,Coordinate b) 
108     {
109         if((a.x == b.x) && (a.y == b.y) && (a.z == b.z))
110             return true;
111         
112         return false;
113     }
114
115     /*==========================================================
116       *
117       * getPairDistance
118       *
119       *========================================================*/   
120     private static double getPairDistance(Pair p)
121     {
122         Coordinate a = (Coordinate)p.first;
123         Coordinate b = (Coordinate)p.second;
124         int dx = a.x - b.x;
125         int dy = a.y - b.y;
126         int dz = a.z - b.z;
127         int dx2 = dx* dx;
128         int dy2 = dy* dy;
129         int dz2 = dz* dz;
130
131         return Math.sqrt((double)(dx2+dy2+dz2));
132     }
133
134
135     /*================================================
136     // coordinat_ comparePair
137      * -- For sorting in list of source/destination pairs
138      * -- Route longer paths first so they are more likely to suceed
139      
140     *================================================*/
141     public static int comparePair(final Object a,final Object b) 
142     {
143         double aDistance = getPairDistance((Pair)a);
144         double bDistance = getPairDistance((Pair)b);
145
146         if(aDistance < bDistance) {
147             return 1;
148         } else if(aDistance > bDistance) {
149             return -1;
150         }
151
152         return 0;
153     }
154
155     /*=======================================================
156       * coordinate_areAdjacent
157       *=======================================================*/
158
159     public static boolean areAdjacent(Coordinate a,Coordinate b) 
160     {
161         int dx = a.x - b.x;
162         int dy = a.y - b.y;
163         int dz = a.z - b.z;
164         int dx2 = dx * dx;
165         int dy2 = dy * dy;
166         int dz2 = dz * dz;
167
168         return (((dx2 + dy2 + dz2) == 1) ? true : false);
169     }
170     }
171
172     /*=====================================================
173       * 
174       * End of Coordinate
175       *
176       *====================================================*/
177     
178