Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:00:47+00:00 2026-05-28T14:00:47+00:00

I am making a CGPoint and a CGPathRef then trying to find if the

  • 0

I am making a CGPoint and a CGPathRef then trying to find if the CGPoint is inside the CGPathRef. Here is the code:

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathMoveToPoint(path, NULL, 200, 0);
CGPathMoveToPoint(path, NULL, 200, 200);
CGPathMoveToPoint(path, NULL, 0, 200);
CGPathCloseSubpath(path);

CGPoint hitPoint = CGPointMake(77, 77);

if ( CGPathIsEmpty(path) )
    NSLog(@"Path Is Empty!");
else
{
    if ( CGPathIsRect(path, NULL) ) 
        NSLog(@"Path is a Rectangle!");
    else
    {
        NSLog(@"Path is NOT a Rectangle!");
        if (CGPathContainsPoint(path, NULL, hitPoint, FALSE)) // FALSE or TRUE - same result
            NSLog(@"Hit Point Inside: x=%f, y=%f", hitPoint.x, hitPoint.y);
        else
            NSLog(@"Hit Point Outside: x=%f, y=%f", hitPoint.x, hitPoint.y);
    }
}    

The output reads:

Path is NOT a Rectangle!
Hit Point Outside: x=77.000000, y=77.000000

The path obviously is a rectangle and the point is inside the closed path. Please clue me in on what I am doing wrong here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:00:48+00:00Added an answer on May 28, 2026 at 2:00 pm

    CGRectIsPath only returns true if the path was created by CGPathCreateWithRect (with a transform parameter that doesn’t rotate or skew the rectangle), or if the path was created by CGPathCreateMutable and had a single rectangle added to it with CGPathAddRect.

    It would be much more work for it to figure out whether any arbitrary path is exactly a rectangle. The path might contain bezier curve segments that are actually straight lines, or sides that are built from consecutive straight line segments.

    If you need to detect whether any arbitrary path is actually just a rectangle, you will have to do it yourself using CGPathApply. It will be complicated.

    As for why your point-inside test isn’t working: you need to use CGPathAddLineToPoint to create the sides of your rectangle:

    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, 200, 0);
    CGPathAddLineToPoint(path, NULL, 200, 200);
    CGPathAddLineToPoint(path, NULL, 0, 200);
    CGPathCloseSubpath(path);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making my first steps with NHibernate, I'm trying to have it creating my Tables
I'm making a partial overlay modal in my app with the code from Semi-Modal
Making a new shooter game here in the vein of Galaga (my fav shooter
Making a piano/keyboard application and trying to figure out the best way to set
making an infinite loop in javascript, and jQuery... this is my current code: $(#bg2).css({opacity:
Making my way through the GAE documents. I have a question I can't find
I'm trying to find connected components present (if any) within a small region of
I use this code to draw a line in quartz2d CGPoint currentPoint = CGPointMake(rascalImage.center.x,
Making a new question, as was suggested to me. I'm trying to send data
Making a simple Java code for Blackjack and need some advice. OK I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.