def triangulate_polygon(polygon,
                        triangle_args='pq30',
                        engine='auto',
                        **kwargs):
    """
    Given a shapely polygon create a triangulation using one
    of the python interfaces to triangle.c:
    > pip install meshpy
    > pip install triangle

    Parameters
    ---------
    polygon : Shapely.geometry.Polygon
        Polygon object to be triangulated
    triangle_args : str
        Passed to triangle.triangulate
    engine : str
        'meshpy', 'triangle', or 'auto'
    kwargs: passed directly to meshpy.triangle.build:
            triangle.build(mesh_info,
                           verbose=False,
                           refinement_func=None,
                           attributes=False,
                           volume_constraints=True,
                           max_volume=None,
                           allow_boundary_steiner=True,
                           allow_volume_steiner=True,
                           quality_meshing=True,
                           generate_edges=None,
                           generate_faces=False,
                           min_angle=None)

    Returns
    --------------
    vertices : (n, 2) float
       Points in space
    faces :    (n, 3) int
       Index of vertices that make up triangles
    """

    # turn the polygon in to vertices, segments, and hole points
    arg = _polygon_to_kwargs(polygon)

    try:
        if str(engine).strip() in ['auto', 'triangle']:
            from triangle import triangulate
            result = triangulate(arg, triangle_args)
            return result['vertices'], result['triangles']
    except ImportError:
        # no `triangle` so move on to `meshpy`
        pass
    except BaseException as E:
        # if we see an exception log it and move on
        log.error('failed to triangulate using triangle!',
                  exc_info=True)
        # if we are running unit tests exit here and fail
        if tol.strict:
            raise E

    # do the import here, as sometimes this import can segfault
    # which is not catchable with a try/except block
    from meshpy import triangle
    # call meshpy.triangle on our cleaned representation
    info = triangle.MeshInfo()
    info.set_points(arg['vertices'])
    info.set_facets(arg['segments'])
    # not all polygons have holes
    if 'holes' in arg:
        info.set_holes(arg['holes'])
    # build mesh and pass kwargs to triangle
    mesh = triangle.build(info, **kwargs)
    # (n, 2) float vertices
    vertices = np.array(mesh.points, dtype=np.float64)
    # (m, 3) int faces
    faces = np.array(mesh.elements, dtype=np.int64)

    return vertices, faces
Given a shapely polygon create a triangulation using one
    of the python interfaces to triangle.c:
    > pip install meshpy
    > pip install triangle

    Parameters
    ---------
    polygon : Shapely.geometry.Polygon
        Polygon object to be triangulated
    triangle_args : str
        Passed to triangle.triangulate
    engine : str
        'meshpy', 'triangle', or 'auto'
    kwargs: passed directly to meshpy.triangle.build:
            triangle.build(mesh_info,
                           verbose=False,
                           refinement_func=None,
                           attributes=False,
                           volume_constraints=True,
                           max_volume=None,
                           allow_boundary_steiner=True,
                           allow_volume_steiner=True,
                           quality_meshing=True,
                           generate_edges=None,
                           generate_faces=False,
                           min_angle=None)

    Returns
    --------------
    vertices : (n, 2) float
       Points in space
    faces :    (n, 3) int
       Index of vertices that make up triangles