import math
from mass3d import Mass3D
from link3d import Link3D

class Circle:
    """Class for a circle of msd3D masses - fixed or floating."""

    def __init__(self):
        self.diameter = 0.0
        self.mass_count = 1
        self.mass_id = "mass"
        self.mass = 0.0
        self.fixed = False
        self.mass_size = 0.0
        self.collision_link_rigidity = 0.05
        self.prefix_id = False
        self.mass_messages = []
        self.link_messages = []

    def get_mass_setup_messages(self):
        """Returns a list of all msd creation messages for masses"""
        
        return self.mass_messages

    def get_link_setup_messages(self):
        """Returns a list of all msd creation messages for links"""
        
        return self.link_messages

    def create_circle(self):
        radius = self.diameter / 2.0

        increment = 2 * math.pi / self.mass_count
        angle = 0.0
        created_mass_count = 0
        
        while math.fabs(angle - (2 * math.pi)) > 1e-9:
            x = radius * math.sin(angle)
            
            if math.fabs(x) < 1e-9:
                x = 0
                
            y = radius * math.cos(angle)
            
            if math.fabs(y) < 1e-9:
                y = 0
                
            mass = Mass3D()
            
            if self.prefix_id == True:
                mass.id = str(created_mass_count) + "-" + self.mass_id
            else:
                mass.id = self.mass_id
            
            mass.fixed = self.fixed
            mass.mass = self.mass
            
            # Set position of mass (all have z value of 0)
            mass.position = (x, y, 0)
            self.mass_messages.append(mass.get_msd_setup_message())
            
            angle += increment
            created_mass_count += 1