# Path: geomeppy/geom/polygons.py
# class Polygon2D(Polygon):
#     """Two-dimensional polygon."""
# 
#     n_dims = 2
#     vector_class = Vector2D
# 
#     def __eq__(self, other):
#         if self.__dict__ == other.__dict__:  # try the simple case first
#             return True
#         else:  # also cover same shape in different rotation
#             if self.difference(other):
#                 return False
#             if almostequal(self.normal_vector, other.normal_vector):
#                 return True
#         return False
# 
#     @property
#     def normal_vector(self):
#         # type: () -> Vector3D
#         as_3d = Polygon3D((v.x, v.y, 0) for v in self)
#         return as_3d.normal_vector
# 
#     def project_to_3D(self, example3d):
#         # type: (Polygon3D) -> Polygon3D
#         """Project the 2D polygon rotated into 3D space.
# 
#         This is used to return a previously rotated 3D polygon back to its original orientation, or to to put polygons
#         generated from pyclipper into the desired orientation.
# 
#         :param example3D: A 3D polygon in the desired plane.
#         :returns: A 3D polygon.
# 
#         """
#         points = self.points_matrix
#         proj_axis = example3d.projection_axis
#         a = example3d.distance
#         v = example3d.normal_vector
#         projected_points = project_to_3D(points, proj_axis, a, v)
#         return Polygon3D(projected_points)
# 
#     @property
#     def zs(self):
#         # type: () -> List[float]
#         return [0.0] * len(self.vertices)


from itertools import product
from geomeppy.geom.polygons import Polygon2D
"""Core and perimeter zoning approach."""


def get_core(footprint, perim_depth=None):
    poly = Polygon2D(footprint)
    core = poly.buffer(distance=-perim_depth)
    return core


def get_perims(footprint, core):
    perims = []
    poly = Polygon2D(footprint)
    for edge in poly.edges:
        c1 = sorted(
            product([edge.p1] * len(core), core),
            key=lambda x: x[0].relative_distance(x[1]),
        )[0][1]
        c2 = sorted(
            product([edge.p2] * len(core), core),
            key=lambda x: x[0].relative_distance(x[1]),
        )[0][1]

# Path: geomeppy/geom/polygons.py
# class Polygon2D(Polygon):
#     """Two-dimensional polygon."""
# 
#     n_dims = 2
#     vector_class = Vector2D
# 
#     def __eq__(self, other):
#         if self.__dict__ == other.__dict__:  # try the simple case first
#             return True
#         else:  # also cover same shape in different rotation
#             if self.difference(other):
#                 return False
#             if almostequal(self.normal_vector, other.normal_vector):
#                 return True
#         return False
# 
#     @property
#     def normal_vector(self):
#         # type: () -> Vector3D
#         as_3d = Polygon3D((v.x, v.y, 0) for v in self)
#         return as_3d.normal_vector
# 
#     def project_to_3D(self, example3d):
#         # type: (Polygon3D) -> Polygon3D
#         """Project the 2D polygon rotated into 3D space.
# 
#         This is used to return a previously rotated 3D polygon back to its original orientation, or to to put polygons
#         generated from pyclipper into the desired orientation.
# 
#         :param example3D: A 3D polygon in the desired plane.
#         :returns: A 3D polygon.
# 
#         """
#         points = self.points_matrix
#         proj_axis = example3d.projection_axis
#         a = example3d.distance
#         v = example3d.normal_vector
#         projected_points = project_to_3D(points, proj_axis, a, v)
#         return Polygon3D(projected_points)
# 
#     @property
#     def zs(self):
#         # type: () -> List[float]
#         return [0.0] * len(self.vertices)


# Path: geomeppy/geom/core_perim.py
from itertools import product
from geomeppy.geom.polygons import Polygon2D

"""Core and perimeter zoning approach."""


def get_core(footprint, perim_depth=None):
    poly = Polygon2D(footprint)
    core = poly.buffer(distance=-perim_depth)
    return core


def get_perims(footprint, core):
    perims = []
    poly = Polygon2D(footprint)
    for edge in poly.edges:
        c1 = sorted(
            product([edge.p1] * len(core), core),
            key=lambda x: x[0].relative_distance(x[1]),
        )[0][1]
        c2 = sorted(
            product([edge.p2] * len(core), core),
            key=lambda x: x[0].relative_distance(x[1]),
        )[0][1]

        perims.append(Polygon2D([c1, edge.p1, edge.p2, c2]))