vendor/amenadiel/jpgraph/src/image/RotImage.php line 192

  1. <?php
  2. /**
  3.  * JPGraph v4.0.3
  4.  */
  5. namespace Amenadiel\JpGraph\Image;
  6. /**
  7.  * @class RotImage
  8.  * // Description: Exactly as Image but draws the image at
  9.  * // a specified angle around a specified rotation point.
  10.  */
  11. class RotImage extends Image
  12. {
  13.     public $a      0;
  14.     public $dx     0;
  15.     public $dy     0;
  16.     public $transx 0;
  17.     public $transy 0;
  18.     private $m     = [];
  19.     public function __construct($aWidth$aHeight$a 0$aFormat DEFAULT_GFORMAT$aSetAutoMargin true)
  20.     {
  21.         parent::__construct($aWidth$aHeight$aFormat$aSetAutoMargin);
  22.         $this->dx $this->left_margin $this->plotwidth 2;
  23.         $this->dy $this->top_margin $this->plotheight 2;
  24.         $this->SetAngle($a);
  25.     }
  26.     public function SetCenter($dx$dy)
  27.     {
  28.         $old_dx   $this->dx;
  29.         $old_dy   $this->dy;
  30.         $this->dx $dx;
  31.         $this->dy $dy;
  32.         $this->SetAngle($this->a);
  33.         return [$old_dx$old_dy];
  34.     }
  35.     public function SetTranslation($dx$dy)
  36.     {
  37.         $old          = [$this->transx$this->transy];
  38.         $this->transx $dx;
  39.         $this->transy $dy;
  40.         return $old;
  41.     }
  42.     public function UpdateRotMatrice()
  43.     {
  44.         $a $this->a;
  45.         $a *= M_PI 180;
  46.         $sa sin($a);
  47.         $ca cos($a);
  48.         // Create the rotation matrix
  49.         $this->m[0][0] = $ca;
  50.         $this->m[0][1] = -$sa;
  51.         $this->m[0][2] = $this->dx * ($ca) + $sa $this->dy;
  52.         $this->m[1][0] = $sa;
  53.         $this->m[1][1] = $ca;
  54.         $this->m[1][2] = $this->dy * ($ca) - $sa $this->dx;
  55.     }
  56.     public function SetAngle($a)
  57.     {
  58.         $tmp     $this->a;
  59.         $this->$a;
  60.         $this->UpdateRotMatrice();
  61.         return $tmp;
  62.     }
  63.     public function Circle($xc$yc$r)
  64.     {
  65.         list($xc$yc) = $this->Rotate($xc$yc);
  66.         parent::Circle($xc$yc$r);
  67.     }
  68.     public function FilledCircle($xc$yc$r)
  69.     {
  70.         list($xc$yc) = $this->Rotate($xc$yc);
  71.         parent::FilledCircle($xc$yc$r);
  72.     }
  73.     public function Arc($xc$yc$w$h$s$e)
  74.     {
  75.         list($xc$yc) = $this->Rotate($xc$yc);
  76.         $s += $this->a;
  77.         $e += $this->a;
  78.         parent::Arc($xc$yc$w$h$s$e);
  79.     }
  80.     public function FilledArc($xc$yc$w$h$s$e$style '')
  81.     {
  82.         list($xc$yc) = $this->Rotate($xc$yc);
  83.         $s += $this->a;
  84.         $e += $this->a;
  85.         parent::FilledArc($xc$yc$w$h$s$e);
  86.     }
  87.     public function SetMargin($lm$rm$tm$bm)
  88.     {
  89.         parent::SetMargin($lm$rm$tm$bm);
  90.         $this->dx $this->left_margin $this->plotwidth 2;
  91.         $this->dy $this->top_margin $this->plotheight 2;
  92.         $this->UpdateRotMatrice();
  93.     }
  94.     public function Rotate($x$y)
  95.     {
  96.         // Optimization. Ignore rotation if Angle==0 || Angle==360
  97.         if ($this->== || $this->== 360) {
  98.             return [$x $this->transx$y $this->transy];
  99.         }
  100.         $x1 round($this->m[0][0] * $x $this->m[0][1] * $y1) + $this->m[0][2] + $this->transx;
  101.         $y1 round($this->m[1][0] * $x $this->m[1][1] * $y1) + $this->m[1][2] + $this->transy;
  102.         return [$x1$y1];
  103.     }
  104.     public function CopyMerge($fromImg$toX$toY$fromX$fromY$toWidth$toHeight$fromWidth = -1$fromHeight = -1$aMix 100)
  105.     {
  106.         list($toX$toY) = $this->Rotate($toX$toY);
  107.         parent::CopyMerge($fromImg$toX$toY$fromX$fromY$toWidth$toHeight$fromWidth$fromHeight$aMix);
  108.     }
  109.     public function ArrRotate($pnts)
  110.     {
  111.         $n safe_count($pnts) - 1;
  112.         for ($i 0$i $n$i += 2) {
  113.             list($x$y)  = $this->Rotate($pnts[$i], $pnts[$i 1]);
  114.             $pnts[$i]     = $x;
  115.             $pnts[$i 1] = $y;
  116.         }
  117.         return $pnts;
  118.     }
  119.     public function DashedLine($x1$y1$x2$y2$dash_length 1$dash_space 4)
  120.     {
  121.         list($x1$y1) = $this->Rotate($x1$y1);
  122.         list($x2$y2) = $this->Rotate($x2$y2);
  123.         parent::DashedLine($x1$y1$x2$y2$dash_length$dash_space);
  124.     }
  125.     public function Line($x1$y1$x2$y2)
  126.     {
  127.         list($x1$y1) = $this->Rotate($x1$y1);
  128.         list($x2$y2) = $this->Rotate($x2$y2);
  129.         parent::Line($x1$y1$x2$y2);
  130.     }
  131.     public function Rectangle($x1$y1$x2$y2)
  132.     {
  133.         // Rectangle uses Line() so it will be rotated through that call
  134.         parent::Rectangle($x1$y1$x2$y2);
  135.     }
  136.     public function FilledRectangle($x1$y1$x2$y2)
  137.     {
  138.         if ($y1 == $y2 || $x1 == $x2) {
  139.             $this->Line($x1$y1$x2$y2);
  140.         } else {
  141.             $this->FilledPolygon([$x1$y1$x2$y1$x2$y2$x1$y2]);
  142.         }
  143.     }
  144.     public function Polygon($pnts$closed false$fast false)
  145.     {
  146.         // Polygon uses Line() so it will be rotated through that call unless
  147.         // fast drawing routines are used in which case a rotate is needed
  148.         if ($fast) {
  149.             parent::Polygon($this->ArrRotate($pnts));
  150.         } else {
  151.             parent::Polygon($pnts$closed$fast);
  152.         }
  153.     }
  154.     public function FilledPolygon($pnts)
  155.     {
  156.         parent::FilledPolygon($this->ArrRotate($pnts));
  157.     }
  158.     public function Point($x$y)
  159.     {
  160.         list($xp$yp) = $this->Rotate($x$y);
  161.         parent::Point($xp$yp);
  162.     }
  163.     public function StrokeText($x$y$txt$dir 0$paragraph_align 'left'$debug false)
  164.     {
  165.         list($xp$yp) = $this->Rotate($x$y);
  166.         return parent::StrokeText($xp$yp$txt$dir$paragraph_align$debug);
  167.     }
  168. }