Rectangle/Path Intersection

G-Man

Member
Joined
Nov 30, 2006
Messages
6
Programming Experience
10+
Is there a quick way if supplied with a System.Drawing.Rectangle or RectangleF and a closed System.Drawing.Drawing2d.GraphicsPath (comprised only of lines), to derive the path (or paths) that an intersection of the two would create?

If you look at the attached file, Path.Jpg you see a closed path. Looking at the file Clipping.jpg shows that path being intersected by a rectangle and Result.Jpg shows the resulting paths created by the intersection.

So, if the function declaration looked like:

Private Function CropPath(ByVal SrcPath As GraphicsPath, ByVal Rect As RectangleF) As PathIntersection

...and the returned structure looked like:

Public Structure PathIntersection
Public PathCount As Integer
Public Paths() As System.Drawing.Drawing2D.GraphicsPath
End Structure

Is there a quick way to impliment this?
 

Attachments

  • Path.JPG
    Path.JPG
    5.7 KB · Views: 30
  • Clipping.JPG
    Clipping.JPG
    6.7 KB · Views: 31
  • Result.JPG
    Result.JPG
    2.7 KB · Views: 27
Yea, you need to create a region from the path and use the Region.Complement method (mmm I think, thing is there's a couple of different methods in the region class and one of them does what you want. I'm sure it's the Complement method.
 
Don't those region methods return regions and not paths? ...Or is there some way to convert regions back to paths?
 
The Region methods don't return anything, they are sub methods that modifies the existing region (self) with the used method and input data. I don't think there is a way back from Region to GraphicsPath, but you can set the Graphics.Clip to the Region.
 
There may be a way back with the GetRegionData Function. Cheers JohnH i was a bit unsure about the exact usage but i knew i was heading the the right direction. It's been a while since i played around with the region class.;)
 
Back
Top