bjoernffm / step-functions
Step Functions for php
Requires
- php: ^7.2
Requires (Dev)
- phpunit/phpunit: ^8.4
This package is not auto-updated.
Last update: 2024-11-18 19:14:20 UTC
README
Step Functions is a library which offers implementation of step functions. Define one or multiple functions, define the bounds where they are in use and this library will interpolate between the functions.
Installation
This library is provided as Composer package. To install it, simply execute the folowing command:
composer require bjoernffm/step-functions
Note: This library requires PHP 7.2.
Usage
The simplest usage that will mostly fulfill your needs is to define one or more functions and add them to an interpolator instance:
<?php use bjoernffm\stepFunctions\StepFunction; use bjoernffm\stepFunctions\Interpolator; require 'vendor/autoload.php'; $first = new StepFunction(0, 1, function($input) { return $input; }); $second = new StepFunction(1, 2, function($input) { return -1*$input+2; }); $interpolator = new Interpolator(); $interpolator->add($first); $interpolator->add($second); echo $interpolator->getValue(0); // output 0 echo $interpolator->getValue(0.5); // output 0.5 echo $interpolator->getValue(1); // output 1 echo $interpolator->getValue(1.5); // output 0.5 echo $interpolator->getValue(2); // output 0
Contributing
Do you want to help improving this project? Simply fork it and post a pull request. You can do everything on your own, you don't need to ask if you can, just do all the awesome things you want!
This project is published under Apache-2.0 license.