tags:

views:

53

answers:

2

I discovered that even numbers of overlapping shapes added to canvas like that:

GeometryGroup gg = new GeometryGroup();
EllipseGeometry e1 = new EllipseGeometry(new Point(10, 10),  20, 20);
EllipseGeometry e2 = new EllipseGeometry(new Point(10, 10),  20, 20);
//EllipseGeometry e3 = new EllipseGeometry(new Point(10, 10),  20, 20);
gg.Children.Add(e1);
gg.Children.Add(e2);
//gg.Children.Add(e3);

Path p = new Path();
p.Data = gg;
p.Fill = Brushes.Red;

MyCanvas.Children.Add(p);

"clears" all previous shapes. If you run these code you will see nothing, but if you uncomment some lines, a circle will appear. Is anybody able give explaination of this strange behavior?

+1  A: 

This occurs because your ellipses are exactly overlapping. The default FillRule for a GeometryGroup is EvenOdd, meaning that a point is considered inside the shape if a line from the point to the exterior crosses an odd number of borders. This is a bit like an XOR rule for shapes. In your case, points inside your shape will always cross an even number of borders (either both e1 and e2, or nothing at all): therefore, no points are ever considered inside the geometry, and no points get filled. Informally, e2 creates a "hole" in e1 which consumes the whole of e1. See the illustration on the GeometryGroup page on MSDN.

If you change the FillRule to NonZero, you will see a more "union"-like effect which is perhaps what you're trying to achieve.

itowlson
+2  A: 
0xA3
It works. Thanks!
Overdose