From 55eddd7accf2c5f9b0f52b22a010c4c4b7c130d1 Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Fri, 6 Feb 2009 19:18:00 -0600 Subject: mv packages to config dir to match web layout --- config/dspam/pear/Image/Graph/Dataset/Function.php | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 config/dspam/pear/Image/Graph/Dataset/Function.php (limited to 'config/dspam/pear/Image/Graph/Dataset/Function.php') diff --git a/config/dspam/pear/Image/Graph/Dataset/Function.php b/config/dspam/pear/Image/Graph/Dataset/Function.php new file mode 100644 index 00000000..08174b1d --- /dev/null +++ b/config/dspam/pear/Image/Graph/Dataset/Function.php @@ -0,0 +1,147 @@ + + * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version CVS: $Id$ + * @link http://pear.php.net/package/Image_Graph + */ + +/** + * Include file Image/Graph/Dataset.php + */ +require_once 'Image/Graph/Dataset.php'; + +/** + * Function data set, points are generated by calling an external function. + * + * The function must be a single variable function and return a the result, + * builtin functions that are fx sin() or cos(). User defined function can be + * used if they are such, i.e: function myFunction($variable) + * + * @category Images + * @package Image_Graph + * @subpackage Dataset + * @author Jesper Veggerby + * @copyright Copyright (C) 2003, 2004 Jesper Veggerby Hansen + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 + * @version Release: @package_version@ + * @link http://pear.php.net/package/Image_Graph + */ +class Image_Graph_Dataset_Function extends Image_Graph_Dataset +{ + + /** + * The name of the function + * @var string + * @access private + */ + var $_dataFunction; + + /** + * Image_Graph_FunctionDataset [Constructor] + * + * @param double $minimumX The minimum X value + * @param double $maximumX The maximum X value + * @param string $function The name of the function, if must be a single + * parameter function like fx sin(x) or cos(x) + * @param int $points The number of points to create + */ + function Image_Graph_Dataset_Function($minimumX, $maximumX, $function, $points) + { + parent::Image_Graph_Dataset(); + $this->_minimumX = $minimumX; + $this->_maximumX = $maximumX; + $this->_dataFunction = $function; + $this->_count = $points; + $this->_calculateMaxima(); + } + + /** + * Add a point to the dataset. + * + * You can't add points to a function dataset + * + * @param int $x The X value to add + * @param int $y The Y value to add, can be omited + * @param var $ID The ID of the point + */ + function addPoint($x, $y = false, $ID = false) + { + } + + /** + * Gets a Y point from the dataset + * + * @param var $x The variable to apply the function to + * @return var The function applied to the X value + * @access private + */ + function _getPointY($x) + { + $function = $this->_dataFunction; + return $function ($x); + } + + /** + * The number of values in the dataset + * + * @return int The number of values in the dataset + * @access private + */ + function _count() + { + return $this->_count; + } + + /** + * The interval between 2 adjacent Y values + * + * @return var The interval + * @access private + */ + function _stepX() + { + return ($this->_maximumX - $this->_minimumX) / $this->_count(); + } + + /** + * Calculates the Y extrema of the function + * + * @access private + */ + function _calculateMaxima() + { + $x = $this->_minimumX; + while ($x <= $this->_maximumX) { + $y = $this->_getPointY($x); + $this->_minimumY = min($y, $this->_minimumY); + $this->_maximumY = max($y, $this->_maximumY); + $x += $this->_stepX(); + } + } + +} + +?> \ No newline at end of file -- cgit v1.2.3