I have a bezier path that comes into my program having been created from an SVG and the problem is it is just an outline. I need to perform hit detection on it, anywhere on the interior of the shape. Is there an equivalent of CGPathCreateCopyByStrokingPath for filling it?
CGContextFillPath will fill a path within a context when it is drawn.
CGPathCreateCopyByStrokingPath takes a path and returns a new path describing the outline of the shape that would be formed when stroking that path. It returns a CGPathRef. So if you can perform hit detection on the results of that, then you can perform them directly on your original path. You don't need a conversion.
Supposing I've misunderstood the question, you can use CGPathContainsPoint to test whether a point is inside a path. Use that directly on what you get from your SVG.
Related
I have a problem. I created sinusoide using code: sinusoide and increased the thickness with path.lineWidth. I also added a dot to the screen (CAShapeLayer). I need to check if my dot is in the sinusoidal. I checked the available function UIBezierPath.contain. Unfortunately, it does not considering the lineWidth. I also checked by color if the pixel on the screen contains color but unfortunately it is very slow and takes 100% CPU. Whether there is any other quick way to find out if the dot is in the UIBezierPath?
Use copy(strokingWithWidth:lineCap:lineJoin:miterLimit:transform:) to create a stroked copy of the path. Then use contains on the copy to test the center of the dot.
I'm currently drawing an angular gradient using a method similar to the one shown by Rob's answer here. I have added an extension to CGContext to draw an angular gradient and would like it to handle the clipping path, so that callers can treat it similar to a method like fillPath(using:).
I have tried using func pathContains(CGPoint, mode: CGPathDrawingMode) on CGContext and func contains(CGPoint, using: CGPathFillRule, transform: CGAffineTransform) on the CGPath returned from the context.
Both of these appear to not use the clipping path, so my drawing goes outside the clipping area.
Is there a way to get either the path clipped already or a copy of the current clipping path so I can also check whether the pixel is contained inside that path also?
You should be able to check if the point is inside your unclipped path and check if the point is inside the clipping path. The clipped path is the intersection fo the clipping path and your path, so a point is inside the clipped path only it its inside both your unclipped path and inside the clipping path.
I'm trying to create a sort of progress bar class that fills along a UIBezierPath as it progresses. I need to stroke a UIBezierPath with a controlled animation.
I think I could implement this if I could truncate the path to a precise portion of its original length. Is this possible? Is there another method I can use to precisely control the animated stroking of a path?
I've seen this question, but the answer seems to address finding the points at the beginning and end of each element. I'd need to get a list of points at a pixel-by-pixel level for a list of points to be a viable solution.
I believe I'm looking for the strokeEnd property.
I want to draw a path and then change it's shape by touching the control points of the path, would it be better to use uibezierpath or core graphics for this purpose and why? I want to get access to the path after im done with modifying it's shape. Thank you.
You're going to want to keep the control points in your own data structure, because neither UIBezierPath nor CGPath provides a convenient way to get at or modify the existing control points of the path.
That said, it's generally easier to use the UIKit drawing API if it covers your needs, so you'll want to convert your data structure to a UIBezierPath to draw it each time the user makes a change.
I implement a free hand drawing module using UIBezierPath, but i want to get the all frame of the curve after i finish drawing, how can i do it.
And if there a way to get the path point for a connected path, it will be great.
Your question is not entirely clear, but if you want the bounding rectangle of a UIBezierPath, there is a bounds property.
If you want to know the position of the last point to connect another path, there is the currentPoint property.
If you want to examine the different parts of the path, you'll have to go down to the underlying CGPath, and the CGPathApply function.
If you want to test if a point is inside the path (would be filled), you can use the containsPoint: method, and if you want to test if a point is part of the path, you will have to do the math yourself using the Bézier formulas...