Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncrossing polygon functions. #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Uncrossing polygon functions. #269

wants to merge 1 commit into from

Commits on Jan 14, 2022

  1. Uncrossing polygon functions.

    This adds some utility functions, the most significant of which is
    uncrossPolygon. This can handle polygons with or without holes. Without
    holes, it takes a polygon in the form of a list of vertices with each
    vertex a list or tuple of at least two elements. For a polygon with
    holes, it takes a list of such polygons, where the first element in the
    list is the outside polygon and all other elements are the holes.
    
    If a polygon self-crosses, additional vertices will be added and part of
    the sequence of vertices will be reversed to uncross the polygon. If the
    polygon contains holes, each hole is checked to make sure it doesn't
    cross other holes or the outline polygon.
    
    The resultant polygon will have consistently clockwise vertices (though
    if the original polygon has multiple loops that only have a vertex in
    common, not all of the polygon may be consistently oriented).
    
    Examples:
    
    - `uncrossPolygon([[0, 4], [0, 2], [2, 2], [2, 0], [0, 0], [2, 4]])`
      results in `[[0, 4], [2, 4], [1, 2], [2, 2], [2, 0], [0, 0], [1, 2],
      [0, 2]]`
    
    - `uncrossPolygon([[[0, 0], [0, 2], [2, 2], [2, 0]], [[1, 1], [1, 3],
      [3, 3], [3, 1]]])` results in `[[[0, 0], [0, 2], [1, 2], [1, 1], [2,
      1], [2, 2], [1, 2], [1, 3], [3, 3], [3, 1], [2, 1], [2, 0]]]`
    manthey committed Jan 14, 2022
    Configuration menu
    Copy the full SHA
    5061098 View commit details
    Browse the repository at this point in the history