public function setNext($param1, $param2 = null)
    {
        if($this->closed)
        {
            throw new LogicException('Boundary has been already closed.');
        }

        $numberOfArgs = func_num_args();
        
        if($numberOfArgs === 2)
        {
            $point = Point::getInstance($param1, $param2);
        }
        elseif($param1 instanceof Point)
        {
            $point = $param1;
        }
        else
        {
            throw new InvalidArgumentException('Passed argument(s) should be coordinations or Point object.');
        }

        $oldNumberOfPoints = $this->numberOfPoints;
        $this->points[$oldNumberOfPoints] = $point;
        $this->numberOfPoints++;

        $diagonalPoint = $this->getDiagonalPoint();

        if(!$diagonalPoint || $diagonalPoint->compareYCoord($point) >= 0)
        {
            $this->diagonalPointYIndex = $oldNumberOfPoints;
        }
        
        if(!$diagonalPoint || $diagonalPoint->compareXCoord($point) <= 0)
        {
            $this->diagonalPointXIndex = $oldNumberOfPoints;
        }

        return $this;
    }