Skip to content

Commit bbb5a0e

Browse files
Samuel Huylebroeckitext-teamcity
authored andcommitted
Add addition method to matrix class
Add method, test, new constructor and improve existing javadocs Autoported commit. Original commit hash: [06d69f7cd]
1 parent f6347fb commit bbb5a0e

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

itext.tests/itext.kernel.tests/itext/kernel/geom/MatrixTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,25 @@ public virtual void TestDeterminant() {
5959
Matrix m = new Matrix(2, 3, 4, 5, 6, 7);
6060
NUnit.Framework.Assert.AreEqual(-2f, m.GetDeterminant(), .001f);
6161
}
62+
63+
/// <exception cref="System.Exception"/>
64+
[NUnit.Framework.Test]
65+
public virtual void TestSubtract() {
66+
Matrix m1 = new Matrix(1, 2, 3, 4, 5, 6);
67+
Matrix m2 = new Matrix(6, 5, 4, 3, 2, 1);
68+
Matrix shouldBe = new Matrix(-5, -3, 0, -1, 1, 0, 3, 5, 0);
69+
Matrix rslt = m1.Subtract(m2);
70+
NUnit.Framework.Assert.AreEqual(shouldBe, rslt);
71+
}
72+
73+
/// <exception cref="System.Exception"/>
74+
[NUnit.Framework.Test]
75+
public virtual void TestAdd() {
76+
Matrix m1 = new Matrix(1, 2, 3, 4, 5, 6);
77+
Matrix m2 = new Matrix(6, 5, 4, 3, 2, 1);
78+
Matrix shouldBe = new Matrix(7, 7, 0, 7, 7, 0, 7, 7, 2);
79+
Matrix rslt = m1.Add(m2);
80+
NUnit.Framework.Assert.AreEqual(shouldBe, rslt);
81+
}
6282
}
6383
}

itext/itext.kernel/itext/kernel/geom/Matrix.cs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,32 @@ public Matrix(float tx, float ty) {
9898
vals[I32] = ty;
9999
}
100100

101-
/// <summary>Creates a Matrix with 6 specified entries</summary>
102-
/// <param name="a"/>
103-
/// <param name="b"/>
104-
/// <param name="c"/>
105-
/// <param name="d"/>
106-
/// <param name="e"/>
107-
/// <param name="f"/>
101+
/// <summary>Creates a Matrix with 9 specified entries</summary>
102+
/// <param name="e11">element at position (1,1)</param>
103+
public Matrix(float e11, float e12, float e13, float e21, float e22, float e23, float e31, float e32, float
104+
e33) {
105+
vals[I11] = e11;
106+
vals[I12] = e12;
107+
vals[I13] = e13;
108+
vals[I21] = e21;
109+
vals[I22] = e22;
110+
vals[I23] = e23;
111+
vals[I31] = e31;
112+
vals[I32] = e32;
113+
vals[I33] = e33;
114+
}
115+
116+
/// <summary>
117+
/// Creates a Matrix with 6 specified entries
118+
/// The third column will always be [0 0 1]
119+
/// (row, column)
120+
/// </summary>
121+
/// <param name="a">element at (1,1)</param>
122+
/// <param name="b">element at (1,2)</param>
123+
/// <param name="c">element at (2,1)</param>
124+
/// <param name="d">element at (2,2)</param>
125+
/// <param name="e">element at (3,1)</param>
126+
/// <param name="f">element at (3,2)</param>
108127
public Matrix(float a, float b, float c, float d, float e, float f) {
109128
vals[I11] = a;
110129
vals[I12] = b;
@@ -154,6 +173,26 @@ public virtual iText.Kernel.Geom.Matrix Multiply(iText.Kernel.Geom.Matrix by) {
154173
return rslt;
155174
}
156175

176+
/// <summary>adds a matrix from this matrix and returns the results</summary>
177+
/// <param name="arg">the matrix to subtract from this matrix</param>
178+
/// <returns>a Matrix object</returns>
179+
public virtual iText.Kernel.Geom.Matrix Add(iText.Kernel.Geom.Matrix arg) {
180+
iText.Kernel.Geom.Matrix rslt = new iText.Kernel.Geom.Matrix();
181+
float[] a = vals;
182+
float[] b = arg.vals;
183+
float[] c = rslt.vals;
184+
c[I11] = a[I11] + b[I11];
185+
c[I12] = a[I12] + b[I12];
186+
c[I13] = a[I13] + b[I13];
187+
c[I21] = a[I21] + b[I21];
188+
c[I22] = a[I22] + b[I22];
189+
c[I23] = a[I23] + b[I23];
190+
c[I31] = a[I31] + b[I31];
191+
c[I32] = a[I32] + b[I32];
192+
c[I33] = a[I33] + b[I33];
193+
return rslt;
194+
}
195+
157196
/// <summary>Subtracts a matrix from this matrix and returns the results</summary>
158197
/// <param name="arg">the matrix to subtract from this matrix</param>
159198
/// <returns>a Matrix object</returns>

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4193350cb976df3b434e844e58d6d14513b8cb9c
1+
06d69f7cd6a8fb4ae0c78f98244e48c4d4257613

0 commit comments

Comments
 (0)