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

    Joined:
    Mar 30, 2012
    #1
    Hi,
    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

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

    Joined:
    Mar 30, 2012
    #3
    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:
    Code:
        CGContextAddLineToPoint(context, sscreenx, sscreeny);
        
        if (isnp == 1) {
        bool shapeContainsPoint = CGContextPathContainsPoint(context, cPoint, kCGPathFillStroke );
        if (shapeContainsPoint == TRUE) {inboundsnp = 1;}
        } // isnp
            
        CGContextFillPath(context); 
    
    Sure beats virtually drawing the polygon again just to hit test it, Thanks :)
     

Share This Page