math/Vector.php
public function distance(Vector $that, int $type = null) : float
    {
        if (null === $type) {
            $type = static::$defaultDistanceType;
        }

        switch ($type) {
            case self::DISTANCE_CARTESIAN:
                return $this->cartesianDistanceTo($that);

            case self::DISTANCE_CHEBYSHEV:
            case self::DISTANCE_CHESSBOARD:
                return $this->chebyshevDistanceTo($that);

            case self::DISTANCE_TAXICAB:
            case self::DISTANCE_MANHATTAN:
                return $this->taxicabDistanceTo($that);
        }

        throw new \InvalidArgumentException('Unsupported distance type ['.$type.'] given.');
    }
public function distance(Vector $that, int $type = null) : float
    {
        if (null === $type) {
            $type = static::$defaultDistanceType;
        }

        switch ($type) {
            case self::DISTANCE_CARTESIAN:
                return $this->cartesianDistanceTo($that);

            case self::DISTANCE_CHEBYSHEV:
            case self::DISTANCE_CHESSBOARD:
                return $this->chebyshevDistanceTo($that);

            case self::DISTANCE_TAXICAB:
            case self::DISTANCE_MANHATTAN:
                return $this->taxicabDistanceTo($that);
        }

        throw new \InvalidArgumentException('Unsupported distance type ['.$type.'] given.');
    }
public function distance ( Vector $ that , int $ type = null ) : float { if ( null === $ type ) { $ type = static :: $ defaultDistanceType ; } switch ( $ type ) { case self :: DISTANCE_CARTESIAN : return $ this -> cartesianDistanceTo ( $ that ) ; case self :: DISTANCE_CHEBYSHEV : case self :: DISTANCE_CHESSBOARD : return $ this -> chebyshevDistanceTo ( $ that ) ; case self :: DISTANCE_TAXICAB : case self :: DISTANCE_MANHATTAN : return $ this -> taxicabDistanceTo ( $ that ) ; } throw new \ InvalidArgumentException ( 'Unsupported distance type [' . $ type . '] given.' ) ; }
Returns the distance of this Vector to the given Vector.

@param   Vector      $that           The Vector to calculate the distance to.
@param   int|null    $type           The type of the distance (one of the DISTANCE_* class constants) or null
to use the value of the public static $defaultDistanceType (Cartesian
distance by default).
@return  float                       The distance of the specified type.
@throws  \InvalidArgumentException   When an unsupported distance type was given.
Returns the distance of this Vector to the given Vector .