1 | /* | |
2 | * Copyright 2006 - 2013 | |
3 | * Stefan Balev <stefan.balev@graphstream-project.org> | |
4 | * Julien Baudry <julien.baudry@graphstream-project.org> | |
5 | * Antoine Dutot <antoine.dutot@graphstream-project.org> | |
6 | * Yoann Pign�� <yoann.pigne@graphstream-project.org> | |
7 | * Guilhelm Savin <guilhelm.savin@graphstream-project.org> | |
8 | * | |
9 | * This file is part of GraphStream <http://graphstream-project.org>. | |
10 | * | |
11 | * GraphStream is a library whose purpose is to handle static or dynamic | |
12 | * graph, create them from scratch, file or any source and display them. | |
13 | * | |
14 | * This program is free software distributed under the terms of two licenses, the | |
15 | * CeCILL-C license that fits European law, and the GNU Lesser General Public | |
16 | * License. You can use, modify and/ or redistribute the software under the terms | |
17 | * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following | |
18 | * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by | |
19 | * the Free Software Foundation, either version 3 of the License, or (at your | |
20 | * option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
23 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
24 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU Lesser General Public License | |
27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28 | * | |
29 | * The fact that you are presently reading this means that you have had | |
30 | * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. | |
31 | */ | |
32 | package org.graphstream.ui.geom; | |
33 | ||
34 | /** | |
35 | * A three component vector made of doubles. | |
36 | * | |
37 | * @author Antoine Dutot | |
38 | * @since 20000613 | |
39 | * @version 0.1 | |
40 | */ | |
41 | public class Vector3 extends Vector2 { | |
42 | // Attributes: | |
43 | ||
44 | private static final long serialVersionUID = 8839258036865851454L; | |
45 | ||
46 | // Constructors | |
47 | ||
48 | /** | |
49 | * New zero vector. | |
50 | */ | |
51 | public Vector3() { | |
52 | data = new double[3]; | |
53 | data[0] = 0; | |
54 | data[1] = 0; | |
55 | data[2] = 0; | |
56 | } | |
57 | ||
58 | /** | |
59 | * New (<code>x</code>,<code>y</code>,<code>z</code>) vector. | |
60 | */ | |
61 | public Vector3(double x, double y, double z) { | |
62 | data = new double[3]; | |
63 | data[0] = x; | |
64 | data[1] = y; | |
65 | data[2] = z; | |
66 | } | |
67 | ||
68 | /** | |
69 | * New vector copy of <code>other</code>. | |
70 | */ | |
71 | public Vector3(Vector3 other) { | |
72 | data = new double[3]; | |
73 |
1
1. |
copy(other); |
74 | } | |
75 | ||
76 | /** | |
77 | * New vector copy of <code>point</code>. | |
78 | */ | |
79 | public Vector3(Point3 point) { | |
80 | data = new double[3]; | |
81 |
1
1. |
copy(point); |
82 | } | |
83 | ||
84 | // Predicates | |
85 | ||
86 | /** | |
87 | * Are all components to zero?. | |
88 | */ | |
89 | @Override | |
90 | public boolean isZero() { | |
91 |
5
1. isZero : negated conditional → NO_COVERAGE 2. isZero : negated conditional → NO_COVERAGE 3. isZero : negated conditional → NO_COVERAGE 4. isZero : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 5. isZero : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (data[0] == 0 && data[1] == 0 && data[2] == 0); |
92 | } | |
93 | ||
94 | /** | |
95 | * Is this equal to other ? | |
96 | */ | |
97 | @Override | |
98 | public boolean equals(Object other) { | |
99 | Vector3 v; | |
100 | ||
101 |
1
1. equals : negated conditional → NO_COVERAGE |
if (!(other instanceof Vector3)) { |
102 |
1
1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
103 | } | |
104 | ||
105 | v = (Vector3) other; | |
106 | ||
107 |
5
1. equals : negated conditional → NO_COVERAGE 2. equals : negated conditional → NO_COVERAGE 3. equals : negated conditional → NO_COVERAGE 4. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 5. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (data[0] == v.data[0] && data[1] == v.data[1] && data[2] == v.data[2]); |
108 | } | |
109 | ||
110 | /** | |
111 | * Is i the index of a component ? | |
112 | * | |
113 | * In other words, is i >= 0 && < than #count() ? | |
114 | */ | |
115 | @Override | |
116 | public boolean validComponent(int i) { | |
117 |
6
1. validComponent : changed conditional boundary → NO_COVERAGE 2. validComponent : changed conditional boundary → NO_COVERAGE 3. validComponent : negated conditional → NO_COVERAGE 4. validComponent : negated conditional → NO_COVERAGE 5. validComponent : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 6. validComponent : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (i >= 0 && i < 3); |
118 | } | |
119 | ||
120 | // Access | |
121 | ||
122 | @Override | |
123 | public Object clone() { | |
124 |
1
1. clone : mutated return of Object value for org/graphstream/ui/geom/Vector3::clone to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Vector3(this); |
125 | } | |
126 | ||
127 | // Access | |
128 | ||
129 | public double dotProduct(double ox, double oy, double oz) { | |
130 |
6
1. dotProduct : Replaced double multiplication with division → NO_COVERAGE 2. dotProduct : Replaced double multiplication with division → NO_COVERAGE 3. dotProduct : Replaced double addition with subtraction → NO_COVERAGE 4. dotProduct : Replaced double multiplication with division → NO_COVERAGE 5. dotProduct : Replaced double addition with subtraction → NO_COVERAGE 6. dotProduct : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Vector3::dotProduct → NO_COVERAGE |
return ((data[0] * ox) + (data[1] * oy) + (data[2] * oz)); |
131 | } | |
132 | ||
133 | /** | |
134 | * Dot product of this and other. | |
135 | */ | |
136 | public double dotProduct(Vector3 other) { | |
137 |
6
1. dotProduct : Replaced double multiplication with division → NO_COVERAGE 2. dotProduct : Replaced double multiplication with division → NO_COVERAGE 3. dotProduct : Replaced double addition with subtraction → NO_COVERAGE 4. dotProduct : Replaced double multiplication with division → NO_COVERAGE 5. dotProduct : Replaced double addition with subtraction → NO_COVERAGE 6. dotProduct : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Vector3::dotProduct → NO_COVERAGE |
return ((data[0] * other.data[0]) + (data[1] * other.data[1]) + (data[2] * other.data[2])); |
138 | } | |
139 | ||
140 | /** | |
141 | * Cartesian length. | |
142 | */ | |
143 | @Override | |
144 | public double length() { | |
145 |
5
1. length : Replaced double multiplication with division → NO_COVERAGE 2. length : Replaced double multiplication with division → NO_COVERAGE 3. length : Replaced double addition with subtraction → NO_COVERAGE 4. length : Replaced double addition with subtraction → NO_COVERAGE 5. length : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Vector3::length → NO_COVERAGE |
return Math.sqrt((data[0] * data[0]) + (data[1] * data[1]) |
146 |
1
1. length : Replaced double multiplication with division → NO_COVERAGE |
+ (data[2] * data[2])); |
147 | } | |
148 | | |
149 | public double z() { | |
150 |
1
1. z : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Vector3::z → NO_COVERAGE |
return data[2]; |
151 | } | |
152 | ||
153 | // Commands | |
154 | ||
155 | /** | |
156 | * Assign value to all elements. | |
157 | */ | |
158 | @Override | |
159 | public void fill(double value) { | |
160 | data[0] = data[1] = data[2] = value; | |
161 | } | |
162 | ||
163 | /** | |
164 | * Explicitly set the i-th component to value. | |
165 | */ | |
166 | @Override | |
167 | public void set(int i, double value) { | |
168 | data[i] = value; | |
169 | } | |
170 | ||
171 | /** | |
172 | * Explicitly set the three components. | |
173 | */ | |
174 | public void set(double x, double y, double z) { | |
175 | data[0] = x; | |
176 | data[1] = y; | |
177 | data[2] = z; | |
178 | } | |
179 | ||
180 | /** | |
181 | * Add each element of other to the corresponding element of this. | |
182 | */ | |
183 | public void add(Vector3 other) { | |
184 |
1
1. add : Replaced double addition with subtraction → NO_COVERAGE |
data[0] += other.data[0]; |
185 |
1
1. add : Replaced double addition with subtraction → NO_COVERAGE |
data[1] += other.data[1]; |
186 |
1
1. add : Replaced double addition with subtraction → NO_COVERAGE |
data[2] += other.data[2]; |
187 | } | |
188 | ||
189 | /** | |
190 | * Substract each element of other to the corresponding element of this. | |
191 | */ | |
192 | public void sub(Vector3 other) { | |
193 |
1
1. sub : Replaced double subtraction with addition → NO_COVERAGE |
data[0] -= other.data[0]; |
194 |
1
1. sub : Replaced double subtraction with addition → NO_COVERAGE |
data[1] -= other.data[1]; |
195 |
1
1. sub : Replaced double subtraction with addition → NO_COVERAGE |
data[2] -= other.data[2]; |
196 | } | |
197 | ||
198 | /** | |
199 | * Multiply each element of this by the corresponding element of other. | |
200 | */ | |
201 | public void mult(Vector3 other) { | |
202 |
1
1. mult : Replaced double multiplication with division → NO_COVERAGE |
data[0] *= other.data[0]; |
203 |
1
1. mult : Replaced double multiplication with division → NO_COVERAGE |
data[1] *= other.data[1]; |
204 |
1
1. mult : Replaced double multiplication with division → NO_COVERAGE |
data[2] *= other.data[2]; |
205 | } | |
206 | ||
207 | /** | |
208 | * Add value to each element. | |
209 | */ | |
210 | @Override | |
211 | public void scalarAdd(double value) { | |
212 |
1
1. scalarAdd : Replaced double addition with subtraction → NO_COVERAGE |
data[0] += value; |
213 |
1
1. scalarAdd : Replaced double addition with subtraction → NO_COVERAGE |
data[1] += value; |
214 |
1
1. scalarAdd : Replaced double addition with subtraction → NO_COVERAGE |
data[2] += value; |
215 | } | |
216 | ||
217 | /** | |
218 | * Substract value to each element. | |
219 | */ | |
220 | @Override | |
221 | public void scalarSub(double value) { | |
222 |
1
1. scalarSub : Replaced double subtraction with addition → NO_COVERAGE |
data[0] -= value; |
223 |
1
1. scalarSub : Replaced double subtraction with addition → NO_COVERAGE |
data[1] -= value; |
224 |
1
1. scalarSub : Replaced double subtraction with addition → NO_COVERAGE |
data[2] -= value; |
225 | } | |
226 | ||
227 | /** | |
228 | * Multiply each element by value. | |
229 | */ | |
230 | @Override | |
231 | public void scalarMult(double value) { | |
232 |
1
1. scalarMult : Replaced double multiplication with division → NO_COVERAGE |
data[0] *= value; |
233 |
1
1. scalarMult : Replaced double multiplication with division → NO_COVERAGE |
data[1] *= value; |
234 |
1
1. scalarMult : Replaced double multiplication with division → NO_COVERAGE |
data[2] *= value; |
235 | } | |
236 | ||
237 | /** | |
238 | * Divide each element by value. | |
239 | */ | |
240 | @Override | |
241 | public void scalarDiv(double value) { | |
242 |
1
1. scalarDiv : Replaced double division with multiplication → NO_COVERAGE |
data[0] /= value; |
243 |
1
1. scalarDiv : Replaced double division with multiplication → NO_COVERAGE |
data[1] /= value; |
244 |
1
1. scalarDiv : Replaced double division with multiplication → NO_COVERAGE |
data[2] /= value; |
245 | } | |
246 | ||
247 | /** | |
248 | * Set this to the cross product of this and other. | |
249 | */ | |
250 | public void crossProduct(Vector3 other) { | |
251 | double x; | |
252 | double y; | |
253 | ||
254 |
3
1. crossProduct : Replaced double multiplication with division → NO_COVERAGE 2. crossProduct : Replaced double multiplication with division → NO_COVERAGE 3. crossProduct : Replaced double subtraction with addition → NO_COVERAGE |
x = (data[1] * other.data[2]) - (data[2] * other.data[1]); |
255 |
3
1. crossProduct : Replaced double multiplication with division → NO_COVERAGE 2. crossProduct : Replaced double multiplication with division → NO_COVERAGE 3. crossProduct : Replaced double subtraction with addition → NO_COVERAGE |
y = (data[2] * other.data[0]) - (data[0] * other.data[2]); |
256 |
3
1. crossProduct : Replaced double multiplication with division → NO_COVERAGE 2. crossProduct : Replaced double multiplication with division → NO_COVERAGE 3. crossProduct : Replaced double subtraction with addition → NO_COVERAGE |
data[2] = (data[0] * other.data[1]) - (data[1] * other.data[0]); |
257 | data[0] = x; | |
258 | data[1] = y; | |
259 | } | |
260 | ||
261 | /** | |
262 | * Set this to the cross product of A and B. | |
263 | */ | |
264 | public void crossProduct(Vector3 A, Vector3 B) { | |
265 |
3
1. crossProduct : Replaced double multiplication with division → NO_COVERAGE 2. crossProduct : Replaced double multiplication with division → NO_COVERAGE 3. crossProduct : Replaced double subtraction with addition → NO_COVERAGE |
data[0] = (A.data[1] * B.data[2]) - (A.data[2] * B.data[1]); |
266 |
3
1. crossProduct : Replaced double multiplication with division → NO_COVERAGE 2. crossProduct : Replaced double multiplication with division → NO_COVERAGE 3. crossProduct : Replaced double subtraction with addition → NO_COVERAGE |
data[1] = (A.data[2] * B.data[0]) - (A.data[0] * B.data[2]); |
267 |
3
1. crossProduct : Replaced double multiplication with division → NO_COVERAGE 2. crossProduct : Replaced double multiplication with division → NO_COVERAGE 3. crossProduct : Replaced double subtraction with addition → NO_COVERAGE |
data[2] = (A.data[0] * B.data[1]) - (A.data[1] * B.data[0]); |
268 | } | |
269 | ||
270 | /** | |
271 | * Transform this into an unit vector. | |
272 | * | |
273 | * @return the vector length. | |
274 | */ | |
275 | @Override | |
276 | public double normalize() { | |
277 | double len = length(); | |
278 | ||
279 |
1
1. normalize : negated conditional → NO_COVERAGE |
if (len != 0) { |
280 |
1
1. normalize : Replaced double division with multiplication → NO_COVERAGE |
data[0] /= len; |
281 |
1
1. normalize : Replaced double division with multiplication → NO_COVERAGE |
data[1] /= len; |
282 |
1
1. normalize : Replaced double division with multiplication → NO_COVERAGE |
data[2] /= len; |
283 | } | |
284 | ||
285 |
1
1. normalize : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Vector3::normalize → NO_COVERAGE |
return len; |
286 | } | |
287 | ||
288 | // Utility | |
289 | ||
290 | /** | |
291 | * Make this a copy of other. | |
292 | */ | |
293 | public void copy(Vector3 other) { | |
294 | data[0] = other.data[0]; | |
295 | data[1] = other.data[1]; | |
296 | data[2] = other.data[2]; | |
297 | } | |
298 | ||
299 | /** | |
300 | * Make this a copy of <code>point</code>. | |
301 | */ | |
302 | public void copy(Point3 point) { | |
303 | data[0] = point.x; | |
304 | data[1] = point.y; | |
305 | data[2] = point.z; | |
306 | } | |
307 | ||
308 | // Misc. | |
309 | ||
310 | @Override | |
311 | public String toString() { | |
312 | StringBuffer sb = new StringBuffer("["); | |
313 | ||
314 | sb.append(data[0]); | |
315 | sb.append('|'); | |
316 | sb.append(data[1]); | |
317 | sb.append('|'); | |
318 | sb.append(data[2]); | |
319 | sb.append(']'); | |
320 | ||
321 |
1
1. toString : mutated return of Object value for org/graphstream/ui/geom/Vector3::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return sb.toString(); |
322 | } | |
323 | } | |
Mutations | ||
73 |
1.1 |
|
81 |
1.1 |
|
91 |
1.1 2.2 3.3 4.4 5.5 |
|
101 |
1.1 |
|
102 |
1.1 |
|
107 |
1.1 2.2 3.3 4.4 5.5 |
|
117 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
124 |
1.1 |
|
130 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
137 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
145 |
1.1 2.2 3.3 4.4 5.5 |
|
146 |
1.1 |
|
150 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
186 |
1.1 |
|
193 |
1.1 |
|
194 |
1.1 |
|
195 |
1.1 |
|
202 |
1.1 |
|
203 |
1.1 |
|
204 |
1.1 |
|
212 |
1.1 |
|
213 |
1.1 |
|
214 |
1.1 |
|
222 |
1.1 |
|
223 |
1.1 |
|
224 |
1.1 |
|
232 |
1.1 |
|
233 |
1.1 |
|
234 |
1.1 |
|
242 |
1.1 |
|
243 |
1.1 |
|
244 |
1.1 |
|
254 |
1.1 2.2 3.3 |
|
255 |
1.1 2.2 3.3 |
|
256 |
1.1 2.2 3.3 |
|
265 |
1.1 2.2 3.3 |
|
266 |
1.1 2.2 3.3 |
|
267 |
1.1 2.2 3.3 |
|
279 |
1.1 |
|
280 |
1.1 |
|
281 |
1.1 |
|
282 |
1.1 |
|
285 |
1.1 |
|
321 |
1.1 |