Some remarks on wx.Rect class Where is additional constructor-like global functions which can be used for creating wx.Rect: wx.RectPS - create rectangle from (point,size)pair. wx.RectPP - create rectangle from (point,point) pair. Actually wx.RectPP accepts points in _any_ order, not only (left_top,right-down) as you can imagine from it's documentation. wxRectPP returns rectangle which lays _around_ both points, say: wx.RectPP( (0,0),(1,1) ) == wx.Rect( 0,0,2,2 ) Where is also a function wx.IntersectRect( r1,r2 ) which returns intersection of two rectangles or None if they don't intersects. Here is small unittest example: {{{ #!python import unittest import wx class TestRectPP( unittest.TestCase ): def test_rect_surrounds_both_points( self ): self.assertEqual( wx.RectPP((0,0),(7,5)), wx.Rect(0,0,8,6) ) def test_points_order_is_irrelevant( self ): p1 = wx.Point( 1,2 ) p2 = wx.Point( 5,6 ) r1 = wx.RectPP( p1, p2 ) r2 = wx.RectPP( p2, p1 ) self.assertEqual( r1, r2 ) class TestIntersection( unittest.TestCase ): def test_equals( self ): r1 = wx.RectPS( (0,0),(4,4) ) r2 = wx.RectPS( (0,0),(4,4) ) r3 = wx.IntersectRect( r1,r2 ) self.assertEqual( r3, wx.RectPS((0,0),(4,4)) ) def test_some_intersection( self ): r1 = wx.RectPS( (0,0),(4,4) ) r2 = wx.RectPS( (1,2),(4,4) ) r3 = wx.IntersectRect( r1,r2 ) self.assertEqual( r3, wx.Rect(1,2,3,2) ) def test_no_intersection_returns_None( self ): r1 = wx.RectPP( (0,0),(10,10) ) r2 = wx.RectPP( (12,12),(20,20) ) r3 = wx.IntersectRect( r1,r2 ) self.assertEqual( r3, None ) def suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite( TestRectPP ) ) suite.addTest( unittest.makeSuite( TestIntersection ) ) return suite if __name__ == '__main__': runner = unittest.TextTestRunner() runner.run( suite() ) }}} (feel free to edit my "english") Vladimir Ignatov ---- See also: [[http://www.python.org/moin/PointsAndRectangles|PythonInfo:PointsAndRectangles]]