This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ class Transform { private $xx; private $xy; private $yx; private $yy; private $dx; private $dy; public function __construct() { $this->xx = 1; $this->xy = 0; $this->yx = 0; $this->yy = 1; $this->dx = 0; $this->dy = 0; } public function setFullMatrix($newXx, $newXy, $newYx, $newYy, $newDx, $newDy) { $this->xx = $newXx; $this->xy = $newXy; $this->yx = $newYx; $this->yy = $newYy; $this->dx = $newDx; $this->dy = $newDy; } public function getXx() { return $this->xx; } public function getXy() { return $this->xy; } public function getYx() { return $this->yx; } public function getYy() { return $this->yy; } public function getDx() { return $this->dx; } public function getDy() { return $this->dy; } public function setXx($x) { $this->xx = $x; } public function setXy($x) { $this->xy = $x; } public function setYx($x) { $this->yx = $x; } public function setYy($x) { $this->yy = $x; } public function setDx($x) { $this->dx = $x; } public function setDy($x) { $this->dy = $x; } public function setTranslate($newDx, $newDy = 0) { $this->setFullMatrix(1,0,0,1,$newDx, $newDy); } public function setScale($scaleX, $scaleY = -1) { if ($scaleY == -1) $scaleY = $scaleX; $this->setFullMatrix($scaleX, 0, 0, $scaleY, 0, 0); } public function setRotate($angle) { $this->setFullMatrix(cos(deg2rad($angle)), sin(deg2rad($angle)), -sin(deg2rad($angle)), cos(deg2rad($angle)), 0, 0); } public function setSkewX($angle) { $this->setFullMatrix(1, 0, tan(deg2rad($angle)), 1, 0, 0); } public function setSkewY($angle) { $this->setFullMatrix(1, tan(deg2rad($angle)), 0, 1, 0, 0); } public function applyToX($x, $y) { return $this->xx * $x + $this->xy * $y + $this->dx; } public function applyToY($x, $y) { return $this->yx * $x + $this->yy * $y + $this->dy; } //does multiplication of the form [$this]*[$other] //and stores the result in $this public function multiplyBy($other) { $xx = ($this->xx*$other->xx + $this->xy*$other->yx); $xy = ($this->xx*$other->xy + $this->xy*$other->yy); $dx = ($this->xx*$other->dx + $this->xy*$other->dy + $this->dx); $yx = ($this->yx*$other->xx + $this->yy*$other->yx); $yy = ($this->yx*$other->xy + $this->yy*$other->yy); $dy = ($this->yx*$other->yx + $this->yy*$other->dy + $this->dy); $this->setFullMatrix($xx, $xy, $yx, $yy, $dx, $dy); } public function isIdentity() { return ($this->xx == 1 && $this->xy == 0 && $this->yx == 0 && $this->yy == 1 && $this->dx == 0 && $this->dy == 0); } } ?>