public static getSplinePoints ( $source, array $args = [] ) : array | ||
$source | The source of our approximation. Should be either a callback function or a set of arrays. | |
$args | array | The arguments of our callback function: derivative, start, end, and n. Example: [$derivative, 0, 8, 5]. If $source is a set of arrays, $args will default to []. |
return | array |
public static function getSplinePoints($source, array $args = []) : array
{
if (is_callable($source)) {
$function = $source;
$derivative = $args[0];
$start = $args[1];
$end = $args[2];
$n = $args[3];
$points = self::functionToSplinePoints($function, $derivative, $start, $end, $n);
} elseif (is_array($source)) {
$points = $source;
} else {
throw new Exception\BadDataException("Input source is incorrect. You need to input either a callback function or a set of arrays");
}
return $points;
}
public function testIncorrectInput() { // The input $source is neither a callback or a set of arrays $this->setExpectedException('MathPHP\\Exception\\BadDataException'); $x = 10; $incorrectFunction = $x ** 2 + 2 * $x + 1; ClampedCubicSpline::getSplinePoints($incorrectFunction, [0, 4, 5]); }