Domanda

I know that there is exactly one specific question that talks about this but its a bit old and I wanted to get a little more technical about it if possible.

First of all take a look at this screenshot: https://www.dropbox.com/s/f94q3qaxrog0ec9/intersections.png

Want I want to have happen is say "I see where they both intersect and where that happens I do not want to draw those 'parts' of the polygon". In this case i would like to draw both polygons but not draw the 'path' of the yellow polygon that is inside the orange polygon. This include not only the line but the fill color as well.

Obviously this gets tricky because you aren't always going to have exact points along the path of each polygon that intersect exactly with other points along another polygon path. As you can see from this screenshot, in order to make this possible, I think, I need to get the points back where they do intersect.

After that and assuming that I can do this, I do not know if there is a way to use the CGPathRef class to do what i need to do. Obviously I am going to have re-create a polygon but according to the docs you cant fill it in unless it is a closed path. So how do you fill in the polygon that is not interesecting without closing the path??

The only thing that i can think of would be to "hide" the parts of the polygon that intersect but unsure how to do this. Can anyone offer any help/insight to this problem??

È stato utile?

Soluzione 2

Ok guys! well i went off and created my own MKPolygon category to solve what i needed to solve. I hope it is also useful to others!

the github link is: https://github.com/geeksweep/MKPolygon-GSPolygonIntersections

Altri suggerimenti

Here you go. I wrote an Objective-C wrapper around Alan's GPC library. Check out MKPolygon-GPC

After days of investigation, here is the solution I found for Swift 4:

1) Go here and clone the project

2) Drag and drop the following in your project:

- MKPolygon+GPC.m

- MKPolygon+GPC.h

- gpc232 (folder)

3) Create a bridging header (here is a tutorial)

4) Open your bridging header file and add the following :

#import "MKPolygon+GPC.h"

5) In your View Controller , use this method to union your two Polygons :

let mergedPolygon = polygon1.fromUnion(with:polygon2) 

NOTE : there is a crash in the current library, I fixed it but I am waiting my pull request to be reviewed. Thanks to SunGard-Labs for the framework !

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top