Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, as i needed a Polygon/Interpolation from a Curved Path myself, i might have a solution for your problem as well: </p> <p>The two 'Public' Functions:</p> <p><code>CGPathRef CGPathCreatePolygonPath(CGPathRef path, int quality);</code></p> <p>Creates an Path with only Line-Elements, quality is the number of segments a curve is split into</p> <p><code>BOOL CGPathContainsPointInterpolated(CGPathRef path, const CGAffineTransform *m, CGPoint point, bool eoFill, int quality);</code></p> <p>Does CGPathContainsPoint and Interpolation in one step, quality is again the number of segments a curve is split into.</p> <p>Here is the implementation.</p> <pre><code>typedef struct { CGMutablePathRef path; int quality; } InterpolationInfo; static inline float cubeInterp(float t, float p0, float p1, float p2, float p3) { return powf(1-t, 3)*p0 + 3*powf(1-t, 2)*t*p1 + 3*(1-t)*powf(t, 2)*p2 + powf(t, 3)*p3; } static void pointsForCubeCurve(CGPoint cp0, CGPoint cp1, CGPoint cp2, CGPoint ep, CGPoint *buffer, int numberPoints) { for (int i = 0; i&lt;numberPoints; i++) { float t = (i+1)/(float)numberPoints; buffer[i] = CGPointMake(cubeInterp(t, cp0.x, cp1.x, cp2.x, ep.x), cubeInterp(t, cp0.y, cp1.y, cp2.y, ep.y)); } } static inline float quadInterp(float t, float p0, float p1, float p2) { return powf(1-t, 2)*p0 + 2*(1-t)*t*p1 + powf(t, 2)*p2; } static void pointsForQuadCurve(CGPoint cp0, CGPoint cp, CGPoint ep, CGPoint *buffer, int numberPoints) { for (int i = 0; i&lt;numberPoints; i++) { float t = (i+1)/(float)numberPoints; buffer[i] = CGPointMake(quadInterp(t, cp0.x, cp.x, ep.x), quadInterp(t, cp0.x, cp.x, ep.x)); } } static void CGPathElementConvertToPolygon(void *info, const CGPathElement *element) { InterpolationInfo *interpInfo = info; switch (element-&gt;type) { case kCGPathElementMoveToPoint: CGPathMoveToPoint(interpInfo-&gt;path, NULL, element-&gt;points[0].x, element-&gt;points[0].y); break; case kCGPathElementAddLineToPoint: CGPathAddLineToPoint(interpInfo-&gt;path, NULL, element-&gt;points[0].x, element-&gt;points[0].y); break; case kCGPathElementAddQuadCurveToPoint: { int nr = interpInfo-&gt;quality; CGPoint buffer[nr]; pointsForQuadCurve(CGPathGetCurrentPoint(interpInfo-&gt;path), element-&gt;points[0], element-&gt;points[1], buffer, nr); for (int i = 0; i&lt;nr; i++) { CGPathAddLineToPoint(interpInfo-&gt;path, NULL, buffer[i].x, buffer[i].y); } break; } case kCGPathElementAddCurveToPoint: { int nr = interpInfo-&gt;quality; CGPoint buffer[nr]; pointsForCubeCurve(CGPathGetCurrentPoint(interpInfo-&gt;path), element-&gt;points[0], element-&gt;points[1], element-&gt;points[2], buffer, nr); for (int i = 0; i&lt;nr; i++) { CGPathAddLineToPoint(interpInfo-&gt;path, NULL, buffer[i].x, buffer[i].y); } break; } case kCGPathElementCloseSubpath: CGPathCloseSubpath(interpInfo-&gt;path); break; default: break; } } static CGPathRef CGPathCreatePolygonPath(CGPathRef path, int quality) { CGMutablePathRef newPath = CGPathCreateMutable(); InterpolationInfo info; info.path = newPath; info.quality = quality; CGPathApply(path, &amp;info, CGPathElementConvertToPolygon); return newPath; } static BOOL CGPathContainsPointInterpolated(CGPathRef path, const CGAffineTransform *m, CGPoint point, bool eoFill, int quality) { CGPathRef polygon = CGPathCreatePolygonPath(path, quality); BOOL returnValue = CGPathContainsPoint(polygon, m, point, eoFill); CGPathRelease(polygon); return returnValue; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload