I want to produce offset in closed polygons using Clipper lib (http://www.angusj.com/delphi/clipper.php).
Since, I am using python 2.7, I am using pyclipper (https://pypi.python.org/pypi/pyclipper) to do the same.
Unfortunately, I am unable to comprehend from polygon offset example of clipper in C++:
#include "clipper.hpp"
...
using namespace ClipperLib;
int main()
{
Path subj;
Paths solution;
subj <<
IntPoint(348,257) << IntPoint(364,148) << IntPoint(362,148) <<
IntPoint(326,241) << IntPoint(295,219) << IntPoint(258,88) <<
IntPoint(440,129) << IntPoint(370,196) << IntPoint(372,275);
ClipperOffset co;
co.AddPath(subj, jtRound, etClosedPolygon);
co.Execute(solution, -7.0);
//draw solution ...
DrawPolygons(solution, 0x4000FF00, 0xFF009900);
}
To implement same in python .
I saw only one example (of clipping, not offset) of pyclipper:
import pyclipper
subj = (
((180, 200), (260, 200), (260, 150), (180, 150)),
((215, 160), (230, 190), (200, 190))
)
clip = ((190, 210), (240, 210), (240, 130), (190, 130))
pc = pyclipper.Pyclipper()
pc.AddPath(clip, pyclipper.PT_CLIP, True)
pc.AddPaths(subj, pyclipper.PT_SUBJ, True)
solution = pc.Execute(pyclipper.CT_INTERSECTION, pyclipper.PFT_EVENODD, pyclipper.PFT_EVENODD )
Unfortunately, not being an experienced programmer, I unable to move ahead.
Kindly help me in this regard.
Thanks in advance.
the same in pyclipper would be:
subj = ((348, 257), (364, 148), (362, 148), (326, 241), (295, 219), (258, 88), (440, 129), (370, 196), (372, 275))
pco = pyclipper.PyclipperOffset()
pco.AddPath(subj, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)
pco.Execute(-7.0)
""" Result (2 polygons, see image below):
[[[365, 260], [356, 254], [363, 202]], [[425, 133], [365, 191], [371, 149], [370, 145], [368, 142], [364, 141], [362, 141], [358, 142], [355, 145], [322, 230], [301, 215], [268, 98]]]
"""
We tried to keep the naming of pyclipper methods and functions as close to the original as possible for a python wrapper. Also the way it is supposed to be used with mimics the base library. The only big difference is in the way Execute
functions are used, as explained here pyclipper - How to use.
You can check the tests to get a better grasp on the usage.