Resolved Check inside polygon

Discussion in 'iOS Programming' started by xArtx, Apr 1, 2013.

  1. xArtx, Apr 1, 2013
    Last edited: Apr 2, 2013

    xArtx macrumors 6502a

    Mar 30, 2012
    I can look elsewhere for C code,
    but I'm wondering if iOS has a way to check inside a path used to
    draw polygons with Quartz2d.

    I have saved all of the screen coordinates in the path,
    so I can do something with them after the polygon is drawn to screen.
    Cheers, Art.
  2. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    Assuming you have a Path, see the documentation for CGPathContainsPoint.
  3. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    Awesome! 5 minutes to get it working. Don't even have to save coordinates
    that make up the polygon, just check it before you fill the path:
        CGContextAddLineToPoint(context, sscreenx, sscreeny);
        if (isnp == 1) {
        bool shapeContainsPoint = CGContextPathContainsPoint(context, cPoint, kCGPathFillStroke );
        if (shapeContainsPoint == TRUE) {inboundsnp = 1;}
        } // isnp
    Sure beats virtually drawing the polygon again just to hit test it, Thanks :)

Share This Page