Skip to content

Commit

Permalink
Adjust pyproject, add more docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
m-clare committed Jun 2, 2024
1 parent d5b58b2 commit 5211210
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 7 deletions.
23 changes: 20 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <mclare@utsv.net>"]
maintainers = [
"Maryanne Wachter <mclare@utsv.net>",
"Connor Ferster <connorferser@gmail.com>"
]
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"
Expand All @@ -24,5 +42,4 @@ requires = ["poetry-core>=1.0.0",
"Cython>=3.0",
"setuptools",
"numpy"]

build-backend = "poetry.core.masonry.api"
76 changes: 72 additions & 4 deletions src/cytriangle/cytriangle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 5211210

Please sign in to comment.