# Path: pyhull/voronoi.py
# class VoronoiTess(object):
#     """
#     Voronoi tessellation for a set of points.
# 
#     .. attribute: dim
# 
#         Dimension of the points.
# 
#     .. attribute: points
# 
#         Original points supplied.
# 
#     .. attribute: vertices
# 
#         Vertices of the Voronoi tessellation as a list of coords.
#         E.g., [[-10.101, -10.101], [0.0, -0.5], [-0.5, 0.0], [0.5, 0.0],
#         [0.0, 0.5]]. Note that the value -10.101 is used by qhull to
#         represent a point at infinity.
# 
#     .. attribute: regions
# 
#         Regions of the Voronoi tessellation as a list of vertex indices.
#         E.g., [[4, 2, 1, 3], [2, 0, 1], [4, 0, 2], [3, 0, 1], [4, 0, 3]]
# 
#     .. attribute: ridges
# 
#         Ridges of the Voronoi tessellation as a dict of adjacent point
#         indices to list of vertex indices.
#         E.g., {(0, 1): [1, 2], (1, 2): [0, 2], (1, 3): [0, 1], (2, 4): [0, 4],
#         (0, 4): [3, 4], (0, 3): [1, 3], (3, 4): [0, 3], (0, 2): [2, 4]}
#         The key is a tuple of length 2 indicating the indices of adjacent
#         points. The values are a list of vertex indices. Hence, (0, 1) : [1,
#         2] indicates a ridge that is between points[0] and points[1],
#         with vertices at vertices[1] and vertices[2]. See the points and
#         vertices attributes for the actual coordinates.
#     """
# 
#     def __init__(self, points, add_bounding_box=False):
#         """
#         Initializes a VoronoiTess from points.
# 
#         Args:
#             points ([[float]]): All the points as a sequence of sequences.
#                 e.g., [[-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
#             add_bounding_box (bool): If True, a hypercube corresponding to
#                 the extremes of each coordinate will be added to the list of
#                 points.
#         """
#         self.points = list(points)
#         dim = [len(i) for i in self.points]
#         if max(dim) != min(dim):
#             raise ValueError("Input points must all have the same dimension!")
#         self.dim = dim[0]
#         if add_bounding_box:
#             coord_ranges = zip(np.amin(points, 0), np.amax(points, 0))
#             for coord in itertools.product(*coord_ranges):
#                 self.points.append(coord)
#         output = qvoronoi("o Fv", self.points)
#         output.pop(0)
#         nvertices, nregions, i = [int(i) for i in output.pop(0).split()]
#         self.vertices = [[float(j) for j in output.pop(0).split()]
#                          for i in range(nvertices)]
#         self.regions = [[int(j) for j in output.pop(0).split()[1:]]
#                         for i in range(nregions)]
# 
#         output.pop(0)
#         ridges = {}
#         for line in output:
#             val = [int(i) for i in line.split()]
#             ridges[tuple(val[1:3])] = val[3:]
#         self.ridges = ridges


import unittest
import numpy as np
from pyhull.voronoi import VoronoiTess
        data = [[0,0], [-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
        self.voro = VoronoiTess(data)
        sphere_data = [[0.3927286959385721, 0.3027233106882571,
                        -0.0642087887467873],
                       [-0.3040289937812381, 0.08411211324060132,
                        -0.3879323695524365],
                       [-0.4167147320140305, -0.1124203247935928,
                        0.252409395022804],
                       [-0.09784613055257477, 0.3994051836806832,
                        0.2844321254445218],
                       [0.0167085276338464, 0.4969839143091518,
                        0.05222847903455247],
                       [-0.3010383814570601, 0.3973744439739354,
                        0.03833332970300512],
                       [0.321916886905792, -0.3514017778986294,
                        -0.1512822144687402],
                       [-0.02357104947939958, 0.4654006301246191,
                        -0.1812364728912125],
                       [0.3199720537828011, -0.3299443654301472,
                        -0.1968618818332127],
                       [-0.4630278928730662, -0.1886147011806086,
                        0.005446551209538857]]
        self.spvoro = VoronoiTess(sphere_data)

        #Make sure higher dim works.
        points = np.random.randn(10, 5)
        self.hdvoro = VoronoiTess(points)

        #Check that bad points raises an error.
        bad_points = [[0,0], [0,1,0], [0,0]]

# Path: pyhull/voronoi.py
# class VoronoiTess(object):
#     """
#     Voronoi tessellation for a set of points.
# 
#     .. attribute: dim
# 
#         Dimension of the points.
# 
#     .. attribute: points
# 
#         Original points supplied.
# 
#     .. attribute: vertices
# 
#         Vertices of the Voronoi tessellation as a list of coords.
#         E.g., [[-10.101, -10.101], [0.0, -0.5], [-0.5, 0.0], [0.5, 0.0],
#         [0.0, 0.5]]. Note that the value -10.101 is used by qhull to
#         represent a point at infinity.
# 
#     .. attribute: regions
# 
#         Regions of the Voronoi tessellation as a list of vertex indices.
#         E.g., [[4, 2, 1, 3], [2, 0, 1], [4, 0, 2], [3, 0, 1], [4, 0, 3]]
# 
#     .. attribute: ridges
# 
#         Ridges of the Voronoi tessellation as a dict of adjacent point
#         indices to list of vertex indices.
#         E.g., {(0, 1): [1, 2], (1, 2): [0, 2], (1, 3): [0, 1], (2, 4): [0, 4],
#         (0, 4): [3, 4], (0, 3): [1, 3], (3, 4): [0, 3], (0, 2): [2, 4]}
#         The key is a tuple of length 2 indicating the indices of adjacent
#         points. The values are a list of vertex indices. Hence, (0, 1) : [1,
#         2] indicates a ridge that is between points[0] and points[1],
#         with vertices at vertices[1] and vertices[2]. See the points and
#         vertices attributes for the actual coordinates.
#     """
# 
#     def __init__(self, points, add_bounding_box=False):
#         """
#         Initializes a VoronoiTess from points.
# 
#         Args:
#             points ([[float]]): All the points as a sequence of sequences.
#                 e.g., [[-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
#             add_bounding_box (bool): If True, a hypercube corresponding to
#                 the extremes of each coordinate will be added to the list of
#                 points.
#         """
#         self.points = list(points)
#         dim = [len(i) for i in self.points]
#         if max(dim) != min(dim):
#             raise ValueError("Input points must all have the same dimension!")
#         self.dim = dim[0]
#         if add_bounding_box:
#             coord_ranges = zip(np.amin(points, 0), np.amax(points, 0))
#             for coord in itertools.product(*coord_ranges):
#                 self.points.append(coord)
#         output = qvoronoi("o Fv", self.points)
#         output.pop(0)
#         nvertices, nregions, i = [int(i) for i in output.pop(0).split()]
#         self.vertices = [[float(j) for j in output.pop(0).split()]
#                          for i in range(nvertices)]
#         self.regions = [[int(j) for j in output.pop(0).split()[1:]]
#                         for i in range(nregions)]
# 
#         output.pop(0)
#         ridges = {}
#         for line in output:
#             val = [int(i) for i in line.split()]
#             ridges[tuple(val[1:3])] = val[3:]
#         self.ridges = ridges


# Path: pyhull/tests/test_voronoi.py
import unittest
import numpy as np
from pyhull.voronoi import VoronoiTess

        data = [[0,0], [-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
        self.voro = VoronoiTess(data)
        sphere_data = [[0.3927286959385721, 0.3027233106882571,
                        -0.0642087887467873],
                       [-0.3040289937812381, 0.08411211324060132,
                        -0.3879323695524365],
                       [-0.4167147320140305, -0.1124203247935928,
                        0.252409395022804],
                       [-0.09784613055257477, 0.3994051836806832,
                        0.2844321254445218],
                       [0.0167085276338464, 0.4969839143091518,
                        0.05222847903455247],
                       [-0.3010383814570601, 0.3973744439739354,
                        0.03833332970300512],
                       [0.321916886905792, -0.3514017778986294,
                        -0.1512822144687402],
                       [-0.02357104947939958, 0.4654006301246191,
                        -0.1812364728912125],
                       [0.3199720537828011, -0.3299443654301472,
                        -0.1968618818332127],
                       [-0.4630278928730662, -0.1886147011806086,
                        0.005446551209538857]]
        self.spvoro = VoronoiTess(sphere_data)

        #Make sure higher dim works.
        points = np.random.randn(10, 5)
        self.hdvoro = VoronoiTess(points)

        #Check that bad points raises an error.
        bad_points = [[0,0], [0,1,0], [0,0]]

        self.assertRaises(ValueError, VoronoiTess, bad_points)