Check if some subpaths of QPainterPath is closed or not



  • Hello,
    I'm trying to figure out a way to check if some of the subpaths contained into a QPainterPath is closed or not.
    What I want to achieve is a generic procedure to filter out all open subpaths and return a QPainterPath with only closed paths.

    Any suggestions ?

    Thanks,
    Gianluca.


  • Moderators

    @
    QPainterPath path = ....;
    QPainterPath newPath;

    foreach( QPolygonF poly, path.QList<QPolygonF> QPainterPath::toSubpathPolygons () )
    {
    if( poly.isEmpty() )
    continue;
    if( ! poly.isClosed() )
    poly << poly.first();
    newPath.addPolygon(poly);
    }
    @

    Not tested though.



  • The polygons returned from toSubpathPolygons are always closed even if they are not !!
    Maybe, they will be closed like the toFillPolygons ??

    However, my question is ill posed, because what I'm looking for is something different that it not belong to the definition of closed written in the document ion of Polygon::isClosed()


  • Moderators

    [quote author="Gianluca" date="1389624359"]The polygons returned from toSubpathPolygons are always closed even if they are not !!
    [/quote]
    Depending on the type of the polygon. How can a line be closed?

    [quote author="Gianluca" date="1389624359"]
    However, my question is ill posed, because what I'm looking for is something different that it not belong to the definition of closed written in the document ion of Polygon::isClosed()
    [/quote]
    and if you want to receive an answer to your question you should tell us what you meant with "closed"...



  • Yes, I know that I should give the correct definition on what I'm looking for, but at the moment I don't have a good definition, and I don't want to confuse people anymore.

    However, changing a bit topic, and talking about the toSubpathsPolygon, it happens the following:
    if you add a "U" shape made up of lines (using lineTo) to a Path, then the corresponding polygon returned by toSubpathsPolygons is closed !!
    But that polygon is not close in any sense !
    So, I suppose that the method will add a line to close the "U" shape as the toFillPolygons do.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.