<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _calculate_port_pos_on_line(self, port_num, side_length, port_width=None):
 """Calculate the position of a port on a line The position depends on the number of element. Elements are equally spaced. If the end of the line is reached, ports are stacked. :param int port_num: The number of the port of that type :param float side_length: The length of the side the element is placed on :param float port_width: The width of one port :return: The position on the line for the given port :rtype: float """

        if port_width is None:
            port_width = 2 * self.border_width
        border_size = self.border_width
        pos = 0.5 * border_size + port_num * port_width
        outermost_pos = max(side_length / 2., side_length - 0.5 * border_size - port_width)
        pos = min(pos, outermost_pos)
        return pos