Point3.java

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
 * 3D point.
36
 * 
37
 * A Point3 is a 3D location in an affine space described by three values along
38
 * the X, the Y and the Z axis. Note the difference with Vector3 wich is defined
39
 * as an array and ensures that the three coordinates X, Y and Z are consecutive
40
 * in memory. Here there are three separate attributes. Further, a point has no
41
 * vector arithmetic bound to it (to points cannot be added, this would have no
42
 * mathematical meaning).
43
 * 
44
 * @author Antoine Dutot
45
 * @since 19990829
46
 * @version 0.1
47
 */
48
public class Point3 extends Point2 implements java.io.Serializable {
49
	// Attributes
50
51
	private static final long serialVersionUID = 5971336344439693816L;
52
53
	/**
54
	 * Z axis value.
55
	 */
56
	public double z;
57
58
	// Attributes -- Shared
59
60
	/**
61
	 * Specific point at (0,0,0).
62
	 */
63
	public static final Point3 NULL_POINT3 = new Point3(0, 0, 0);
64
65
	// Constructors
66
67
	/**
68
	 * New 3D point at(0,0,0).
69
	 */
70
	public Point3() {
71
	}
72
73
	/**
74
	 * New 3D point at (x,y,0).
75
	 */
76
	public Point3(double x, double y) {
77 1 1. : removed call to org/graphstream/ui/geom/Point3::set → NO_COVERAGE
		set(x, y, 0);
78
	}
79
80
	/**
81
	 * New 3D point at(x,y,z).
82
	 */
83
	public Point3(double x, double y, double z) {
84 1 1. : removed call to org/graphstream/ui/geom/Point3::set → NO_COVERAGE
		set(x, y, z);
85
	}
86
87
	/**
88
	 * New copy of other.
89
	 */
90
	public Point3(Point3 other) {
91 1 1. : removed call to org/graphstream/ui/geom/Point3::copy → NO_COVERAGE
		copy(other);
92
	}
93
94
	public Point3(Vector3 vec) {
95 1 1. : removed call to org/graphstream/ui/geom/Point3::copy → NO_COVERAGE
		copy(vec);
96
	}
97
	
98
	public Point3(float data[]) {
99
		this(0, data);
100
	}
101
	
102
	public Point3(double data[]) {
103
		this(0, data);
104
	}
105
106
	public Point3(int start, float data[]) {
107 1 1. : negated conditional → NO_COVERAGE
		if(data != null) {
108 4 1. : changed conditional boundary → NO_COVERAGE
2. : Replaced integer addition with subtraction → NO_COVERAGE
3. : Replaced integer addition with subtraction → NO_COVERAGE
4. : negated conditional → NO_COVERAGE
			if(data.length>start+0) x = data[start+0];
109 4 1. : changed conditional boundary → NO_COVERAGE
2. : Replaced integer addition with subtraction → NO_COVERAGE
3. : Replaced integer addition with subtraction → NO_COVERAGE
4. : negated conditional → NO_COVERAGE
			if(data.length>start+1) y = data[start+1];
110 4 1. : changed conditional boundary → NO_COVERAGE
2. : Replaced integer addition with subtraction → NO_COVERAGE
3. : Replaced integer addition with subtraction → NO_COVERAGE
4. : negated conditional → NO_COVERAGE
			if(data.length>start+2) z = data[start+2];
111
		}
112
	}
113
	
114
	public Point3(int start, double data[]) {
115 1 1. : negated conditional → NO_COVERAGE
		if(data != null) {
116 4 1. : changed conditional boundary → NO_COVERAGE
2. : Replaced integer addition with subtraction → NO_COVERAGE
3. : Replaced integer addition with subtraction → NO_COVERAGE
4. : negated conditional → NO_COVERAGE
			if(data.length>start+0) x = data[start+0];
117 4 1. : changed conditional boundary → NO_COVERAGE
2. : Replaced integer addition with subtraction → NO_COVERAGE
3. : Replaced integer addition with subtraction → NO_COVERAGE
4. : negated conditional → NO_COVERAGE
			if(data.length>start+1) y = data[start+1];
118 4 1. : changed conditional boundary → NO_COVERAGE
2. : Replaced integer addition with subtraction → NO_COVERAGE
3. : Replaced integer addition with subtraction → NO_COVERAGE
4. : negated conditional → NO_COVERAGE
			if(data.length>start+2) z = data[start+2];
119
		}
120
	}
121
122
	// Predicates
123
124
	/**
125
	 * Are all components to zero?.
126
	 */
127
	@Override
128
	public boolean isZero() {
129 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 (x == 0 && y == 0 && z == 0);
130
	}
131
132
	// /**
133
	// * Is other equal to this ?
134
	// */
135
	// public boolean
136
	// equals( const Point3 < double > & other ) const
137
	// {
138
	// return( x == other.x
139
	// and y == other.y
140
	// and z == other.z );
141
	// }
142
143
	/**
144
	 * Create a new point linear interpolation of this and <code>other</code>.
145
	 * The new point is located between this and <code>other</code> if
146
	 * <code>factor</code> is between 0 and 1 (0 yields this point, 1 yields the
147
	 * <code>other</code> point).
148
	 */
149
	public Point3 interpolate(Point3 other, double factor) {
150 3 1. interpolate : Replaced double subtraction with addition → NO_COVERAGE
2. interpolate : Replaced double multiplication with division → NO_COVERAGE
3. interpolate : Replaced double addition with subtraction → NO_COVERAGE
		Point3 p = new Point3(x + ((other.x - x) * factor), y
151 6 1. interpolate : Replaced double subtraction with addition → NO_COVERAGE
2. interpolate : Replaced double multiplication with division → NO_COVERAGE
3. interpolate : Replaced double addition with subtraction → NO_COVERAGE
4. interpolate : Replaced double subtraction with addition → NO_COVERAGE
5. interpolate : Replaced double multiplication with division → NO_COVERAGE
6. interpolate : Replaced double addition with subtraction → NO_COVERAGE
				+ ((other.y - y) * factor), z + ((other.z - z) * factor));
152
153 1 1. interpolate : mutated return of Object value for org/graphstream/ui/geom/Point3::interpolate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return p;
154
	}
155
156
	/**
157
	 * Distance between this and <code>other</code>.
158
	 */
159
	public double distance(Point3 other) {
160 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double xx = other.x - x;
161 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double yy = other.y - y;
162 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double zz = other.z - z;
163 6 1. distance : Replaced double multiplication with division → NO_COVERAGE
2. distance : Replaced double multiplication with division → NO_COVERAGE
3. distance : Replaced double addition with subtraction → NO_COVERAGE
4. distance : Replaced double multiplication with division → NO_COVERAGE
5. distance : Replaced double addition with subtraction → NO_COVERAGE
6. distance : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Point3::distance → NO_COVERAGE
		return Math.abs(Math.sqrt((xx * xx) + (yy * yy) + (zz * zz)));
164
	}
165
166
	/**
167
	 * Distance between this and point (x,y,z).
168
	 */
169
	public double distance(double x, double y, double z) {
170 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double xx = x - this.x;
171 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double yy = y - this.y;
172 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double zz = z - this.z;
173 6 1. distance : Replaced double multiplication with division → NO_COVERAGE
2. distance : Replaced double multiplication with division → NO_COVERAGE
3. distance : Replaced double addition with subtraction → NO_COVERAGE
4. distance : Replaced double multiplication with division → NO_COVERAGE
5. distance : Replaced double addition with subtraction → NO_COVERAGE
6. distance : replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Point3::distance → NO_COVERAGE
		return Math.abs(Math.sqrt((xx * xx) + (yy * yy) + (zz * zz)));
174
	}
175
176
	// Commands
177
178
	/**
179
	 * Make this a copy of other.
180
	 */
181
	public void copy(Point3 other) {
182
		x = other.x;
183
		y = other.y;
184
		z = other.z;
185
	}
186
187
	public void copy(Vector3 vec) {
188
		x = vec.data[0];
189
		y = vec.data[1];
190
		z = vec.data[2];
191
	}
192
193
	/**
194
	 * Like #moveTo().
195
	 */
196
	public void set(double x, double y, double z) {
197
		this.x = x;
198
		this.y = y;
199
		this.z = z;
200
	}
201
202
	// Commands -- moving
203
204
	/**
205
	 * Move to absolute position (x,y,z).
206
	 */
207
	public void moveTo(double x, double y, double z) {
208
		this.x = x;
209
		this.y = y;
210
		this.z = z;
211
	}
212
213
	/**
214
	 * Move of given vector(dx,dy,dz).
215
	 */
216
	public void move(double dx, double dy, double dz) {
217 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.x += dx;
218 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.y += dy;
219 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.z += dz;
220
	}
221
222
	/**
223
	 * Move of given point <code>p</code>.
224
	 */
225
	public void move(Point3 p) {
226 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.x += p.x;
227 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.y += p.y;
228 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.z += p.z;
229
	}
230
231
	/**
232
	 * Move of given vector d.
233
	 */
234
	public void move(Vector3 d) {
235 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.x += d.data[0];
236 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.y += d.data[1];
237 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.z += d.data[2];
238
	}
239
240
	/**
241
	 * Move in depth of dz.
242
	 */
243
	public void moveZ(double dz) {
244 1 1. moveZ : Replaced double addition with subtraction → NO_COVERAGE
		z += dz;
245
	}
246
247
	/**
248
	 * Scale of factor (sx,sy,sz).
249
	 */
250
	public void scale(double sx, double sy, double sz) {
251 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		x *= sx;
252 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		y *= sy;
253 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		z *= sz;
254
	}
255
256
	/**
257
	 * Scale by factor s.
258
	 */
259
	public void scale(Point3 s) {
260 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		x *= s.x;
261 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		y *= s.y;
262 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		z *= s.z;
263
	}
264
265
	/**
266
	 * Scale by factor s.
267
	 */
268
	public void scale(Vector3 s) {
269 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		x *= s.data[0];
270 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		y *= s.data[1];
271 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		z *= s.data[2];
272
	}
273
274
	/**
275
	 * Scale by a given scalar.
276
	 * 
277
	 * @param scalar
278
	 *            The multiplier.
279
	 */
280
	public void scale(double scalar) {
281 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		x *= scalar;
282 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		y *= scalar;
283 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		z *= scalar;
284
	}
285
286
	/**
287
	 * Change only depth at absolute coordinate z.
288
	 */
289
	public void setZ(double z) {
290
		this.z = z;
291
	}
292
293
	/**
294
	 * Exchange the values of this and other.
295
	 */
296
	public void swap(Point3 other) {
297
		double t;
298
299 1 1. swap : negated conditional → NO_COVERAGE
		if (other != this) {
300
			t = this.x;
301
			this.x = other.x;
302
			other.x = t;
303
304
			t = this.y;
305
			this.y = other.y;
306
			other.y = t;
307
308
			t = this.z;
309
			this.z = other.z;
310
			other.z = t;
311
		}
312
	}
313
314
	// Commands -- misc.
315
316
	@Override
317
	public String toString() {
318
		StringBuffer buf;
319
320
		buf = new StringBuffer("Point3[");
321
322
		buf.append(x);
323
		buf.append('|');
324
		buf.append(y);
325
		buf.append('|');
326
		buf.append(z);
327
		buf.append("]");
328
329 1 1. toString : mutated return of Object value for org/graphstream/ui/geom/Point3::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return buf.toString();
330
	}
331
}

Mutations

77

1.1
Location :
Killed by : none
removed call to org/graphstream/ui/geom/Point3::set → NO_COVERAGE

84

1.1
Location :
Killed by : none
removed call to org/graphstream/ui/geom/Point3::set → NO_COVERAGE

91

1.1
Location :
Killed by : none
removed call to org/graphstream/ui/geom/Point3::copy → NO_COVERAGE

95

1.1
Location :
Killed by : none
removed call to org/graphstream/ui/geom/Point3::copy → NO_COVERAGE

107

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

108

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location :
Killed by : none
negated conditional → NO_COVERAGE

109

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location :
Killed by : none
negated conditional → NO_COVERAGE

110

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location :
Killed by : none
negated conditional → NO_COVERAGE

115

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

116

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location :
Killed by : none
negated conditional → NO_COVERAGE

117

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location :
Killed by : none
negated conditional → NO_COVERAGE

118

1.1
Location :
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

4.4
Location :
Killed by : none
negated conditional → NO_COVERAGE

129

1.1
Location : isZero
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : isZero
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : isZero
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : isZero
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

5.5
Location : isZero
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

150

1.1
Location : interpolate
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

2.2
Location : interpolate
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

3.3
Location : interpolate
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

151

1.1
Location : interpolate
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

2.2
Location : interpolate
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

3.3
Location : interpolate
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

4.4
Location : interpolate
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

5.5
Location : interpolate
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

6.6
Location : interpolate
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

153

1.1
Location : interpolate
Killed by : none
mutated return of Object value for org/graphstream/ui/geom/Point3::interpolate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

160

1.1
Location : distance
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

161

1.1
Location : distance
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

162

1.1
Location : distance
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

163

1.1
Location : distance
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

2.2
Location : distance
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

3.3
Location : distance
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

4.4
Location : distance
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

5.5
Location : distance
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

6.6
Location : distance
Killed by : none
replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Point3::distance → NO_COVERAGE

170

1.1
Location : distance
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

171

1.1
Location : distance
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

172

1.1
Location : distance
Killed by : none
Replaced double subtraction with addition → NO_COVERAGE

173

1.1
Location : distance
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

2.2
Location : distance
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

3.3
Location : distance
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

4.4
Location : distance
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

5.5
Location : distance
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

6.6
Location : distance
Killed by : none
replaced return of double value with -(x + 1) for org/graphstream/ui/geom/Point3::distance → NO_COVERAGE

217

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

218

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

219

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

226

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

227

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

228

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

235

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

236

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

237

1.1
Location : move
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

244

1.1
Location : moveZ
Killed by : none
Replaced double addition with subtraction → NO_COVERAGE

251

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

252

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

253

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

260

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

261

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

262

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

269

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

270

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

271

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

281

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

282

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

283

1.1
Location : scale
Killed by : none
Replaced double multiplication with division → NO_COVERAGE

299

1.1
Location : swap
Killed by : none
negated conditional → NO_COVERAGE

329

1.1
Location : toString
Killed by : none
mutated return of Object value for org/graphstream/ui/geom/Point3::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 0.33