'''
Created on 16-Apr-2021

@author: bthakur
'''
import inspect

from xv.util.data import CacheProcessor

class PopularShapesHelper():
    '''
    Popular shapes like soccer field etc.
    '''
    
    def __init__(self, **kwargs):
        self.verbose = kwargs.get('verbose', False)
        pass
    
    
    def plot_a_soccer_field(self, *args, **kwargs):
        '''
        @use_cache = True/False
        @refresh_cache = False/True
        '''
        cache_processor = CacheProcessor(verbose = self.verbose)
        
        method = self._plot_a_soccer_field
        plot_code, svg_str = cache_processor.get_svg_and_runnable_code(method, 
                                                                       *args, 
                                                                       **kwargs)
        plot_code = plot_code.replace("self.verbose", "False")
        return plot_code, svg_str
        pass

    
    def plot_a_soccer_field_to_png(self, *args, **kwargs):
        '''
        @use_cache = True/False
        @refresh_cache = False/True
        '''
        cache_processor = CacheProcessor(verbose = self.verbose)
        
        method = self._plot_a_soccer_field
        plot_code, svg_str = cache_processor.get_png_and_runnable_code(method, 
                                                                       *args, 
                                                                       **kwargs)
        plot_code = plot_code.replace("self.verbose", "False")
        return plot_code, svg_str
        pass

    
    def _plot_a_soccer_field(self):
        import matplotlib.pyplot as plt
        from numpy import linspace, pi, cos, sin
        plt.ioff()
        
        #Boundery
        #Left out line straight line
        plt.plot((1,1),(0,75), color = 'red')
        #Right out line straight line
        plt.plot((119,119),(0,75), color = 'red')
        #Down out line horizontal line
        plt.plot((0,119),(1,1), color = 'red')
        #Top out line horizontal line
        plt.plot((0,118),(74,74), color = 'red')
        
        #Panelty area of right side
        #Right Panelty area straight line
        plt.plot((102,102),(16.5,58.5), color = 'black')
        #Right Panelty area up horizontal line
        plt.plot((102,120),(58.5,58.5), color = 'black')
        #Right Panelty area dow horizontal line
        plt.plot((102,120),(16.5,16.5), color = 'black')
        
        #Panelty area on left side
        #Left Panelty area straight line
        plt.plot((19,19),(16.5,58.5), color = 'black')
        #Left Panelty area down horizontal line
        plt.plot((0,19),(16.5,16.5), color = 'black')
        #Left Panelty area up horizontal line
        plt.plot((0,19),(58.5,58.5), color = 'black')
        
        #Goal area of Right side
        #Right Goal area straight line
        plt.plot((109,109),(20.2,54.8), color = 'black')
        #Right Goal area up horizontal line
        plt.plot((109,120),(54.8,54.8), color = 'black')
        #Right Goal area down horizontal line
        plt.plot((109,120),(20.2,20.2), color = 'black')
        
        #Goal area of Left side
        #Left Goal area straight line
        plt.plot((12,12),(20.2,54.8), color = 'black')
        #Left Goal area down horizontal line
        plt.plot((0,12),(20.2,20.2), color = 'black')
        #Left Goal area up horizontal line
        plt.plot((0,12),(54.8,54.8), color = 'black')
        
        #Thinks in middle
        # Middle straight line
        plt.plot((60,60),(0,75), color = 'black')
        #Dot in middle
        plt.plot(60, 35, color = 'red', marker ='o', markersize = 10 )
        #Circle
        angles = linspace (0, 2 *  pi, 40)
        r = 10
        plt.plot (60 + r * cos(angles), 35 + r * sin(angles), color = 'black')
        #set uniform units for x and y axes 
        plt.gca().set_aspect('equal', adjustable='box')
        
        #Corner back
        #Left bottem Corner back
        angles = linspace (0 * (2 * pi / 4), 1 * (2 * pi / 4), 40)
        r = 6
        plt.plot (0 + r * cos(angles), 0 + r * sin(angles), color = 'black')
        #Right bottem Corner back
        angles = linspace (1 * (2 * pi / 4), 2 * (2 * pi / 4), 40)
        r = 6
        plt.plot (120 + r * cos(angles), 0 + r * sin(angles), color = 'black')
        #Left top Corner back
        angles = linspace (3 * (2 * pi / 4), 4 * (2 * pi / 4), 40)
        r = 6
        plt.plot (0 + r * cos(angles), 75 + r * sin(angles), color = 'black')
        #Right bottem Corner back
        angles = linspace (2 * (2 * pi / 4), 3 * (2 * pi / 4), 40)
        r = 6
        plt.plot (120 + r * cos(angles), 75 + r * sin(angles), color = 'black')
        
        #setting scale
        plt.xlim(0,120)
        plt.ylim(0,75)
        pass
    
    pass
#class PopularShapesHelper(
