Matrix.java

1
/*
2
 * Copyright 2008 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
import java.util.Arrays;
50
51
/**
52
 * Keeps all the values of a 3 by 3 matrix
53
 * and allows you to do some math with matrices.
54
 *
55
 * @since 2.1.4
56
 */
57
public class Matrix {
58
    /**
59
     * the row=1, col=1 position ('a') in the matrix.
60
     */
61
    public static final int I11 = 0;
62
    /**
63
     * the row=1, col=2 position ('b') in the matrix.
64
     */
65
    public static final int I12 = 1;
66
    /**
67
     * the row=1, col=3 position (always 0 for 2-D) in the matrix.
68
     */
69
    public static final int I13 = 2;
70
    /**
71
     * the row=2, col=1 position ('c') in the matrix.
72
     */
73
    public static final int I21 = 3;
74
    /**
75
     * the row=2, col=2 position ('d') in the matrix.
76
     */
77
    public static final int I22 = 4;
78
    /**
79
     * the row=2, col=3 position (always 0 for 2-D) in the matrix.
80
     */
81
    public static final int I23 = 5;
82
    /**
83
     * the row=3, col=1 ('e', or X translation) position in the matrix.
84
     */
85
    public static final int I31 = 6;
86
    /**
87
     * the row=3, col=2 ('f', or Y translation) position in the matrix.
88
     */
89
    public static final int I32 = 7;
90
    /**
91
     * the row=3, col=3 position (always 1 for 2-D) in the matrix.
92
     */
93
    public static final int I33 = 8;
94
95
    /**
96
     * the values inside the matrix (the identity matrix by default).
97
     */
98
    private final float[] vals = new float[]{
99
            1, 0, 0,
100
            0, 1, 0,
101
            0, 0, 1
102
    };
103
104
    /**
105
     * constructs a new Matrix with identity.
106
     */
107
    Matrix() {
108
    }
109
110
    /**
111
     * Constructs a matrix that represents translation
112
     *
113
     * @param tx
114
     * @param ty
115
     */
116
    Matrix(float tx, float ty) {
117
        vals[I31] = tx;
118
        vals[I32] = ty;
119
    }
120
121
    /**
122
     * Creates a Matrix with 6 specified entries
123
     *
124
     * @param a
125
     * @param b
126
     * @param c
127
     * @param d
128
     * @param e
129
     * @param f
130
     */
131
    Matrix(float a, float b, float c, float d, float e, float f) {
132
        vals[I11] = a;
133
        vals[I12] = b;
134
        vals[I13] = 0;
135
        vals[I21] = c;
136
        vals[I22] = d;
137
        vals[I23] = 0;
138
        vals[I31] = e;
139
        vals[I32] = f;
140
        vals[I33] = 1;
141
    }
142
143
    /**
144
     * Gets a specific value inside the matrix.
145
     *
146
     * @param index an array index corresponding with a value inside the matrix
147
     * @return the value at that specific position.
148
     */
149
    public float get(int index) {
150 1 1. get : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/Matrix::get → NO_COVERAGE
        return vals[index];
151
    }
152
153
    /**
154
     * multiplies this matrix by 'b' and returns the result
155
     * See http://en.wikipedia.org/wiki/Matrix_multiplication
156
     *
157
     * @param by The matrix to multiply by
158
     * @return the resulting matrix
159
     */
160
    @SuppressWarnings("Duplicates")
161
    public Matrix multiply(Matrix by) {
162
        Matrix result = new Matrix();
163
164
        float[] a = vals;
165
        float[] b = by.vals;
166
        float[] c = result.vals;
167
168 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I11] = a[I11] * b[I11] + a[I12] * b[I21] + a[I13] * b[I31];
169 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I12] = a[I11] * b[I12] + a[I12] * b[I22] + a[I13] * b[I32];
170 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I13] = a[I11] * b[I13] + a[I12] * b[I23] + a[I13] * b[I33];
171 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I21] = a[I21] * b[I11] + a[I22] * b[I21] + a[I23] * b[I31];
172 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I22] = a[I21] * b[I12] + a[I22] * b[I22] + a[I23] * b[I32];
173 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I23] = a[I21] * b[I13] + a[I22] * b[I23] + a[I23] * b[I33];
174 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I31] = a[I31] * b[I11] + a[I32] * b[I21] + a[I33] * b[I31];
175 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I32] = a[I31] * b[I12] + a[I32] * b[I22] + a[I33] * b[I32];
176 5 1. multiply : Replaced float multiplication with division → NO_COVERAGE
2. multiply : Replaced float multiplication with division → NO_COVERAGE
3. multiply : Replaced float addition with subtraction → NO_COVERAGE
4. multiply : Replaced float multiplication with division → NO_COVERAGE
5. multiply : Replaced float addition with subtraction → NO_COVERAGE
        c[I33] = a[I31] * b[I13] + a[I32] * b[I23] + a[I33] * b[I33];
177
178 1 1. multiply : mutated return of Object value for com/lowagie/text/pdf/parser/Matrix::multiply to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return result;
179
    }
180
181
    /**
182
     * Subtracts a matrix from this matrix and returns the results
183
     *
184
     * @param arg the matrix to subtract from this matrix
185
     * @return the resulting matrix
186
     */
187
    public Matrix subtract(Matrix arg) {
188
        Matrix result = new Matrix();
189
190
        float[] a = vals;
191
        float[] b = arg.vals;
192
        float[] c = result.vals;
193
194 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I11] = a[I11] - b[I11];
195 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I12] = a[I12] - b[I12];
196 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I13] = a[I13] - b[I13];
197 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I21] = a[I21] - b[I21];
198 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I22] = a[I22] - b[I22];
199 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I23] = a[I23] - b[I23];
200 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I31] = a[I31] - b[I31];
201 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I32] = a[I32] - b[I32];
202 1 1. subtract : Replaced float subtraction with addition → NO_COVERAGE
        c[I33] = a[I33] - b[I33];
203
204 1 1. subtract : mutated return of Object value for com/lowagie/text/pdf/parser/Matrix::subtract to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return result;
205
    }
206
207
    /**
208
     * Checks equality of matrices.
209
     *
210
     * @param obj the other Matrix that needs to be compared with this matrix.
211
     * @return true if both matrices are equal
212
     * @see java.lang.Object#equals(java.lang.Object)
213
     */
214
    @Override
215
    public boolean equals(Object obj) {
216 1 1. equals : negated conditional → NO_COVERAGE
        if (!(obj instanceof Matrix))
217 1 1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            return false;
218
219 1 1. equals : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return Arrays.equals(vals, ((Matrix) obj).vals);
220
    }
221
222
    /**
223
     * Generates a hash code for this object.
224
     *
225
     * @return the hash code of this object
226
     * @see java.lang.Object#hashCode()
227
     */
228
    @Override
229
    public int hashCode() {
230
        int result = 1;
231
        for (float val : vals) {
232
            result = 31 * result + Float.floatToIntBits(val);
233
        }
234
235
        return result;
236
    }
237
238
    /**
239
     * Generates a String representation of the matrix.
240
     *
241
     * @return the values, delimited with tabs and newlines.
242
     * @see java.lang.Object#toString()
243
     */
244
    @Override
245
    public String toString() {
246
        return vals[I11] + "\t" + vals[I12] + "\t" + vals[I13] + "\n" +
247
                vals[I21] + "\t" + vals[I22] + "\t" + vals[I13] + "\n" +
248
                vals[I31] + "\t" + vals[I32] + "\t" + vals[I33];
249
    }
250
}

Mutations

150

1.1
Location : get
Killed by : none
replaced return of float value with -(x + 1) for com/lowagie/text/pdf/parser/Matrix::get → NO_COVERAGE

168

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

169

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

170

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

171

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

172

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

173

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

174

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

175

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

176

1.1
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

2.2
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

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

4.4
Location : multiply
Killed by : none
Replaced float multiplication with division → NO_COVERAGE

5.5
Location : multiply
Killed by : none
Replaced float addition with subtraction → NO_COVERAGE

178

1.1
Location : multiply
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/parser/Matrix::multiply to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

194

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

195

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

196

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

197

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

198

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

199

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

200

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

201

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

202

1.1
Location : subtract
Killed by : none
Replaced float subtraction with addition → NO_COVERAGE

204

1.1
Location : subtract
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/parser/Matrix::subtract to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

216

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

217

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

219

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

Active mutators

Tests examined


Report generated by PIT 1.4.2