[Interest] Distance from point to path.

Elvis Stansvik elvstone at gmail.com
Tue Dec 29 15:49:33 CET 2015


2015-12-29 15:07 GMT+01:00 william.crocker at analog.com
<william.crocker at analog.com>:
> On 12/29/2015 06:42 AM, Elvis Stansvik wrote:
>>
>> 2015-12-28 22:49 GMT+01:00 william.crocker at analog.com
>>>
>>>
>>> Given a QPoint and a QPainterPath.
>>> How do I find the distance from the QPoint to the
>>> closest point along the QPainterPath.
>>>
>> Like Konstantin said, the best approach probably depends on whether
>> you know something about your paths or not (all lines? all arcs?
>>
>
> I can do it, but I should not have to.
> Many programs suffer from this annoyance.
>
>    I clearly point at object A and it selects object B.
>    (Probably because it stops at the first intersecting object.)
>
> I say this is an important feature enhancement.
>
>    Provide a function on a QPainterPath to find the
>    distance of closest approach to a QPoint.

Perhaps. But you should consider that QPainterPath is, as the name
suggests, primarily for painting, and not meant for solving generic
geometric problems. So I'm not sure how a feature request for this
would be received by the Qt devs. Point projection is one problem, but
there are many others, and they are surely not all within the scope of
QPainterPath.

If I were you, I would instead try to find a library that can
calculate the minimum point-to-bezier distance, or if you feel up for
it, implement it yourself. The line case is trivial.

Elvis

>
> I could then use QGraphicsScene::items() to find the
> intersecting set of a bounding rectangle around the
> mouse click and then nail it down with distance to
> each object in that set.
>
>
>> Elvis
>>
>>>
>>> Thanks.
>>>
>>> Bill
>>>
>>> ---------
>>> All of the above to find the shape closest to a mouse click.
>>> Note that methods are provided to find the set of objects
>>> which intersect a rectangle centered on the point, but which one
>>> is really the closest?
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list