]>
git.saurik.com Git - wxWidgets.git/blob - tests/graphics/affinematrix.cpp
c6a0696241f0f0b8d52a3cf9ab43f07263dd0c5c
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/affinetransform.cpp
3 // Purpose: Unit test for transformations implemented for wxAffineMatrix2D
4 // Author: Catalin Raceanu
6 // Copyright: (c) 2011 wxWidgets development team
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
19 #include "wx/dcmemory.h"
20 #include "wx/affinematrix2d.h"
23 #include "testimage.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 class AffineTransformTestCase
: public CppUnit::TestCase
32 AffineTransformTestCase()
34 wxImage::AddHandler(new wxJPEGHandler
);
40 CPPUNIT_TEST_SUITE( AffineTransformTestCase
);
41 CPPUNIT_TEST( InvertMatrix
);
42 #if wxUSE_DC_TRANSFORM_MATRIX
43 CPPUNIT_TEST( VMirrorAndTranslate
);
44 CPPUNIT_TEST( Rotate90Clockwise
);
45 #endif // wxUSE_DC_TRANSFORM_MATRIX
46 CPPUNIT_TEST_SUITE_END();
49 #if wxUSE_DC_TRANSFORM_MATRIX
50 void VMirrorAndTranslate();
51 void Rotate90Clockwise();
55 #endif // wxUSE_DC_TRANSFORM_MATRIX
57 DECLARE_NO_COPY_CLASS(AffineTransformTestCase
)
60 // register in the unnamed registry so that these tests are run by default
61 CPPUNIT_TEST_SUITE_REGISTRATION( AffineTransformTestCase
);
63 // also include in it's own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AffineTransformTestCase
, "AffineTransformTestCase" );
66 void AffineTransformTestCase::setUp()
68 #if wxUSE_DC_TRANSFORM_MATRIX
69 m_imgOrig
.LoadFile("horse.jpg");
71 CPPUNIT_ASSERT( m_imgOrig
.IsOk() );
73 m_bmpOrig
= wxBitmap(m_imgOrig
);
74 #endif // wxUSE_DC_TRANSFORM_MATRIX
77 void AffineTransformTestCase::InvertMatrix()
79 wxAffineMatrix2D matrix1
;
80 matrix1
.Set(wxMatrix2D(2, 1, 1, 1), wxPoint2DDouble(1, 1));
82 wxAffineMatrix2D
matrix2(matrix1
);
89 CPPUNIT_ASSERT_EQUAL( 1, (int)m
.m_11
);
90 CPPUNIT_ASSERT_EQUAL( -1, (int)m
.m_12
);
91 CPPUNIT_ASSERT_EQUAL( -1, (int)m
.m_21
);
92 CPPUNIT_ASSERT_EQUAL( 2, (int)m
.m_22
);
93 CPPUNIT_ASSERT_EQUAL( 0, (int)p
.m_x
);
94 CPPUNIT_ASSERT_EQUAL( -1, (int)p
.m_y
);
96 matrix2
.Concat(matrix1
);
97 CPPUNIT_ASSERT( matrix2
.IsIdentity() );
100 #if wxUSE_DC_TRANSFORM_MATRIX
102 void AffineTransformTestCase::VMirrorAndTranslate()
104 wxBitmap
bmpUsingMatrix(m_bmpOrig
.GetWidth(), m_bmpOrig
.GetHeight());
106 // build the mirrored image using the transformation matrix
108 wxMemoryDC
dc(bmpUsingMatrix
);
110 if ( !dc
.CanUseTransformMatrix() )
113 wxAffineMatrix2D matrix
;
114 matrix
.Mirror(wxVERTICAL
);
115 matrix
.Translate(0, m_bmpOrig
.GetHeight() - 1);
116 dc
.SetTransformMatrix(matrix
);
117 dc
.DrawBitmap(m_bmpOrig
, 0, 0);
120 CPPUNIT_ASSERT_EQUAL( bmpUsingMatrix
.ConvertToImage(),
121 m_imgOrig
.Mirror(false) );
124 void AffineTransformTestCase::Rotate90Clockwise()
126 wxBitmap
bmpUsingMatrix(m_bmpOrig
.GetHeight(), m_bmpOrig
.GetWidth());
128 // build the rotated image using the transformation matrix
130 wxMemoryDC
dc(bmpUsingMatrix
);
132 if ( !dc
.CanUseTransformMatrix() )
135 wxAffineMatrix2D matrix
;
136 matrix
.Rotate(-0.5 * M_PI
);
137 matrix
.Translate(m_bmpOrig
.GetHeight(), 0);
138 dc
.SetTransformMatrix(matrix
);
139 dc
.DrawBitmap(m_bmpOrig
, 0, 0);
142 CPPUNIT_ASSERT_EQUAL( bmpUsingMatrix
.ConvertToImage(),
143 m_imgOrig
.Rotate90(true) );
146 #endif // wxUSE_DC_TRANSFORM_MATRIX