Razack
Razack

Reputation: 1896

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

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

Upvotes: 2

Views: 1185

Answers (2)

Agnel Kurian
Agnel Kurian

Reputation: 59466

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

Upvotes: 2

Prasoon KT
Prasoon KT

Reputation: 11

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

Upvotes: 1

Related Questions