<?php

/**
|--------------------------------------------------------------------------
| Global Distance Functions
|--------------------------------------------------------------------------
|
| This is a home for functions that don't belong to any one class and
| that should be available anywhere in the application.
|
*/

/**
 |--------------------------------------------------------------------------
 | Metric functions
 |--------------------------------------------------------------------------
 | Functions that convert from metric to imperial or from a smaller
 | metric unit to a larger one.
 |
 */

if (! function_exists('centimeters2Inches')) {
    /**
     * Convert from centimeters to inches.
     *
     * @since 1.0.0
     *
     * @param float|int|string $centimeters
     * @param int $precision
     *
     * @return float
     */
    function centimeters2Inches($centimeters, int $preceision = 1): float
    {
        return round(($centimeters / 2.54), $preceision);
    }
}

if (! function_exists('centimeters2Feet')) {
    /**
     * Convert from centimeters to inches.
     *
     * @since 1.0.0
     *
     * @param float|int|string $centimeters
     * @param int $precision
     *
     * @return float
     */
    function centimeters2Feet($centimeters, int $preceision = 1): float
    {
        return round((($centimeters / 2.54) * 12), $preceision);
    }
}

if (! function_exists('centimeters2Meters')) {
    /**
     * Convert from centimeters to meters.
     *
     * @since 1.0.0
     *
     * @param float|int|string $centimeters
     * @param int $precision
     *
     * @return float
     */
    function centimeters2Meters($centimeters, int $preceision = 1): float
    {
        return round(($centimeters / 100), $preceision);
    }
}

if (! function_exists('centimeters2Yards')) {
    /**
     * Convert from centimeters to yards.
     *
     * @since 1.0.0
     *
     * @param float|int|string $centimeters
     * @param int $precision
     *
     * @return float
     */
    function centimeters2Yards($centimeters, int $preceision = 1): float
    {
        return round(($centimeters / 91.44), $preceision);
    }
}

if (! function_exists('meters2Miles')) {
    /**
     * Convert from meters to miles.
     *
     * @since 1.0.0
     *
     * @param float|int|string $meters
     * @param int $precision
     *
     * @return float
     */
    function meters2Miles($meters, int $preceision = 1): float
    {
        return round(($meters * 0.00062137), $preceision);
    }
}

if (! function_exists('kilometers2Miles')) {
    /**
     * Convert from kilometers to meters.
     *
     * @since 1.0.0
     *
     * @param float|int|string $kilometers
     * @param int $precision
     *
     * @return float
     */
    function kilometers2Miles($kilometers, int $preceision = 1): float
    {
        return round(($kilometers * 1.609), $preceision);
    }
}

if (! function_exists('meters2Kilometers')) {
    /**
     * Convert from meters to kilometers.
     *
     * @since 1.0.0
     *
     * @param float|int|string $meters
     * @param int $precision
     *
     * @return float
     */
    function meters2Kilometers($meters, int $preceision = 1): float
    {
        return round(($meters / 1000), $preceision);
    }
}

if (! function_exists('millimeters2Inches')) {
    /**
     * Convert from millimeters to inches.
     *
     * @since 1.0.0
     *
     * @param float|int|string $millimeters
     * @param int $precision
     *
     * @return float
     */
    function millimeters2Inches($millimeters, int $preceision = 1): float
    {
        return round(($millimeters / 25.4), $preceision);
    }
}

/**
 |--------------------------------------------------------------------------
 | Imperial functions
 |--------------------------------------------------------------------------
 | Functions that convert from imperial to metric or from a smaller
 | imperial unit to a larger one.
 |
 */

if (! function_exists('inches2Millimeters')) {
    /**
     * Convert from inches to millimeters.
     *
     * @since 1.0.0
     *
     * @param float|int|string $inches
     * @param int $precision
     *
     * @return float
     */
    function inches2Millimeters($inches, int $preceision = 1): float
    {
        return round(($inches * 2.54), $preceision);
    }
}

if (! function_exists('inches2Meters')) {
    /**
     * Convert from inches to meters.
     *
     * @since 1.0.0
     *
     * @param float|int|string $inches
     * @param int $precision
     *
     * @return float
     */
    function inches2Meters($inches, int $preceision = 1): float
    {
        return round(($inches / 39.37), $preceision);
    }
}

if (! function_exists('inches2Yards')) {
    /**
     * Convert from inches to yards.
     *
     * @since 1.0.0
     *
     * @param float|int|string $inches
     * @param int $precision
     *
     * @return float
     */
    function inches2Yards($inches, int $preceision = 1): float
    {
        return round(($inches / 36), $preceision);
    }
}

if (! function_exists('inches2Feet')) {
    /**
     * Convert from inches to feet.
     *
     * @since 1.0.0
     *
     * @param float|int|string $inches
     * @param int $precision
     *
     * @return float
     */
    function inches2Feet($inches, int $preceision = 1): float
    {
        return round(($inches * 12), $preceision);
    }
}
