<?php
// XNumber.php
// Created: 2023-09-15
// Updated: 2023-11-09

namespace Index;

use InvalidArgumentException;

/**
 * Provides various helper methods for numbers.
 */
final class XNumber {
    public static function weighted(float $num1, float $num2, float $weight): float {
        $weight = min(1, max(0, $weight));
        return ($num1 * $weight) + ($num2 * (1 - $weight));
    }

    public static function almostEquals(float $value1, float $value2): bool {
        return abs($value1 - $value2) <= PHP_FLOAT_EPSILON;
    }

    public static function easeInQuad(float $n): float {
        return $n * $n;
    }

    public static function easeOutQuad(float $n): float {
        return 1 - (1 - $n) * (1 - $n);
    }
}