S.J. Lim
S.J. Lim

Reputation: 3165

How to recognize if CGPoint is included in shape?

I'm a beginner in quartz.

I'm wonderring a way that recognize if CGPoint is included in shape.

Please give me a help of Expert.

Follow is concept diagram.

enter image description here

In above three case, Result I want is YES, Because three RED CGPoint is included in shape.

It is possible like follow way?

CGPoint RedPoint1 = {200,100};
CGPoint RedPoint2 = {200,200};
CGPoint RedPoint3 = {350,300};

BOOL includeRect;
includeRect = CGRectContainsPoint(RectCase, RedPoint1);

BOOL includeCircle;
includeCircle = CG ? ContainsPoint(CircleCase, RedPoint2)

BOOL includeBoldLine;
includeBoldLine = CG ? ContainsPoint(BoldLineCase, RedPoint3);

Upvotes: 0

Views: 149

Answers (1)

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

The ease of this all depends on how your shapes are defined.

If you have these as CGPathRefs or NSBezierPaths there is a containsPoint: method you could use.

If these are CGRects that have a transform applied to them, you can use the CGAffineTransformPoint methods to move the point into the same coordinate space and then use CGRectContainsPoint

Upvotes: 2

Related Questions