Reputation: 175
i have a CGMutablePathRef object called path, i want to know, how can i know path is null, it means i didn't use
CGPathAddLineToPoint(path, NULL, point.x, point.y);
or
CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
to push points into path.
Upvotes: 2
Views: 429
Reputation: 523284
To check whether a path is NULL, use the ==
/!=
operator.
if (path != NULL)
CGPathAddLineToPoint(path, NULL, point.x, point.y);
To check whether a path contains no nothing, use CGPathIsEmpty.
if (!CGPathIsEmpty(path))
CGPathAddLineToPoint(path, NULL, point.x, point.y);
To check whether a path's point has been moved, use CGPathGetCurrentPoint and compare with (0, 0).
if (!CGPointEqualToPoint(CGPathGetCurrentPoint(path), CGPointZero))
CGPathAddLineToPoint(path, NULL, point.x, point.y);
Of course this cannot distinguish between a truly empty path and a path that someone called CGPathMoveToPoint(path, NULL, 0, 0)
on it.
(Actually, why you need to care? Just create a new path if you want an empty one.)
Upvotes: 2
Reputation: 104698
a CGMutablePathRef is a pointer, so all you have to do to test this is:
if (NULL != path) {
CGPathAddLineToPoint(path, NULL, point.x, point.y);
}
Upvotes: 0