On 5 April 2016 at 01:12, Igor Stasenko <[email protected]> wrote: > > > On 5 April 2016 at 00:51, Andrei Chis <[email protected]> wrote: > > btw, Andrei , if you looking how you can test if point contains shape or > not, take a look at AthensCurveFlattener. > It converts curved path, that containing Bezier curves (or not) into > simple polygonal shape that consists only from a simple lines. > Then there AthensPolygonTester, that has the piece you missing: > - a small algorithm that can test if given point inside or outside that > polygon. > > Please note that it is simpler even-odd rule algorithm. It not works > correctly for all possible cases. > > There's another algorithm- winding number algorithm, that is much better, > but i had to switch to other stuff before were able to get my hands to it. > It is more reliable, since it can work for self-intersecting shapes. > > https://en.wikipedia.org/wiki/Point_in_polygon > > So, what you need is to wire these things down to Bloc.Then whenever you > need to test whether point within shape or not, you can convert any path > into polygon and perform the test. And of course, you can cache the results > of conversion in order to avoid expensive computations every time you need > to perform such tests. Once path is converted, the test is relatively cheap > and costs something like O(n), where n is number of line segments. > > Or maybe, to simplify things, you could extend the shape protocol and > introduce #containsPoint: > or as variant #containsPoint:ifNotAvailable: > so that if shape implements such feature - it can answer true or false, > and if not - evaluating a block. So, you don't have to implement all tests > for all kinds of shapes that invented or not yet invented in universe. > > Oh, forgot to add, you can look for example how i converting path in AthensBezier3Scene class.
> -- > Best regards, > Igor Stasenko. > -- Best regards, Igor Stasenko.
