0

I use the algorithm of checking if a point is inside a region:

  • draw a point with color1

  • draw a region with color2

  • check if point still has color1

So the main problem for me is the last step.

I know it is possible to do this with core graphics but it is probably slow. In OpenVG and OpenGL it could be faster but:

  • I can't find any examples

  • it requires 2 cycles of built-in draw function - draw a point and a region on the first call and check color on the second. And the same operation for each region separately.

genpfault
  • 51,148
  • 11
  • 85
  • 139
user2083364
  • 744
  • 1
  • 7
  • 20
  • Report you. In what place it is a duplicate of that question?! I described an algorithm that uses color comparison but on your page they describe methods which perform complex calculations and compare coordinates. – user2083364 Dec 20 '13 at 11:46
  • Sorry I was on my iPad and short-lipped. Long answer: you're essentially asking for a "point in polygon" algorithm as described here: http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test. At least that's the reasonable thing to do. Testing for a specific pixel is possible but always a lot slower than a polygon intersection test because reading from the framebuffer is slow in basically any renderer. The clever alternative is to essentially remember what you're drawing as, say, CGPoint and CGPath and then perform the intersection test. – CodeSmile Dec 20 '13 at 13:27
  • It can be slower in iOS. But I know that this algorithm is faster at least in Flash (for example, it allows to draw a huge amount of objects in scrolling shooter game and check collisions with a ship). – user2083364 Dec 20 '13 at 14:35
  • Honestly not sure if it is the least intensive way of doing it, but I've always used the simple call of CGRectContainsPoint(CGRect rect, CGPoint point) which returns a boolean. – Corbin87 Dec 29 '13 at 19:06
  • and? "area" doesn't rectangle area. What will you do if you have some circles which are too close to each other? – user2083364 Dec 30 '13 at 06:18

0 Answers0