Here is a pretty quick and clean solution. It also works to test several paths against one, which is good, right?
It works with CGBezier (iOS and MacOS compatible)
• 1 - Create contexts of necessary items
Create a 16-bit, single component (non-alpha) graphics port with the same size as the view .
16-, ( -) 1 .
• 2 - :
computeContext :
- ( )
- , .
- ,
- ( computeContext.) testContext - :
CGImageRef clippedPathsImage = CGBitmapContextCreateImage(computeContext);
CGRect onePixSquare = CGRectMake(0,0,1,1);
CGContextDrawImage(testContext, onePixSquare, clippedPathsImage);
( , . malloc , bitmapContext)
!
long* data = CGBitmapContextGetData(testContext);
BOOL intersects = (*data!=0);
,
computeContext, , 25% .
1 , 4 ( 25- , ).
8 . , , 1 . , .
, , , - !
GitHub ;)
https://github.com/moosefactory
, , !;)
16 .
, , . - bitmapInfo ( ), , float.
-(CGContextRef)createComputeContext
{
size_t w = (size_t)self.bounds.size.width;
size_t h = (size_t)self.bounds.size.height;
size_t nComps = 1;
size_t bits = 16;
size_t bitsPerPix = bits*nComps;
size_t bytesPerRow = bitsPerPix*w;
CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
CGContextRef bmContext = CGBitmapContextCreate(NULL, w, h, bits, bytesPerRow, cs, 0);
return bmContext;
}