How to verify if a Rectangle is completely contained in a region or graphicspath

StackOverflow https://stackoverflow.com/questions/20993621

  •  25-09-2022
  •  | 
  •  

Question

We are using GDI+ and we have different regions or graphicspath. How to determine if a rectangle is completely inside this region.

Was it helpful?

Solution

The following function returns whether or not the union of region r and rectangle r1 is equal to r. Theoretically it is the same as determining whether r completely contains r1. Also, it requires a Graphics object to perform the comparison.

bool Contains(Region r, RectangleF r1, Graphics g) {
  Region u = r.Clone();
  u.Union(r1);
  return r.Equals(u, g);
}

Update: Corrected region comparison as discussed in another post

OTHER TIPS

I Guess,

  1. Take regions or graphics path pixels to array
  2. Take Rectangle pixels to another array
  3. check each rectangle pixels from array with region pixel array
  4. if all rectangle pixels exists in region pixel array, it means rectangle contained in region
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top