Hi,
I have been working with regions recently. I have set up a small example. Interset and Subtract medhods work as I have expected. But not the Xor and Union methods.
the example shows all four methods. we have two rectangles. the xor and union take up all the space of both rectangles, which is wrong. What am I doing incorrectly?
thanks,
jan bodnar
#!/usr/bin/python
# regions.py
import wx
class Regions(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(300, 280))
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Centre()
self.Show(True)
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.SetPen(wx.Pen('#D4D4D4'))
dc.DrawRectangle(20, 20, 50, 50)
dc.DrawRectangle(30, 40, 50, 50)
region1 = wx.Region(20, 20, 50, 50)
region2 = wx.Region(30, 40, 50, 50)
region1.SubtractRegion(region2)
rect = region1.GetBox()
dc.SetBrush(wx.Brush('BLUE'))
dc.DrawRectangleRect(rect)
dc.SetBrush(wx.Brush('WHITE'))
dc.DrawRectangle(100, 20, 50, 50)
dc.DrawRectangle(110, 40, 50, 50)
region1 = wx.Region(100, 20, 50, 50)
region2 = wx.Region(110, 40, 50, 50)
region1.IntersectRegion(region2)
rect = region1.GetBox()
dc.SetBrush(wx.Brush('RED'))
dc.DrawRectangleRect(rect)
dc.SetBrush(wx.Brush('WHITE'))
dc.DrawRectangle(180, 20, 50, 50)
dc.DrawRectangle(190, 40, 50, 50)
region1 = wx.Region(180, 20, 50, 50)
region2 = wx.Region(190, 40, 50, 50)
region1.UnionRegion(region2)
rect = region1.GetBox()
dc.SetBrush(wx.Brush('#fa8e00'))
dc.DrawRectangleRect(rect)
dc.SetBrush(wx.Brush('WHITE'))
dc.DrawRectangle(20, 120, 50, 50)
dc.DrawRectangle(30, 140, 50, 50)
region1 = wx.Region(20, 120, 50, 50)
region2 = wx.Region(30, 140, 50, 50)
region1.XorRegion(region2)
rect = region1.GetBox()
dc.SetBrush(wx.Brush('#619e1b'))
dc.DrawRectangleRect(rect)
app = wx.App()
Regions(None, -1, 'regions')
app.MainLoop()