From 5211210d06d98ca14c3221a002ce84e24d6836ce Mon Sep 17 00:00:00 2001 From: Maryanne Wachter Date: Sun, 2 Jun 2024 16:31:17 -0700 Subject: [PATCH] Adjust pyproject, add more docstrings --- pyproject.toml | 23 +++++++++-- src/cytriangle/cytriangle.pyx | 76 +++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 49033be..b0cdace 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,15 +1,33 @@ [tool.poetry] name = "cytriangle" -version = "0.1.0" +version = "1.0.0" description = "Object-oriented Cython wrapper of Shewchuk's Triangle Library" authors = ["Maryanne Wachter "] +maintainers = [ + "Maryanne Wachter ", + "Connor Ferster " +] license = "LGPL 3.0" repository = "https://github.com/m-clare/cytriangle" readme = "README.md" +keywords = [ + "finite-element-analysis", + "triangular-meshing", + "mesh", + "FEA" +] +classifiers = [ + "Environment :: Console", + "Topic :: Scientific/Engineering", + "Natural Language :: English", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] [tool.poetry.build] script = "build_ext.py" -generate-setup-file = true [tool.poetry.dependencies] python = ">=3.9" @@ -24,5 +42,4 @@ requires = ["poetry-core>=1.0.0", "Cython>=3.0", "setuptools", "numpy"] - build-backend = "poetry.core.masonry.api" diff --git a/src/cytriangle/cytriangle.pyx b/src/cytriangle/cytriangle.pyx index 29c3718..a3cb6f4 100644 --- a/src/cytriangle/cytriangle.pyx +++ b/src/cytriangle/cytriangle.pyx @@ -29,8 +29,15 @@ cdef class CyTriangle: Returns a dictionary representation of the triangulation voronoi output. validate_input_flags(opts=""): Checks validity of flag options to avoid obvious incompatibilities between - flags provided - + flags provided. + triangulate(triflags=""): + Computes the triangulation on the input object with -Qz and user input flags. + delaunay(): + Runs the triangulate method on the input object with -Qz flags. + convex_hull(): + Runs the triangulate method on the input object with the -Qzc flags. + voronoi(): + Runs the triangulate method on the input object with the -Qzc flags. """ cdef TriangleIO _in @@ -85,22 +92,83 @@ cdef class CyTriangle: # generic triangulation that accepts any switch cpdef triangulate(self, triflags=''): + """ + Runs the main triangulation method on the in_ object with any additional + user flags input as triflags. + + The following flags are included by default: + + - Q Quiet: suppresses all output messages from Triangle library + + - z Numbers all items starting from zero (zero-indexed) rather than one. + + Adapted from Shewchuk's documentation: + + The sequence is roughly as follows. Many of these steps can be skipped, + depending on the command line switches. + + - Read the vertices from a file and triangulate them (no -r) + - Insert the PSLG segments (-p), and possibly segments on the convex + hull (-c). + - Read the holes (-p), regional attributes (-pA), and regional area + constraints (-pa). Carve the holes and concavities, and spread the + regional attributes and area constraints. + - Enforce the constraints on minimum angle (-q) and maximum area (-a). + Also enforce the conforming Delaunay property (-q and -a). + - Compute the number of edges in the resulting mesh. + - Promote the mesh's linear triangles to higher order elements (-o). + - Write the output files. + - Check the consistency and Delaunay property of the mesh (-C). + + """ if triflags: self.validate_input_flags(triflags) opts = f"Qz{triflags}".encode('utf-8') if ctriangulate(opts, self._in._io, self._out._io, self._vorout._io) is not None: raise RuntimeError('Triangulation failed') + return self.out cpdef delaunay(self): + """ + Run the main triangulation method on the in_ object with *only* -Qz flags enabled. + + - Q Quiet: suppresses all output messages from Triangle library + + - z Numbers all items starting from zero (zero-indexed) rather than one. + + """ opts = "Qz".encode('utf-8') if ctriangulate(opts, self._in._io, self._out._io, self._vorout._io) is not None: raise RuntimeError('Delaunay triangulation failed') + return self.out cpdef convex_hull(self): + """ + Run the main triangulation method on the in_ object with -Qzc flags enabled. + + - Q Quiet: suppresses all output messages from Triangle library. + + - z Numbers all items starting from zero (zero-indexed) rather than one. + + - c Encloses the convex hull with segments + + """ opts = f"Qzc".encode('utf-8') if ctriangulate(opts, self._in._io, self._out._io, self._vorout._io) is not None: - raise RuntimeError('Convex hull construction failed') + raise RuntimeError('Delaunay triangulation and convex hull construction failed') + return self.out cpdef voronoi(self): + """ + Run the main triangulation method on the in_ object with -Qzv flags enabled. + + - Q Quiet: suppresses all output messages from Triangle library. + + - z Numbers all items starting from zero (zero-indexed) rather than one. + + - v Generates a Voronoi diagram. + + """ opts = f"Qzv".encode('utf-8') if ctriangulate(opts, self._in._io, self._out._io, self._vorout._io) is not None: - raise RuntimeError('Generation of voronoi diagram failed') + raise RuntimeError('Delaunay triangulation and generation of voronoi diagram failed') + return self.out