Hammy
Hammy

Reputation: 35

Determine Boundaries of CGMutablePathRef?

I have path being made by CGMutablePathRef

  CGMutablePathRef pointsPathpath = CGPathCreateMutable();
  CGPathMoveToPoint(pointsPathpath, NULL, firstPoint.x, firstPoint.y);
  CGPathAddLineToPoint(pointsPathpath, NULL, secondPoint.x, secondPoint.y);
  CGPathAddLineToPoint(pointsPathpath, NULL, thirdPoint.x, thirdPoint.y);
  CGPathAddLineToPoint(pointsPathpath, NULL, fourthPoint.x, fourthPoint.y);
  CGPathCloseSubpath(pointsPathpath);

Is there any way to get its boundary points?

Thanks in Advance.

Upvotes: 0

Views: 179

Answers (2)

David Rönnqvist
David Rönnqvist

Reputation: 56645

Core Graphics has two method to calculate the "bounding box" of a CGPath.

  1. CGPathGetPathBoundingBox()
  2. CGPathGetBoundingBox()

The first one returns the smallest bounding box that encloses all the points in the path but not including control points for curves.

The second one does include control points for curves.

Your path doesn't have any curves so they will both return the same rectangle but for more advanced paths they generally return different areas.

The below image illustrates their difference. The black lines with circles in the end are the control points for the curves in the path.

enter image description here

Upvotes: 3

Tom Irving
Tom Irving

Reputation: 10069

You can use either CGPathGetBoundingBox() or CGPathGetPathBoundingBox().

Both of these are listed in the CGPath documentation: http://developer.apple.com/library/ios/#documentation/graphicsimaging/Reference/CGPath/Reference/reference.html

Upvotes: 1

Related Questions