Source for file Spline.php
Documentation is available at Spline.php
* <p>Title: Spline class</p>
* <p>Description: Spline smoothing.</p>
* <p>Copyright (c) 2005-2008 by Steema Software SL. All Rights
* <p>Company: Steema Software SL</p>
private $pointList= Array();
private $knuckleList= Array();
private $vertexList= Array();
* Indicates the spline has already calculated smooth points. <br>
* Set to false to force the spline to rebuild smooth points.<br>
* Indicates the spline has already calculated smooth points. <br>
* Set to false to force the spline to rebuild smooth points.<br>
// Release allocated memory for vertices
$this->clearVertexList();
private function setCapacity($value) {
if ($value != $this->capacity) {
$currentSize = $this->capacity;
$oldPoints[] = $this->pointList;
$oldKnuckle[] = $this->knuckleList;
$this->knuckleList = null;
$this->pointList[] = $value;
$this->knuckleList[] = $value;
if ($this->capacity != 0) {
$this->capacity = $value;
* The number of resulting smooth points.<br>
* Must be a multiple of source points.
* Sets the number of resulting smooth points.<br>
* Must be a multiple of source points.
if ($this->fragments != $value) {
$this->fragments = min($value, 600);
* When true, the spline calculates interpolated points that will pass
* exactly over source points.<br>
* When false, the spline resulting points do not necessarily pass over
return $this->interpolate;
* When true, the spline calculates interpolated points that will pass
* exactly over source points.<br>
* When false, the spline resulting points do not necessarily pass over
if ($value != $this->interpolate) {
$this->interpolate = $value;
return $this->pointList[$index];
* Use to set the source point for the Knuckle <br><br>
public function setPoint($index, $value) {
$this->pointList[$index] = $value;
* Makes the Index source point a control point. <br><br>
* By default, TSmoothingFunction does not set any source point <br>
private function getKnuckle($index) {
if (($index == 0) || ($index == $this->noPoints - 1)) {
return $this->knuckleList[$index];
* Makes the Index source point a control point. <br><br>
* By default, TSmoothingFunction does not set any source point <br>
$this->knuckleList[$index] = $value;
* Returns the number of total source points. <br>
* For each point that is a control point ( Knuckle[ Index ] is true ),
* the number of vertices is incremented by 2. <br>
return $this->noVertices;
private function fillMatrix() {
if (($this->noVertices > 2) && ($this->noVertices <= 250)) {
for ($i = 2; $i < $this->noVertices; $i++ ) {
$this->matrix[$i][$i - 1] = 1 / 6;
$this->matrix[$i][$i] = 2 / 3;
$this->matrix[$i][$i + 1] = 1 / 6;
// $this->matrix[$i][$i - 1] = 1f / 6f;
// $this->matrix[$i][$i] = 2f / 3f;
// $this->matrix[$i][$i + 1] = 1f / 6f;
$this->matrix[$this->noVertices][$this->noVertices] = 1;
while ($i < $this->noVertices - 1) {
if ((abs($this->vertexList[$i]->x -
$this->vertexList[$i - 1]->x) < self::$MINLIMIT) &&
(abs($this->vertexList[$i + 1]->x - $this->vertexList[$i]->x) <
(abs($this->vertexList[$i]->y - $this->vertexList[$i - 1]->y) <
(abs($this->vertexList[$i + 1]->y - $this->vertexList[$i]->y) <
for ($j = $i - 1; $j <= $i + 1; $j++ ) {
$this->matrix[$j][$j - 1] = 0;
$this->matrix[$j][$j] = 1;
$this->matrix[$j][$j + 1] = 0;
* Calculates new smoothed points from list of points.
if ($this->noPoints > 1) {
$this->clearVertexList();
for ($i = 0; $i < $this->noPoints; $i++ ) {
if ($this->getKnuckle($i)) {
$this->vertexList= Array();
//$this->vertexList[] = new TeePoint();
// $this->vertexList = new TeePoint[$this->noVertices + 2];
for ($i = 0; $i < $this->noPoints; $i++ ) {
if ($this->getKnuckle($i)) {
$this->vertexList[$j + 1] = $vertex2D;
$this->vertexList[$j + 2] = $vertex2D;
$this->vertexList[$j + 1] = $this->pointList[$i];
if ($this->interpolate) {
// $matrix = new double[noVertices + 1][];
for ($i = 1; $i <= $this->noVertices; $i++ ) {
$this->matrix[$i] = Array();
for ($tt= 0;$tt< $this->noVertices+ 1;$tt++ )
$this->matrix[$i][$tt]= 0.0;
// $this->matrix[$i] = new double[noVertices + 1];
private function doInterpolate() {
if (($this->noVertices < 250) && ($this->noVertices > 2)) {
for ($tt= 0;$tt< $this->noVertices+ 2;$tt++ )
// Point.Double[] tmp = new Point.Double[noVertices + 2];
for ($i = 1; $i <= $this->noVertices; $i++ ) {
for ($j = $i + 1; $j <= $this->noVertices; $j++ ) {
$factor = $this->matrix[$j][$i] / $this->matrix[$i][$i];
for ($k = 1; $k <= $this->noVertices; $k++ ) {
$this->matrix[$j][$k] = $this->matrix[$j][$k] - $factor * $this->matrix[$i][$k];
$this->vertexList[$j]->x = (float) ($this->vertexList[$j]->x -
$factor * $this->vertexList[$j - 1]->x);
$this->vertexList[$j]->y = (float) ($this->vertexList[$j]->y -
$factor * $this->vertexList[$j - 1]->y);
(float) ($this->vertexList[$this->noVertices]->x /
$this->matrix[$this->noVertices][$this->noVertices]),
(float) ($this->vertexList[$this->noVertices]->y /
$this->matrix[$this->noVertices][$this->noVertices]));
for ($i = $this->noVertices - 1; $i >= 1; $i-- ) {
(float) ((1 / $this->matrix[$i][$i]) *
($this->vertexList[$i]->x - $this->matrix[$i][$i +
(float) ((1 / $this->matrix[$i][$i]) *
($this->vertexList[$i]->y - $this->matrix[$i][$i +
$this->clearVertexList();
$this->vertexList = $tmp;
* Adds a new source point with specified X and Y values.
if ($this->noPoints == $this->capacity) {
$this->setCapacity($this->capacity + 25);
private function clearVertexList() {
$this->vertexList = null;
* Removes all source points.
public function clear() {
$this->clearVertexList();
$this->interpolate = false;
private function phantomPoints() {
2 * $this->vertexList[$i + 1]->x - $this->vertexList[$i + 2]->x,
2 * $this->vertexList[$i + 1]->y - $this->vertexList[$i + 2]->y);
* Returns an interpolated point.
* @param parameter double
public function value($parameter) {
if ($this->noPoints < 2) {
$s = max(0, (int) $mid - 1);
if ($s > $this->noVertices + 1) {
$s = $this->noVertices + 1;
for ($c = $s; $c <= $e; $c++ ) {
(double) $dist = abs($c - $mid);
(double) $mix = ($dist < 1) ?
(4.0 / 6.0) - ($dist * $dist) +
(0.5 * $dist * $dist * $dist) :
(2 - $dist) * (2 - $dist) * (2 - $dist) / 6;
$result->x += (float) ($this->vertexList[$c]->x * $mix);
$result->y += (float) ($this->vertexList[$c]->y * $mix);
|