using System.Drawing.Drawing2D ; using System.Drawing; using System; using System.Text.RegularExpressions; using System.Reflection; public class TestRegionData { public void TestInfinite() { myRegion = new Region ( new Rectangle( 3,2,4,5 ) ); myRegion.MakeInfinite(); } public void TestEmpty() { myRegion = new Region ( new Rectangle( 3,2,4,5 ) ); myRegion.MakeEmpty(); } public void TestRectangle01() { myRegion = new Region ( new Rectangle( 0,0,2,3 ) ); } public void TestRectangle02() { myRegion = new Region ( new RectangleF( 0.5f, -2.75f, 21.125f, 19.625f ) ); } public void TestRegion() { myRegion = new Region( new Rectangle(6,6,8,8 ) ); myRegion.Exclude( new RectangleF( 0,0,3,4.3f ) ); myRegion.Xor( new RectangleF( 0,0.002f,3,4.3f ) ); myRegion.Union( new RectangleF( -1,-1,44,33 ) ); Region r = new Region( new Rectangle(-8,0,2,66) ); r.Complement( new RectangleF( -1,-1,3,39 ) ); r.Union( new Rectangle( 6,44,72,72 ) ); myRegion.Intersect(r); } public void TestIntersect() { myRegion = new Region ( new RectangleF( 0.5f, -2.75f, 21.125f, 19.625f ) ); myRegion.Intersect( new Rectangle( 0 ,0 , 5, 7 ) ); } public void TestUnion() { myRegion = new Region ( new RectangleF( -0.5f, -4.75f, 2.125f, 2.625f ) ); myRegion.Union( new Rectangle( -5 ,-5 , 5, 5 ) ); myRegion.Union( new Rectangle( 9, 9, 2, 3 ) ); } public void TestXor() { myRegion = new Region ( new Rectangle( 0, 0, 2 , 3 ) ); myRegion.Xor( new Rectangle( 3, 3, 4 , 7 ) ); } public void TestExclude() { myRegion = new Region ( new Rectangle( 0, -3, 7 , 3 ) ); myRegion.Exclude( new Rectangle( 3, 3, 4 , 1 ) ); } public void TestComplement() { myRegion = new Region ( new Rectangle( 0, 5, 7 , 12 ) ); myRegion.Complement( new Rectangle( 3, 3, 4 , 8 ) ); } public void TestTransform01() { myRegion = new Region( new Rectangle(-43,32,100,234) ); myRegion.Union( new RectangleF( -1,-1,44,33 ) ); myRegion.MakeEmpty(); Matrix m = new Matrix( -0.25f, 0.0f, 0.0f, -0.2343f, -0.1f, -0.4f ) ; myRegion.Transform( m ) ; } public void TestTransform02() { myRegion = new Region( new Rectangle(6, -7, 8, 34 ) ); myRegion.Xor( new RectangleF( 0, 0.002f, 3, 4.3f ) ); Matrix m = new Matrix( -0.125f, 0.0f, 0.0f, 1.5f, 0.0f, -4.023f ) ; myRegion.Transform( m ) ; } public void TestTransform05() { myRegion = new Region( new Rectangle(6,6,8,8 ) ); myRegion.Exclude( new RectangleF( 0,0,3,4.3f ) ); myRegion.Xor( new RectangleF( 0,0.002f,3,4.3f ) ); myRegion.Union( new RectangleF( -1,-1,44,33 ) ); Region r = new Region( new Rectangle(-8,0,2,66) ); r.Complement( new RectangleF( -1,-1,3,39 ) ); r.Union( new Rectangle( 6,44,72,72 ) ); myRegion.Intersect(r); Matrix m = new Matrix( 0.0f, 0.0f, 0.0f, -34.2343f, 0.0f, 0.0f ) ; myRegion.Transform( m ) ; } public void TestTransform03() { myRegion = new Region( new Rectangle(-43,32,100,234) ); myRegion.Union( new RectangleF( -1,-1,44,33 ) ); Region r = new Region( new Rectangle(-8,0,2,66) ); r.Union( new Rectangle( 6,44,72,72 ) ); myRegion.Intersect(r); Matrix m = new Matrix( -0.25f, 0.0f, 0.0f, -0.2343f, -0.1f, -0.4f ) ; myRegion.Transform( m ) ; } public void TestTransform04() { myRegion = new Region( new Rectangle(-43,32,100,234) ); myRegion.Union( new RectangleF( -1,-1,44,33 ) ); myRegion.MakeEmpty(); Matrix m = new Matrix( -0.25f, 23.0f, -20.0f, -0.2343f, -0.1f, -0.4f ) ; myRegion.Transform( m ) ; } public void TestTransform06() { myRegion = new Region( new Rectangle(-43,32,100,234) ); myRegion.Union( new RectangleF( -1,-1,44,33 ) ); myRegion.Union( new RectangleF( 45,32,44,44 ) ); Matrix m = new Matrix( -0.33f, 0.0f, 0.0f, -2.2f, 2.1f, -3.411f ) ; myRegion.Transform( m ) ; } public void TestTranslate01() { myRegion = new Region(); myRegion.MakeInfinite(); myRegion.Translate( -2, 20 ); } public void TestTranslate02() { myRegion = new Region( new Rectangle(-2,-2,200,200) ); myRegion.Intersect( new RectangleF( .023f, 2.2f, 12.01f, 11.999f ) ); myRegion.Xor( new RectangleF( 50,50,2,2 ) ); myRegion.Xor( new RectangleF( 23,24,2,2 ) ); myRegion.Exclude( new RectangleF( 30,30,50,23 ) ); myRegion.Union( new RectangleF( 0.01f,120.2f,300,12 ) ); myRegion.Union( new Rectangle( -12,-50,40,40) ); myRegion.Xor( new RectangleF( 0,0,23,24 ) ); myRegion.Translate( 0.01f, 33.3f ); } public void TestTranslate03() { Region R = new Region( new Rectangle(-2,-2,200,200) ); R.Intersect( new RectangleF( .023f, 2.2f, 12.01f, 11.999f ) ); R.Xor( new RectangleF( 50,50,2,2 ) ); R.Xor( new RectangleF( 23,24,2,2 ) ); R.Exclude( new RectangleF( 30,30,50,23 ) ); R.Union( new RectangleF( 0.01f,120.2f,300,12 ) ); R.Union( new Rectangle( -12,-50,40,40) ); R.Xor( new RectangleF( 0,0,23,24 ) ); myRegion = new Region( R.GetRegionData() ) ; myRegion.Xor( new RectangleF( -1,-1,3,39 ) ); myRegion.Union( new Rectangle( 6,44,72,72 ) ); myRegion.Union( new Rectangle( 2,3,66,66 ) ); myRegion.Xor( new RectangleF( -12,-23,66,66 ) ); myRegion.Translate( 100.5f, -200.5f ); } public static void Main( string[] args ) { TestRegionData trd = new TestRegionData() ; Type myType = trd.GetType(); MethodInfo[] myMethods = myType.GetMethods(); // run one test case if ( args.Length >0 ) { string testCase = args[0] ; MethodInfo metInfo = null; foreach ( MethodInfo m in myMethods ) { if ( m.Name.Equals(testCase) ) { metInfo = m ; break; } } if ( metInfo != null ) { Console.WriteLine( "\nrunning {0}:", metInfo.Name ); metInfo.Invoke( trd, null ); trd.Inspect() ; } else { Console.WriteLine( " Test method {0} does not exist. ", testCase ); Console.WriteLine( " Call this program either without arguments ( to run all test cases)," ); Console.WriteLine( " or with one of the following arguments:" ); Regex r = new Regex("^Test"); foreach ( MethodInfo m in myMethods ) if ( r.IsMatch( m.Name ) ) Console.WriteLine( "\t{0}", m.Name ); } return; } // run all test cases Regex r = new Regex("^Test"); foreach ( MethodInfo m in myMethods ) if ( r.IsMatch( m.Name ) ) { Console.WriteLine( "\nrunning {0}:", m.Name ); m.Invoke( trd, null ); trd.Inspect() ; } } private RegionData myRegionData ; private Region myRegion ; public void Inspect() { myRegionData = myRegion.GetRegionData(); int myRegionDataLength = myRegionData.Data.Length; Console.WriteLine("RegionData length is {0}", myRegionDataLength); Console.WriteLine("Regiondata bytes are:"); for ( int i =0; i