MathPHP\NumericalAnalysis\Interpolation\ClampedCubicSpline::validateSpline PHP Method

validateSpline() public static method

Validate that there are enough input arrays (points), that each point array has precisely three numbers, and that no two points share the same first number (x-component)
public static validateSpline ( 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 validateSpline(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) !== 3) {
                throw new Exception\BadDataException('Each array needs to have have precisely three numbers, representing x, y, and y-prime');
            }
            $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;
    }

Usage Example

コード例 #1
0
 public function testNotAFunctionException()
 {
     // Two arrays share the same first number (x-component)
     $this->setExpectedException('MathPHP\\Exception\\BadDataException');
     ClampedCubicSpline::validateSpline([[0, 0, 1], [0, 5, 0], [1, 1, 3]]);
 }