# Path: openmodes/helpers.py
# class Identified(object):
#     """An object which can be uniquely identified by an id number. It is
#     assumed that any object which subclasses Identified is immutable, so that
#     its id can be used for caching complex results which depend on this object.
#     """
# 
#     def __init__(self):
#         self.id = uuid.uuid4()
# 
#     def __hash__(self):
#         return self.id.__hash__()
# 
#     def __eq__(self, other):
#         return hasattr(other, 'id') and (self.id == other.id)
# 
#     def __repr__(self):
#         "Represent the object by its id, in addition to its memory address"
#         return ("<%s at 0x%08x with id %s>" % (str(self.__class__)[8:-2],
#                                                id(self),
#                                                str(self.id)))
# 
# Path: openmodes/external/point_in_polygon.py
# def wn_PnPoly(P, V):
#     wn = 0   # the winding number counter
# 
#     # repeat the first vertex at end
#     V = tuple(V[:]) + (V[0],)
# 
#     # loop through all edges of the polygon
#     for i in range(len(V)-1):     # edge from V[i] to V[i+1]
#         if V[i][1] <= P[1]:        # start y <= P[1]
#             if V[i+1][1] > P[1]:     # an upward crossing
#                 if is_left(V[i], V[i+1], P) > 0: # P left of edge
#                     wn += 1           # have a valid up intersect
#         else:                      # start y > P[1] (no test needed)
#             if V[i+1][1] <= P[1]:    # a downward crossing
#                 if is_left(V[i], V[i+1], P) < 0: # P right of edge
#                     wn -= 1           # have a valid down intersect
#     return wn


import numpy as np
import numpy.linalg as la
import scipy.special
from openmodes.helpers import Identified
from openmodes.external.point_in_polygon import wn_PnPoly
        from openmodes import dunavant
    n = num_points

    phi = 0.5*(1 + np.sqrt(5))
    i = -n+1 + 2*np.arange(num_points, dtype=np.float64)

    theta = 2*np.pi*i / phi

    sphi = i/n
    cphi = np.sqrt((n + i) * (n - i)) / n

    if cartesian:
        x = cphi * np.sin(theta)
        y = cphi * np.cos(theta)
        z = sphi
        return x, y, z
    else:
        phi = np.arctan2(sphi, cphi)
        return theta, phi


class Contour(object):
    """A contour for line integration in the complex plane"""

    def points_inside(self, points):
        "Check each point to see whether it lies within the contour"
        vertices = np.array([x for x, w in self])
        vertices = np.hstack((vertices.real[:, None], vertices.imag[:, None]))
        inside = np.empty(np.product(points.shape), dtype=np.bool)

        for point_num, point in enumerate(points.flat):

# Path: openmodes/helpers.py
# class Identified(object):
#     """An object which can be uniquely identified by an id number. It is
#     assumed that any object which subclasses Identified is immutable, so that
#     its id can be used for caching complex results which depend on this object.
#     """
# 
#     def __init__(self):
#         self.id = uuid.uuid4()
# 
#     def __hash__(self):
#         return self.id.__hash__()
# 
#     def __eq__(self, other):
#         return hasattr(other, 'id') and (self.id == other.id)
# 
#     def __repr__(self):
#         "Represent the object by its id, in addition to its memory address"
#         return ("<%s at 0x%08x with id %s>" % (str(self.__class__)[8:-2],
#                                                id(self),
#                                                str(self.id)))
# 
# Path: openmodes/external/point_in_polygon.py
# def wn_PnPoly(P, V):
#     wn = 0   # the winding number counter
# 
#     # repeat the first vertex at end
#     V = tuple(V[:]) + (V[0],)
# 
#     # loop through all edges of the polygon
#     for i in range(len(V)-1):     # edge from V[i] to V[i+1]
#         if V[i][1] <= P[1]:        # start y <= P[1]
#             if V[i+1][1] > P[1]:     # an upward crossing
#                 if is_left(V[i], V[i+1], P) > 0: # P left of edge
#                     wn += 1           # have a valid up intersect
#         else:                      # start y > P[1] (no test needed)
#             if V[i+1][1] <= P[1]:    # a downward crossing
#                 if is_left(V[i], V[i+1], P) < 0: # P right of edge
#                     wn -= 1           # have a valid down intersect
#     return wn


# Path: openmodes/integration.py
import numpy as np
import numpy.linalg as la
import scipy.special
from openmodes.helpers import Identified
from openmodes.external.point_in_polygon import wn_PnPoly
        from openmodes import dunavant

    n = num_points

    phi = 0.5*(1 + np.sqrt(5))
    i = -n+1 + 2*np.arange(num_points, dtype=np.float64)

    theta = 2*np.pi*i / phi

    sphi = i/n
    cphi = np.sqrt((n + i) * (n - i)) / n

    if cartesian:
        x = cphi * np.sin(theta)
        y = cphi * np.cos(theta)
        z = sphi
        return x, y, z
    else:
        phi = np.arctan2(sphi, cphi)
        return theta, phi


class Contour(object):
    """A contour for line integration in the complex plane"""

    def points_inside(self, points):
        "Check each point to see whether it lies within the contour"
        vertices = np.array([x for x, w in self])
        vertices = np.hstack((vertices.real[:, None], vertices.imag[:, None]))
        inside = np.empty(np.product(points.shape), dtype=np.bool)

        for point_num, point in enumerate(points.flat):

            inside[point_num] = wn_PnPoly((point.real, point.imag), vertices)