# -*- coding: utf-8 -*-
"""polygon_sequence.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1DBTOWxlOh2KM7aveuK4u7nvptCSNydZx
"""

from google.colab import files
src = list(files.upload().values())[0]
open('polygon.py','wb').write(src)
import polygon

from polygon import Polygon as poly 
from functools import lru_cache

class Polygon_sequence:
    """ 
    A class which generates a regular strict convex polygon with desired vertex and circumradius
    """
    def __init__(self, vertices, circumradius):
        """
        A constructor to initialize the Polygon class attributes
        """
        self.vertices = vertices # Number of vertices of polygon
        self.circumradius = circumradius # Circumradius

    @property
    def vertices(self):
        """A function to calculate number of vertices"""
        return self.vertices


    def vertices(self, vertices):
        """A function to set the number of vertices of polygon"""
        if not isinstance(vertices, int):
            raise TypeError(f'Number of edges/vertices should be of type integer')
        if vertices < 3:
            raise ValueError(f'Number of edges/vertices should be greater than or equal to 3')

        self.vertices = vertices

    @property
    def circumradius(self):
        """A function to calculate circumradius"""
        return self.circumradius

    
    def circumradius(self, circumradius):
        """A function to set the circumradius of polygon"""
        if not isinstance(circumradius, int):
            raise TypeError(f'Circumradius should be of type integer')
        if radius < 0:
            raise ValueError(f'Circumradius should be greater than 0')

        self.circumradius = circumradius

    @property
    def max_efficiency_polygon(self):
        """ A function to find the max efficiency polygon """
        max_ratio = -100
        for i in range(self.vertices-2):
            area_perimeter_ratio = self.__getitem__(i)[1]
            if area_perimeter_ratio > max_ratio:
                max_ratio = area_perimeter_ratio
                max_ratio_polygon = self.__getitem__(i)[0]
        return max_ratio_polygon

    def __getitem__(self, sequence):
        """A function to get next item in the sequence """
        if isinstance(sequence, int):
            sequence = sequence + 3
            if sequence - 3 < 0:
                sequence = self.vertices + sequence - 3
            if sequence  < 3 or sequence > self.vertices:
                raise IndexError
            else:
                if sequence >= 3:
                    return Polygon_sequence._sequence(sequence, self.circumradius)
        else:
            raise TypeError ('Please provide valid integer value')

 

    def __len__(self)->int:
        """
        This is a length function
        """
        return self.vertices - 2


 
    def __repr__(self):
        """ Representation function for Polygon Sequence"""
        return (f'Polygon Sequence of ({self.vertices}, {self.circumradius})')


    @staticmethod
    @lru_cache(2 ** 10)
    def _sequence(sequence,circumradius):
        if sequence < 3:
            return None
        else:
            poly1 = poly(sequence,circumradius)
            return poly1 , poly1.area/poly1.perimeter