Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about intersection of two path #25

Open
bluepixeltech opened this issue Apr 21, 2022 · 2 comments
Open

Question about intersection of two path #25

bluepixeltech opened this issue Apr 21, 2022 · 2 comments

Comments

@bluepixeltech
Copy link

First of all thank you for the very useful library you created! I have a question regarding the intersection of two paths and I hope you will have a chance to help me. Suppose that we have two paths like the following image, one rectangle and a circle. We I get the intersection of the two as an array and then append them the result is a path depicted in red in the image which is correct. However, for my application I need to exclude the line in the red path and only keep the arc. How can I do that? Thank you in advance.

IMG_863FED981F98-1
n

@adamwulf
Copy link
Owner

Hi! I'm glad to hear you're finding the library useful :)

I believe you'll be able to get what you want if you use an unclosed circle path. UIBezierPath(ovalIn: frame) will create a path that has a .closePath element as its last element. If you instead trim off that closePath element:

// a circle is closed and has 2 or more elements
var circlePath = UIBezierPath(ovalIn: frame)
assert(circlePath.isClosed && circlePath.elementCount >= 2)
// trim off the last closePath element
circlePath = circlePath.trimming(toElement: circlePath.elementCount - 2, andTValue: 1.0)
assert(!circlePath.isClosed)
// now using circlePath for the intersection won't return a closed shape

I think that'll do what you need. there's a chance that the closePath element is inside the box, which means the intersection will return up to two pieces of the circle. the order you append them may make a difference as well, so keep that in mind.

@bluepixeltech
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants