diff --git a/README.rst b/README.rst index 717491e..865da1a 100644 --- a/README.rst +++ b/README.rst @@ -23,24 +23,26 @@ For further information, see the latest `release notes v3.15) and the -availability of a compiler with c++17 compatibility. Currently the package has been tested on Windows 10, using VS2019. E +Alternatively, pyclipr may be compiled directly from source within the python environment. Currently the prerequisites +are the a compliant c++ build environment include CMake build system (>v3.15) and the availability of a compiler with +c++17 compatibility. Currently the package has been tested built using Windows 10, using VS2019 and Mac OSX Sonoma. -Ensure that you perform the recurisve submodule when initialising the repoistory. +Firstly, clone the PyClipr repository whilst ensuring that you perform the recurisve submodule when initialising +the repoistory. This ensures that all dependencies (pybind, pyclipr, eigen, fmt) are downloaded into the source tree. .. code:: bash @@ -70,17 +72,16 @@ by using either `execute` or `execute2` methods, respectively. # Tuple definition of a path path = [(0.0, 0.), (0, 105.1234), (100, 105.1234), (100, 0), (0, 0)] - path2 = [(0, 0), (0, 50), (100, 50), (100, 0), (0,0)] - + path2 = [(1.0, 1.0), (1.0, 50), (100, 50), (100, 1.0), (1.0,1.0)] # Create an offsetting object po = pyclipr.ClipperOffset() # Set the scale factor to convert to internal integer representation - pc.scaleFactor = int(1000) + po.scaleFactor = int(1000) # add the path - ensuring to use Polygon for the endType argument - po.addPath(np.array(path), pyclipr.Miter, pyclipr.Polygon) + po.addPath(np.array(path), pyclipr.JoinType.Miter, pyclipr.EndType.Polygon) # Apply the offsetting operation using a delta. offsetSquare = po.execute(10.0) @@ -97,14 +98,18 @@ by using either `execute` or `execute2` methods, respectively. """ Test Polygon Clipping """ # Below returns paths - out = pc.execute(pyclipr.Intersection, pyclipr.EvenOdd) - out2 = pc.execute(pyclipr.Union, pyclipr.EvenOdd) - out3 = pc.execute(pyclipr.Difference, pyclipr.EvenOdd) - out4 = pc.execute(pyclipr.Xor, pyclipr.EvenOdd) + out = pc.execute(pyclipr.Intersection, pyclipr.FillRule.EvenOdd) + out2 = pc.execute(pyclipr.Union, pyclipr.FillRule.EvenOdd) + out3 = pc.execute(pyclipr.Difference, pyclipr.FillRule.EvenOdd) + out4 = pc.execute(pyclipr.Xor, pyclipr.FillRule.EvenOdd) # Using execute2 returns a PolyTree structure that provides hierarchical information inflormation # if the paths are interior or exterior - outB = pc.execute2(pyclipr.Intersection, pyclipr.EvenOdd) + outB = pc.execute2(pyclipr.Intersection, pyclipr.FillRule.EvenOdd) + + # An alternative equivalent name is executeTree + outB = pc.executeTree(pyclipr.Intersection, pyclipr.FillRule.EvenOdd) + """ Test Open Path Clipping """ # Pyclipr can be used for clipping open paths. This remains simple to complete using the Clipper2 library @@ -113,7 +118,7 @@ by using either `execute` or `execute2` methods, respectively. pc2.scaleFactor = int(1e5) # The open path is added as a subject (note the final argument is set to True) - pc2.addPath( ((50,-10),(50,110)), pyclipr.Subject, True) + pc2.addPath( ((40,-10),(50,130)), pyclipr.Subject, True) # The clipping object is usually set to the Polygon pc2.addPaths(offsetSquare, pyclipr.Clip, False) @@ -121,12 +126,27 @@ by using either `execute` or `execute2` methods, respectively. """ Test the return types for open path clipping with option enabled""" # The returnOpenPaths argument is set to True to return the open paths. Note this function only works # well using the Boolean intersection option - outC = pc2.execute(pyclipr.Intersection, pyclipr.NonZero) - outC2, openPathsC = pc2.execute(pyclipr.Intersection, pyclipr.NonZero, returnOpenPaths=True) + outC = pc2.execute(pyclipr.Intersection, pyclipr.FillRule.NonZero) + outC2, openPathsC = pc2.execute(pyclipr.Intersection, pyclipr.FillRule.NonZero, returnOpenPaths=True) + + outD = pc2.execute2(pyclipr.Intersection, pyclipr.FillRule.NonZero) + outD2, openPathsD = pc2.execute2(pyclipr.Intersection, pyclipr.FillRule.NonZero, returnOpenPaths=True) + + # Plot the results + pathPoly = np.array(path) - outD = pc2.execute2(pyclipr.Intersection, pyclipr.NonZero) - outD2, openPathsD = pc2.execute2(pyclipr.Intersection, pyclipr.NonZero, returnOpenPaths=True) + import matplotlib.pyplot as plt + plt.figure() + plt.axis('equal') + # Plot the original polygon + plt.fill(pathPoly[:,0], pathPoly[:,1], 'b', alpha=0.1, linewidth=1.0, linestyle='dashed', edgecolor='#000') + # Plot the offset square + plt.fill(offsetSquare[0][:, 0], offsetSquare[0][:, 1], linewidth=1.0, linestyle='dashed', edgecolor='#333', facecolor='none') + # Plot the intersection + plt.fill(out[0][:, 0], out[0][:, 1], facecolor='#75507b') + # Plot the open path intersection + plt.plot(openPathsC[0][:,0], openPathsC[0][:,1],color='#222', linewidth=1.0, linestyle='dashed', marker='.',markersize=20.0) \ No newline at end of file