On 5 April 2016 at 02:37, Aliaksei Syrel <alex.syrel@gmail.com> wrote:
About hit detection. Idea was to be completely general. And this is the only approach I found (still bad because uses native calls instead of athens-like solution) that works with text. Text is also a shape and it's very cool to be able to detect events inside characters. Imagine morph in form of huge arbitrary string.
Yes, that would be cool to have.
Current solution does not render, it only sets fill paint and path, then uses cairo, no need to invent wheel. Imagine that paint is something fancy, Cairo takes Cairo about special cases.
This code was born before Cairo came to play. Mind you that Cairo is only one of the potential backends of Athens. It doesn't means that you cannot use feature and invent own wheel. Don't you think i am not hating to reproduce numerical algorithms by myself, if i would be able to use one that already available for use. But that was not the case. So, exposing feature via correct protocol is the way to go. Then when backend provides such feature, one can simply use backed.. and if not - then it will fallback to homemade numerical crunching. And especially that code smells and need a cleanup (not your code, but code in Athens). All i wanna see is exposing feature in nice and consisting way. We all want it to be there. Not just you and me, but whole community does. The rest is a poetry.
Cheers Alex On Apr 5, 2016 12:17 AM, "Igor Stasenko" <siguctua@gmail.com> wrote:
On 5 April 2016 at 01:12, Igor Stasenko <siguctua@gmail.com> wrote:
On 5 April 2016 at 00:51, Andrei Chis <chisvasileandrei@gmail.com> 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.
-- Best regards, Igor Stasenko.