I have a QPainterPath that can hold any sequence of lines and/or cubic bezier curves. Now, I've got a QPoint that I need to calculate the shortest distance between the QPainterPath and the point. Since the path itself does not do much more than storing the elements in order I add them to the path, it doesn't provide such functionality by itself. The only idea I had was to construct a polygon using the QPainterPath::toFillPolygon(), but this sometimes returns me a polygon that is equal to the path and sometimes an empty polygon. Moreover, the QPolygonF object is just a list of points, some of them connected with lines, and some of them are not connected in the original path, but I can't find out which of them are connected and which not.
Is there any (simple) solution to calculate the shortest distance between a QPainterPath (preferably without converting to a polygon) and a QPoint?
QPainterPathhaspointAtPercent()so you can iterate the path at a given step and check the distances between a number of points lying on the path and the target point.This will give you roughly the shortest distance, and if you want more precision, you can focus on those segments of the path and iterate at a finer step.