MathPHP\NumericalAnalysis\Interpolation\Interpolation::validate PHP Method

validate() public static method

Validate that there are enough input arrays (points), that each point array has precisely two numbers, and that no two points share the same first number (x-component)
public static validate ( array $points, number $degree = 2 ) : boolean
$points array Array of arrays (points)
$degree number The miminum number of input arrays
return boolean
    public static function validate(array $points, $degree = 2) : bool
    {
        if (count($points) < $degree) {
            throw new Exception\BadDataException('You need to have at least $degree sets of coordinates (arrays) for this technique');
        }
        $x_coordinates = [];
        foreach ($points as $point) {
            if (count($point) !== 2) {
                throw new Exception\BadDataException('Each array needs to have have precisely two numbers, an x- and y-component');
            }
            $x_component = $point[self::X];
            if (in_array($x_component, $x_coordinates)) {
                throw new Exception\BadDataException('Not a function. Your input array contains more than one coordinate with the same x-component.');
            }
            array_push($x_coordinates, $x_component);
        }
        return true;
    }