Point2.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
 * 2D point.
36
 * 
37
 * A Point2 is a 2D location in an affine space described by three values along
38
 * the X, and Y axes. This differs from the Vector3 and Vector4 classes in that
39
 * it is only 2D and has no vector arithmetic bound to it (to points cannot be
40
 * added, this would have no mathematical meaning).
41
 * 
42
 * @author Antoine Dutot
43
 * @since 20001121 creation
44
 * @version 0.1
45
 */
46
public class Point2 implements java.io.Serializable {
47
	// Attributes
48
49
	private static final long serialVersionUID = 965985679540486895L;
50
51
	/**
52
	 * X axis value.
53
	 */
54
	public double x;
55
56
	/**
57
	 * Y axis value.
58
	 */
59
	public double y;
60
61
	// Attributes -- Shared
62
63
	/**
64
	 * Specific point at (0,0).
65
	 */
66
	public static final Point2 NULL_POINT2 = new Point2(0, 0);
67
68
	// Constructors
69
70
	/**
71
	 * New 2D point at (0,0).
72
	 */
73
	public Point2() {
74
	}
75
76
	/**
77
	 * New 2D point at (x,y).
78
	 */
79
	public Point2(double x, double y) {
80 1 1. : removed call to org/graphstream/ui/geom/Point2::set → NO_COVERAGE
		set(x, y);
81
	}
82
83
	/**
84
	 * New copy of other.
85
	 */
86
	public Point2(Point2 other) {
87 1 1. : removed call to org/graphstream/ui/geom/Point2::copy → NO_COVERAGE
		copy(other);
88
	}
89
90
	/**
91
	 * New 2D point at (x,y).
92
	 */
93
	public void make(double x, double y) {
94 1 1. make : removed call to org/graphstream/ui/geom/Point2::set → NO_COVERAGE
		set(x, y);
95
	}
96
97
	// Accessors
98
99
	/**
100
	 * Are all components to zero?.
101
	 */
102
	public boolean isZero() {
103 4 1. isZero : negated conditional → NO_COVERAGE
2. isZero : negated conditional → NO_COVERAGE
3. isZero : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
4. isZero : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
		return (x == 0 && y == 0);
104
	}
105
106
	// /**
107
	// * Is other equal to this ?
108
	// */
109
	// public boolean
110
	// equals( const Point2 < double > & other ) const
111
	// {
112
	// return( x == other.x
113
	// and y == other.y
114
	// and z == other.z );
115
	// }
116
117
	/**
118
	 * Create a new point linear interpolation of this and <code>other</code>.
119
	 * The new point is located between this and <code>other</code> if
120
	 * <code>factor</code> is between 0 and 1 (0 yields this point, 1 yields the
121
	 * <code>other</code> point).
122
	 */
123
	public Point2 interpolate(Point2 other, double factor) {
124 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
		Point2 p = new Point2(x + ((other.x - x) * factor), y
125 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
				+ ((other.y - y) * factor));
126
127 1 1. interpolate : mutated return of Object value for org/graphstream/ui/geom/Point2::interpolate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return p;
128
	}
129
130
	/**
131
	 * Distance between this and <code>other</code>.
132
	 */
133
	public double distance(Point2 other) {
134 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double xx = other.x - x;
135 1 1. distance : Replaced double subtraction with addition → NO_COVERAGE
		double yy = other.y - y;
136 4 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 return of double value with -(x + 1) for org/graphstream/ui/geom/Point2::distance → NO_COVERAGE
		return Math.abs(Math.sqrt((xx * xx) + (yy * yy)));
137
	}
138
139
	// Commands
140
141
	/**
142
	 * Make this a copy of other.
143
	 */
144
	public void copy(Point2 other) {
145
		x = other.x;
146
		y = other.y;
147
	}
148
149
	/**
150
	 * Like #moveTo().
151
	 */
152
	public void set(double x, double y) {
153
		this.x = x;
154
		this.y = y;
155
	}
156
157
	// Commands -- moving
158
159
	/**
160
	 * Move to absolute position (x,y).
161
	 */
162
	public void moveTo(double x, double y) {
163
		this.x = x;
164
		this.y = y;
165
	}
166
167
	/**
168
	 * Move of given vector (dx,dy).
169
	 */
170
	public void move(double dx, double dy) {
171 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.x += dx;
172 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.y += dy;
173
	}
174
175
	/**
176
	 * Move of given point <code>p</code>.
177
	 */
178
	public void move(Point2 p) {
179 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.x += p.x;
180 1 1. move : Replaced double addition with subtraction → NO_COVERAGE
		this.y += p.y;
181
	}
182
183
	/**
184
	 * Move horizontally of dx.
185
	 */
186
	public void moveX(double dx) {
187 1 1. moveX : Replaced double addition with subtraction → NO_COVERAGE
		x += dx;
188
	}
189
190
	/**
191
	 * Move vertically of dy.
192
	 */
193
	public void moveY(double dy) {
194 1 1. moveY : Replaced double addition with subtraction → NO_COVERAGE
		y += dy;
195
	}
196
197
	/**
198
	 * Scale of factor (sx,sy).
199
	 */
200
	public void scale(double sx, double sy) {
201 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		x *= sx;
202 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		y *= sy;
203
	}
204
205
	/**
206
	 * Scale by factor s.
207
	 */
208
	public void scale(Point2 s) {
209 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		x *= s.x;
210 1 1. scale : Replaced double multiplication with division → NO_COVERAGE
		y *= s.y;
211
	}
212
213
	/**
214
	 * Change only abscissa at absolute coordinate x.
215
	 */
216
	public void setX(double x) {
217
		this.x = x;
218
	}
219
220
	/**
221
	 * Change only ordinate at absolute coordinate y.
222
	 */
223
	public void setY(double y) {
224
		this.y = y;
225
	}
226
227
	/**
228
	 * Exchange the values of this and other.
229
	 */
230
	public void swap(Point2 other) {
231
		double t;
232
233 1 1. swap : negated conditional → NO_COVERAGE
		if (other != this) {
234
			t = this.x;
235
			this.x = other.x;
236
			other.x = t;
237
238
			t = this.y;
239
			this.y = other.y;
240
			other.y = t;
241
		}
242
	}
243
244
	// Commands -- misc.
245
246
	@Override
247
	public String toString() {
248
		StringBuffer buf;
249
250
		buf = new StringBuffer("Point2[");
251
252
		buf.append(x);
253
		buf.append('|');
254
		buf.append(y);
255
		buf.append("]");
256
257 1 1. toString : mutated return of Object value for org/graphstream/ui/geom/Point2::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return buf.toString();
258
	}
259
}

Mutations

80

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

87

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

94

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

103

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
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

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

124

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

125

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

127

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

134

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

135

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

136

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 return of double value with -(x + 1) for org/graphstream/ui/geom/Point2::distance → NO_COVERAGE

171

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

172

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

179

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

180

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

187

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

194

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

201

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

202

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

209

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

210

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

233

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

257

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

Active mutators

Tests examined


Report generated by PIT 0.33