Skip to content

Instantly share code, notes, and snippets.

@jpt1122
Created April 17, 2016 07:27
Show Gist options
  • Save jpt1122/213d23181a099e4100d863ac9c82572c to your computer and use it in GitHub Desktop.
Save jpt1122/213d23181a099e4100d863ac9c82572c to your computer and use it in GitHub Desktop.
Here is some more sample code demonstrating matrix equivalence based on the order of operations on that matrix
public class TestMatrix
{
public static void test(SomeActivity a)
{
test1(a);
test2(a);
test3(a);
}
public static void test1(SomeActivity a)
{
Matrix m1 = new Matrix();
m1.setScale(2, 2);
m1.preScale(2, 2);
m1.postScale(2, 2);
Matrix m2 = new Matrix();
m2.postScale(2, 2);
m2.postScale(2, 2);
m2.postScale(2, 2);
assertL("test1",a,m1,m2,"m1 and m2 will be same");
}
public static void test2(SomeActivity a)
{
Matrix m1 = new Matrix();
m1.setScale(2, 2);
m1.preTranslate(-2, -2);
m1.postTranslate(2, 2);
Matrix m2 = new Matrix();
m2.postTranslate(-2, -2);
m2.postScale(2, 2);
m2.postTranslate(2, 2);
assertL("test2",a,m1,m2,"m1 and m2 will be the same");
}
public static void test3(SomeActivity a)
{
Matrix m1 = new Matrix();
m1.setScale(2, 2);
m1.preTranslate(-2, -2);
m1.postTranslate(2, 2);
Matrix m2 = new Matrix();
m2.preTranslate(-2, -2);
m2.postTranslate(2, 2);
m2.setScale(2, 2);
assertL("test4",a,m1,m2,"m1 and m2 will not be the same");
Matrix m3 = new Matrix();
m3.setScale(2, 2);
assertL("test3",a,m2,m3,"m2 and m3 will be the same");
}
private static void assertL(String testName
, SomeActivity a
, Matrix m1
, Matrix m2
, String assertText)
{
if (m1.equals(m2))
{
a.appendText("\n" + testName + ": m1 is same as m2");
}
else
{
a.appendText("\n" + testName + ": m1 is NOT same as m2");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment