[Cuis-dev] VectorGraphics and Morph
Mariano Montone
marianomontone at gmail.com
Fri Jun 19 08:42:08 PDT 2020
El 19/6/20 a las 12:30, Juan Vuletich escribió:
> On 6/19/2020 10:55 AM, Mariano Montone via Cuis-dev wrote:
>> El 19/6/20 a las 07:41, Hilaire Fernandes via Cuis-dev escribió:
>>
>>> It is the vector rendering, specific to the Morph.
>>>
>>> *isOrthoRectangularMorph* ^ false
>>>
>>> Inform it is not rectangular, Juan already prepare this.
>>>
>>> *morphContainsPoint: aLocalPoint* | polarPoint min max | (self
>>> morphLocalBounds containsPoint: aLocalPoint) ifFalse: [^ false].
>>> polarPoint _ (aLocalPoint + bounds topLeft - radius asPoint) * (1 @ -1).
>>> min _ Float halfPi - (aperture / 2) - shift. max _ Float
>>> halfPi
>>> + (aperture / 2) - shift. ^ (polarPoint r between:
>>> innerRadius and: radius) and: ["Deal when crossing
>>> zero" (polarPoint theta between: min
>>> and: max) or: [polarPoint
>>> theta between: min + Float
>>> twoPi and: max + Float
>>> twoPi ] ]
>>>
>>> Then you can have Morph detection/selecting really matching the vector
>>> shape.
>> I've been developing a Diagrams tool in Cuis using Cairo, and needed
>> this for shapes and connectors there.
>>
>> And used the hit canvas technique:
>> https://www.w3.org/wiki/Canvas_hit_testing
>>
>> The interesting thing about it is that you get precise
>> morphContainsPoint implementation, without having to do any calculations
>> at all! You just let the morph draw (both on vector canvas and hit
>> canvas, then use hit canvas for point containment detection).
>>
>> Implementation is here at the moment:
>> https://bitbucket.org/mmontone/mold/src/master/Dia.pck.st
>>
>> Cheers!
>>
>> Mariano
>
> VectorEngine already does this. It includes an extra buffer, ivar
> 'morphIds' in VectorEngine classes. Recently I also added ivar 'id' to
> Morph. For every pixel the engine draws in the context of a Morph, its
> id is stored at pixel position in morphIds. Then, it is just a matter of
> querying morphIds.
Cool stuff! :D
More information about the Cuis-dev
mailing list