Authored by Justin R. Miller

fix shape/circle hit detection passed on presence of fill color

@@ -135,7 +135,25 @@ @@ -135,7 +135,25 @@
135 135
136 - (BOOL)containsPoint:(CGPoint)thePoint 136 - (BOOL)containsPoint:(CGPoint)thePoint
137 { 137 {
138 - return CGPathContainsPoint(shapeLayer.path, nil, thePoint, [shapeLayer.fillRule isEqualToString:kCAFillRuleEvenOdd]); 138 + BOOL containsPoint = NO;
  139 +
  140 + if ([self.fillColor isEqual:[UIColor clearColor]])
  141 + {
  142 + // if shape is not filled with a color, do a simple "point on path" test
  143 + //
  144 + UIGraphicsBeginImageContext(self.bounds.size);
  145 + CGContextAddPath(UIGraphicsGetCurrentContext(), shapeLayer.path);
  146 + containsPoint = CGContextPathContainsPoint(UIGraphicsGetCurrentContext(), thePoint, kCGPathStroke);
  147 + UIGraphicsEndImageContext();
  148 + }
  149 + else
  150 + {
  151 + // else do a "path contains point" test
  152 + //
  153 + containsPoint = CGPathContainsPoint(shapeLayer.path, nil, thePoint, [shapeLayer.fillRule isEqualToString:kCAFillRuleEvenOdd]);
  154 + }
  155 +
  156 + return containsPoint;
139 } 157 }
140 158
141 - (void)setLineColor:(UIColor *)newLineColor 159 - (void)setLineColor:(UIColor *)newLineColor
@@ -437,7 +437,25 @@ @@ -437,7 +437,25 @@
437 437
438 - (BOOL)containsPoint:(CGPoint)thePoint 438 - (BOOL)containsPoint:(CGPoint)thePoint
439 { 439 {
440 - return CGPathContainsPoint(shapeLayer.path, nil, thePoint, [shapeLayer.fillRule isEqualToString:kCAFillRuleEvenOdd]); 440 + BOOL containsPoint = NO;
  441 +
  442 + if ([self.fillColor isEqual:[UIColor clearColor]])
  443 + {
  444 + // if shape is not filled with a color, do a simple "point on path" test
  445 + //
  446 + UIGraphicsBeginImageContext(self.bounds.size);
  447 + CGContextAddPath(UIGraphicsGetCurrentContext(), shapeLayer.path);
  448 + containsPoint = CGContextPathContainsPoint(UIGraphicsGetCurrentContext(), thePoint, kCGPathStroke);
  449 + UIGraphicsEndImageContext();
  450 + }
  451 + else
  452 + {
  453 + // else do a "path contains point" test
  454 + //
  455 + containsPoint = CGPathContainsPoint(shapeLayer.path, nil, thePoint, [shapeLayer.fillRule isEqualToString:kCAFillRuleEvenOdd]);
  456 + }
  457 +
  458 + return containsPoint;
441 } 459 }
442 460
443 - (void)closePath 461 - (void)closePath