Why does Region.IsEmpty () need a graphics context?

I use Region.IsEmpty() to see if two areas intersect, but I really don't understand why I need to provide a Graphics context.

The official description informs

The current transform of the graphics context g is used to calculate the inner region of the region on the drawing surface.

What transformation in two dimensions can separate two overlapping regions or make an empty region empty?

Is this a matter of detail? From anti-aliasing to anti-aliasing?

+6
source share
3 answers

Regions are a function of GDI and strongly correlate with GDI device contexts. You can specify an area with floating point numbers, such as a constructor that accepts GraphicsPath or RectangleF. But the final calculations are performed with integer precision. Just enough for pixel accuracy, no longer needed.

Mapping from logical coordinates to device coordinates (i.e. pixels) is done by adjusting the device context. Which may have a display mode other than 1: 1. Thus, the area in which the rectangle, say, 2.0 x 2.0, may appear empty when it is displayed in pixels. For example, SetMapMode () .

So watch out when you intend to use the Regions as a common tool, especially the lack of accuracy of the result (no better than the whole accuracy) may come as a surprise.

+4
source

The Region.IsEmpty(Graphics g) method checks whether the current graphics context specified as g has any elements that occupy a specific area.

It is not necessary to check whether two areas intersect, but rather whether any other elements on the surface of the drawing intersect the area. The instance of Graphics allows Region to perform validation on the surface of the drawing, as it is defined as Graphics . In a way, this method really looks like [inoperative code] g.ContainsElementsWhichIntersect(theRegion) .

+4
source

From your link:

Checks if this region has empty space on the specified surface of the drawing.

The operative term in this expression draws a surface . To have a drawing surface, you need a graphics context, and therefore an instance of the Graphics object.

The fact that the documentation mentions the conversion is probably just a little confusing jargon. This is just a fancy way of saying that the return value will be true in the current state of the graph context. If something changes, for example, ScaleTransform or even a vanilla call to DrawLine, then a "transformation" has occurred, and then the result of IsEmpty may be invalid.

Also <I would not be surprised if, in fact, some kind of matrix transformation was applied with the coordinates of the region provided for detecting the "void".

+2
source

Source: https://habr.com/ru/post/948019/


All Articles