I'm using a CombinedGeometry
in C# to join several polygons together.
The RenderedGeometry
of each shape is taken, and joined to the final shape with GeometryCombineMode.Union
.
开发者_运维技巧However, I'm having a problem where two shapes are adjacent, but not overlapping (a 0px gap between the two). As they do not overlap, they will not be joined by the CombinedGeometry
.
I've considered enlarging each input shape by 1 pixel, then contracting the output by the same, but this can't be done accurately using a ScaleTransform
.
How can I join these two shapes together?
Try the following - I've not tested it, but logically I think it will work:
Create a rectangle that encloses your shapes - calculate the combined bounding box and extend it a bit to cope with rounding error.
Then perform a "Exclude" between the rectangle and each shape in turn.
Once you've done that you'll have a rectangle with a hole cut out that's the effective union of all your shapes.
Then do an "Xor" of the this with another rectangle the same size as the first.
I think this should produce your "union".
精彩评论