reversing polylines

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
mrhickman53
Junior Member
Posts: 17
Joined: Thu Sep 07, 2023 1:17 am

reversing polylines

Post by mrhickman53 » Thu Feb 22, 2024 2:38 pm

RPolyline.reverse() apparently only returns the bool value of true. What is the intent of this method?

Does a method exist for RPolyline which will reverse the direction of the polyline, reverse the order of the vertices?

I want to reverse a polyline then appendVertex() or appendShape() to the original startPoint of the polyline. I have polylines that I am attempting to aggregate that were drawn with different orientations, clockwise or counter-clockwise with respect to the closed outline I am attempting to create from them.

User avatar
andrew
Site Admin
Posts: 9063
Joined: Fri Mar 30, 2007 6:07 am

Re: reversing polylines

Post by andrew » Thu Feb 22, 2024 2:45 pm

Yes, reverse is the method you are looking for. Perhaps, you can provide a bit of context (code), so we can help efficiently.

You also might want to have a look at this code of the Modify > Reverse tool of QCAD which also works for polylines:
https://github.com/qcad/qcad/blob/maste ... Reverse.js

CVH
Premier Member
Posts: 3480
Joined: Wed Sep 27, 2017 4:17 pm

Re: reversing polylines

Post by CVH » Thu Feb 22, 2024 10:11 pm

Hi,

With an RPolyline shape in a variable called 'poly'
poly.reverse(); will reverse the orientation of the RPolyline stored in 'poly'.

That is all there is to it.
Also see:
https://qcad.org/doc/qcad/3.0/developer ... 14d08a32ef

var test = poly.reverse(); will indeed return a boolean in 'test' and also reverse the orientation of the shape in 'poly'.

You really don't need the var test = part.
The boolean is always true, see: https://github.com/qcad/qcad/blob/maste ... 1938-L1967
Line 1966 simply returns true.

Regards,
CVH

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”