# -*- coding: utf-8 -*-

"""axes.py

A module containing functions that generate and operate on different axes
types. David Janssen wrote them, Tom Wallis tweaked and documented.

"""

from __future__ import print_function, division
import numpy as np

#-----------------------------------------------------------------------------#
#                                 Local Utility                               #
#-----------------------------------------------------------------------------#


def unpack_container(*args):
    """Unpack a container

    If container contains a single entry, which is a container as well, return
    the nested container. In all other cases, return the original container.

    Suggested use:
    def foo(*args):
        tuple(unpack_container(args))

    foo(1, 2, 3) == foo((1, 2, 3)) == foo(((1, 2, 3)))
    t

    """
    if len(args) == 1 and hasattr(args[0], 'count'):
        return unpack_container(*args[0])
    else:
        return args


def parse_axes_limits(*args):
    """Return parsed axes limits

    Axes-limits are defined as:
    [xmin xmax ymin ymax]

    Arguments to this function can be provided either as tuple, or as separate
    arguments, they are treated equivalently. Furthermore, the input can be
    either a single number, a pair of number, or a set of four numbers.

    Axes limits can be:
      - n -> (-n, n, -n, n)
      - (a, b) -> (a, b, a, b)
      - (a, b, c, d) -> (a, b, c, d)