# Path: py/fiberassign/utils.py
# def option_list(opts):
# def assert_isoformat_utc(time_str):
# def get_date_cutoff(datetype, cutoff_case):
# def get_svn_version(svn_dir):
# def get_last_line(fn):
# def read_ecsv_keys(fn):


from datetime import datetime, timezone
from scipy.interpolate import interp1d
from .utils import Logger
from ._internal import (
    Hardware,
    FIBER_STATE_OK,
    FIBER_STATE_UNASSIGNED,
    FIBER_STATE_STUCK,
    FIBER_STATE_BROKEN,
    FIBER_STATE_RESTRICT,
    Circle,
    Segments,
    Shape,
)
    from astropy.time import Time
    from desimeter.fiberassign import fiberassign_radec2xy_cs5, fiberassign_radec2xy_flat
    from desimeter.fiberassign import fiberassign_cs5_xy2radec, fiberassign_flat_xy2radec
    from astropy.time import Time
    from desimeter.transform.pos2ptl import flat2ptl
    from desimeter.transform.pos2ptl import ptl2flat
import numpy as np
import desimodel.io as dmio



def expand_closed_curve(xx, yy, margin):
    '''
    For the --margin-{pos,petal,gfa} options, we can add a buffer zone
    around the positioner keep-out polygons.  This function implements
    the geometry to achieve this.

    Given a RIGHT-HANDED closed polygon xx,yy and margin, returns new
    x,y coordinates expanded by a margin of `margin`.

    (By right-handed, I mean that the points are listed
    counter-clockwise, and if you walk the boundary, the inside of the
    shape is to the left; the expanded points will be to the right.)

    If the order of the polygon is reversed, the "expanded" points
    will actually be on the *inside* of the polygon.  Setting the
    margin negative counteracts this.

    Note that we strictly require a closed curve.  Collinear polygon
    segments will cause problems!

    '''
    ex, ey = [],[]

    # These are closed curves (last point = first point)
    # (this isn't strictly required by the fundamental algorithm, but is assumed
    # in the way we select previous and next points in the loop below.)
    if (xx[0] != xx[-1]) or (yy[0] != yy[-1]):

# Path: py/fiberassign/utils.py
# def option_list(opts):
# def assert_isoformat_utc(time_str):
# def get_date_cutoff(datetype, cutoff_case):
# def get_svn_version(svn_dir):
# def get_last_line(fn):
# def read_ecsv_keys(fn):


# Path: py/fiberassign/hardware.py
from datetime import datetime, timezone
from scipy.interpolate import interp1d
from .utils import Logger
from ._internal import (
    Hardware,
    FIBER_STATE_OK,
    FIBER_STATE_UNASSIGNED,
    FIBER_STATE_STUCK,
    FIBER_STATE_BROKEN,
    FIBER_STATE_RESTRICT,
    Circle,
    Segments,
    Shape,
)
    from astropy.time import Time
    from desimeter.fiberassign import fiberassign_radec2xy_cs5, fiberassign_radec2xy_flat
    from desimeter.fiberassign import fiberassign_cs5_xy2radec, fiberassign_flat_xy2radec
    from astropy.time import Time
    from desimeter.transform.pos2ptl import flat2ptl
    from desimeter.transform.pos2ptl import ptl2flat
import numpy as np
import desimodel.io as dmio




def expand_closed_curve(xx, yy, margin):
    '''
    For the --margin-{pos,petal,gfa} options, we can add a buffer zone
    around the positioner keep-out polygons.  This function implements
    the geometry to achieve this.

    Given a RIGHT-HANDED closed polygon xx,yy and margin, returns new
    x,y coordinates expanded by a margin of `margin`.

    (By right-handed, I mean that the points are listed
    counter-clockwise, and if you walk the boundary, the inside of the
    shape is to the left; the expanded points will be to the right.)

    If the order of the polygon is reversed, the "expanded" points
    will actually be on the *inside* of the polygon.  Setting the
    margin negative counteracts this.

    Note that we strictly require a closed curve.  Collinear polygon
    segments will cause problems!

    '''
    ex, ey = [],[]

    # These are closed curves (last point = first point)
    # (this isn't strictly required by the fundamental algorithm, but is assumed
    # in the way we select previous and next points in the loop below.)
    if (xx[0] != xx[-1]) or (yy[0] != yy[-1]):

        log = Logger.get()