Left image is my starting situation: red is a region, and black is a XLD rectangle.
The right is what I would like to achive. I would need that wherever the Region touches the Rectangle, the region is stretched out by X pixel.. my approach would be to draw a rectangular region with Width "X" and then unite it "union2()" but I have a difficult time to figure out the Y coordinates of the rectangles. Better yet, I can find the intersections, but I do not know how to find out if it is the "beginning" or the "end" of the intersection, so if it is the top or the bottom of the rectangle.. I was thinking that the first is alway the beginning and then they alternate, but in reality it happens that the intersection returns two values at the same pixel..
Here a demo code
The input
The output