1 | /* | |
2 | * Copyright 2009 by Kevin Day. | |
3 | * | |
4 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
5 | * (the "License"); you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
7 | * | |
8 | * Software distributed under the License is distributed on an "AS IS" basis, | |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
10 | * for the specific language governing rights and limitations under the License. | |
11 | * | |
12 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
15 | * the Initial Developer are Copyright (C) 1999-2008 by Bruno Lowagie. | |
16 | * All Rights Reserved. | |
17 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
18 | * are Copyright (C) 2000-2008 by Paulo Soares. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): all the names of the contributors are added in the source code | |
21 | * where applicable. | |
22 | * | |
23 | * Alternatively, the contents of this file may be used under the terms of the | |
24 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
25 | * provisions of LGPL are applicable instead of those above. If you wish to | |
26 | * allow use of your version of this file only under the terms of the LGPL | |
27 | * License and not to allow others to use your version of this file under | |
28 | * the MPL, indicate your decision by deleting the provisions above and | |
29 | * replace them with the notice and other provisions required by the LGPL. | |
30 | * If you do not delete the provisions above, a recipient may use your version | |
31 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
32 | * | |
33 | * This library is free software; you can redistribute it and/or modify it | |
34 | * under the terms of the MPL as stated above or under the terms of the GNU | |
35 | * Library General Public License as published by the Free Software Foundation; | |
36 | * either version 2 of the License, or any later version. | |
37 | * | |
38 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
39 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
40 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
41 | * details. | |
42 | * | |
43 | * If you didn't download this code from the following link, you should check if | |
44 | * you aren't using an obsolete version: | |
45 | * http://www.lowagie.com/iText/ | |
46 | */ | |
47 | package com.lowagie.text.pdf.parser; | |
48 | ||
49 | /** | |
50 | * Represents a vector (i.e. a point in space). This class is completely | |
51 | * unrelated to the {@link java.util.Vector} class in the standard JRE. | |
52 | * <br><br> | |
53 | * For many PDF related operations, the z coordinate is specified as 1 | |
54 | * This is to support the coordinate transformation calculations. If it | |
55 | * helps, just think of all PDF drawing operations as occurring in a single plane | |
56 | * with z=1. | |
57 | */ | |
58 | @SuppressWarnings("WeakerAccess") | |
59 | public class Vector { | |
60 | /** | |
61 | * index of the X coordinate | |
62 | */ | |
63 | private static final int I1 = 0; | |
64 | /** | |
65 | * index of the Y coordinate | |
66 | */ | |
67 | private static final int I2 = 1; | |
68 | /** | |
69 | * index of the Z coordinate | |
70 | */ | |
71 | private static final int I3 = 2; | |
72 | ||
73 | /** | |
74 | * the values inside the vector | |
75 | */ | |
76 | private final float[] values = new float[]{ | |
77 | 0, 0, 0 | |
78 | }; | |
79 | ||
80 | /** | |
81 | * Creates a new Vector | |
82 | * | |
83 | * @param x the X coordinate | |
84 | * @param y the Y coordinate | |
85 | * @param z the Z coordinate | |
86 | */ | |
87 | public Vector(float x, float y, float z) { | |
88 | values[I1] = x; | |
89 | values[I2] = y; | |
90 | values[I3] = z; | |
91 | } | |
92 | ||
93 | /** | |
94 | * Gets the value from a coordinate of the vector | |
95 | * | |
96 | * @param index the index of the value to get (I1, I2 or I3) | |
97 | * @return value from a coordinate of the vector | |
98 | */ | |
99 | public float get(int index) { | |
100 |
1
1. get : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/Vector::get → NO_COVERAGE |
return values[index]; |
101 | } | |
102 | ||
103 | /** | |
104 | * Computes the cross product of this vector and the specified matrix | |
105 | * | |
106 | * @param by the matrix to cross this vector with | |
107 | * @return the result of the cross product | |
108 | */ | |
109 | public Vector cross(Matrix by) { | |
110 |
5
1. cross : Replaced float multiplication with division → NO_COVERAGE 2. cross : Replaced float multiplication with division → NO_COVERAGE 3. cross : Replaced float addition with subtraction → NO_COVERAGE 4. cross : Replaced float multiplication with division → NO_COVERAGE 5. cross : Replaced float addition with subtraction → NO_COVERAGE |
float x = values[I1] * by.get(Matrix.I11) + values[I2] * by.get(Matrix.I21) + values[I3] * by.get(Matrix.I31); |
111 |
5
1. cross : Replaced float multiplication with division → NO_COVERAGE 2. cross : Replaced float multiplication with division → NO_COVERAGE 3. cross : Replaced float addition with subtraction → NO_COVERAGE 4. cross : Replaced float multiplication with division → NO_COVERAGE 5. cross : Replaced float addition with subtraction → NO_COVERAGE |
float y = values[I1] * by.get(Matrix.I12) + values[I2] * by.get(Matrix.I22) + values[I3] * by.get(Matrix.I32); |
112 |
5
1. cross : Replaced float multiplication with division → NO_COVERAGE 2. cross : Replaced float multiplication with division → NO_COVERAGE 3. cross : Replaced float addition with subtraction → NO_COVERAGE 4. cross : Replaced float multiplication with division → NO_COVERAGE 5. cross : Replaced float addition with subtraction → NO_COVERAGE |
float z = values[I1] * by.get(Matrix.I13) + values[I2] * by.get(Matrix.I23) + values[I3] * by.get(Matrix.I33); |
113 | ||
114 |
1
1. cross : mutated return of Object value for com/lowagie/text/pdf/parser/Vector::cross to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Vector(x, y, z); |
115 | } | |
116 | ||
117 | /** | |
118 | * Computes the difference between this vector and the specified vector | |
119 | * | |
120 | * @param v the vector to subtract from this one | |
121 | * @return the results of the subtraction | |
122 | */ | |
123 | public Vector subtract(Vector v) { | |
124 |
1
1. subtract : Replaced float subtraction with addition → NO_COVERAGE |
float x = values[I1] - v.values[I1]; |
125 |
1
1. subtract : Replaced float subtraction with addition → NO_COVERAGE |
float y = values[I2] - v.values[I2]; |
126 |
1
1. subtract : Replaced float subtraction with addition → NO_COVERAGE |
float z = values[I3] - v.values[I3]; |
127 | ||
128 |
1
1. subtract : mutated return of Object value for com/lowagie/text/pdf/parser/Vector::subtract to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Vector(x, y, z); |
129 | } | |
130 | ||
131 | /** | |
132 | * Computes the sum of this vector and the specified vector | |
133 | * | |
134 | * @param v the vector to subtract from this one | |
135 | * @return the results of the subtraction | |
136 | */ | |
137 | public Vector add(Vector v) { | |
138 |
1
1. add : Replaced float addition with subtraction → NO_COVERAGE |
float x = values[I1] + v.values[I1]; |
139 |
1
1. add : Replaced float addition with subtraction → NO_COVERAGE |
float y = values[I2] + v.values[I2]; |
140 |
1
1. add : Replaced float addition with subtraction → NO_COVERAGE |
float z = values[I3] + v.values[I3]; |
141 | ||
142 |
1
1. add : mutated return of Object value for com/lowagie/text/pdf/parser/Vector::add to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Vector(x, y, z); |
143 | } | |
144 | ||
145 | /** | |
146 | * Computes the cross product of this vector and the specified vector | |
147 | * | |
148 | * @param with the vector to cross this vector with | |
149 | * @return the cross product | |
150 | */ | |
151 | public Vector cross(Vector with) { | |
152 |
3
1. cross : Replaced float multiplication with division → NO_COVERAGE 2. cross : Replaced float multiplication with division → NO_COVERAGE 3. cross : Replaced float subtraction with addition → NO_COVERAGE |
float x = values[I2] * with.values[I3] - values[I3] * with.values[I2]; |
153 |
3
1. cross : Replaced float multiplication with division → NO_COVERAGE 2. cross : Replaced float multiplication with division → NO_COVERAGE 3. cross : Replaced float subtraction with addition → NO_COVERAGE |
float y = values[I3] * with.values[I1] - values[I1] * with.values[I3]; |
154 |
3
1. cross : Replaced float multiplication with division → NO_COVERAGE 2. cross : Replaced float multiplication with division → NO_COVERAGE 3. cross : Replaced float subtraction with addition → NO_COVERAGE |
float z = values[I1] * with.values[I2] - values[I2] * with.values[I1]; |
155 | ||
156 |
1
1. cross : mutated return of Object value for com/lowagie/text/pdf/parser/Vector::cross to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Vector(x, y, z); |
157 | } | |
158 | ||
159 | /** | |
160 | * Computes the dot product of this vector with the specified vector | |
161 | * | |
162 | * @param with the vector to dot product this vector with | |
163 | * @return the dot product | |
164 | */ | |
165 | public float dot(Vector with) { | |
166 |
6
1. dot : Replaced float multiplication with division → NO_COVERAGE 2. dot : Replaced float multiplication with division → NO_COVERAGE 3. dot : Replaced float addition with subtraction → NO_COVERAGE 4. dot : Replaced float multiplication with division → NO_COVERAGE 5. dot : Replaced float addition with subtraction → NO_COVERAGE 6. dot : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/Vector::dot → NO_COVERAGE |
return values[I1] * with.values[I1] + values[I2] * with.values[I2] + values[I3] * with.values[I3]; |
167 | } | |
168 | ||
169 | /** | |
170 | * Computes the length of this vector | |
171 | * | |
172 | * <b>Note:</b> If you are working with raw vectors from PDF, be careful - | |
173 | * the Z axis will generally be set to 1. If you want to compute the | |
174 | * length of a vector, subtract it from the origin first (this will set | |
175 | * the Z axis to 0). | |
176 | * <p> | |
177 | * For example: | |
178 | * <code>aVector.subtract(originVector).length();</code> | |
179 | * | |
180 | * @return the length of this vector | |
181 | */ | |
182 | public float length() { | |
183 |
1
1. length : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/Vector::length → NO_COVERAGE |
return (float) Math.sqrt(lengthSquared()); |
184 | } | |
185 | ||
186 | /** | |
187 | * Computes the length squared of this vector. | |
188 | * <p> | |
189 | * The square of the length is less expensive to compute, and is often | |
190 | * useful without taking the square root. | |
191 | * <br><br> | |
192 | * <b>Note:</b> See the important note under {@link Vector#length()} | |
193 | * | |
194 | * @return the square of the length of the vector | |
195 | */ | |
196 | public float lengthSquared() { | |
197 |
6
1. lengthSquared : Replaced float multiplication with division → NO_COVERAGE 2. lengthSquared : Replaced float multiplication with division → NO_COVERAGE 3. lengthSquared : Replaced float addition with subtraction → NO_COVERAGE 4. lengthSquared : Replaced float multiplication with division → NO_COVERAGE 5. lengthSquared : Replaced float addition with subtraction → NO_COVERAGE 6. lengthSquared : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/Vector::lengthSquared → NO_COVERAGE |
return values[I1] * values[I1] + values[I2] * values[I2] + values[I3] * values[I3]; |
198 | } | |
199 | ||
200 | /** | |
201 | * @see java.lang.Object#toString() | |
202 | */ | |
203 | @Override | |
204 | public String toString() { | |
205 | return values[I1] + "," + values[I2] + "," + values[I3]; | |
206 | } | |
207 | } | |
Mutations | ||
100 |
1.1 |
|
110 |
1.1 2.2 3.3 4.4 5.5 |
|
111 |
1.1 2.2 3.3 4.4 5.5 |
|
112 |
1.1 2.2 3.3 4.4 5.5 |
|
114 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
128 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
140 |
1.1 |
|
142 |
1.1 |
|
152 |
1.1 2.2 3.3 |
|
153 |
1.1 2.2 3.3 |
|
154 |
1.1 2.2 3.3 |
|
156 |
1.1 |
|
166 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
183 |
1.1 |
|
197 |
1.1 2.2 3.3 4.4 5.5 6.6 |