Example #1
0
 public function testSetPosition()
 {
     $point = new Point(0, 0);
     $point->setPosition(100, 200);
     $this->assertEquals(100, $point->x);
     $this->assertEquals(200, $point->y);
 }
Example #2
0
 public function testRotate()
 {
     $point = new Point(30, 0);
     $point->rotate(90, new Point(0, 0));
     $this->assertEquals(0, $point->x);
     $this->assertEquals(30, $point->y);
     $point->rotate(90, new Point(0, 0));
     $this->assertEquals(-30, $point->x);
     $this->assertEquals(0, $point->y);
     $point = new Point(300, 200);
     $point->rotate(90, new Point(0, 0));
     $this->assertEquals(-200, $point->x);
     $this->assertEquals(300, $point->y);
 }
Example #3
0
 /**
  * Aligns current size's pivot point to given position
  * and moves point automatically by offset.
  *
  * @param  string  $position
  * @param  integer $offset_x
  * @param  integer $offset_y
  * @return \Intervention\Image\Size
  */
 public function align($position, $offset_x = 0, $offset_y = 0)
 {
     switch (strtolower($position)) {
         case 'top':
         case 'top-center':
         case 'top-middle':
         case 'center-top':
         case 'middle-top':
             $x = intval($this->width / 2);
             $y = 0 + $offset_y;
             break;
         case 'top-right':
         case 'right-top':
             $x = $this->width - $offset_x;
             $y = 0 + $offset_y;
             break;
         case 'left':
         case 'left-center':
         case 'left-middle':
         case 'center-left':
         case 'middle-left':
             $x = 0 + $offset_x;
             $y = intval($this->height / 2);
             break;
         case 'right':
         case 'right-center':
         case 'right-middle':
         case 'center-right':
         case 'middle-right':
             $x = $this->width - $offset_x;
             $y = intval($this->height / 2);
             break;
         case 'bottom-left':
         case 'left-bottom':
             $x = 0 + $offset_x;
             $y = $this->height - $offset_y;
             break;
         case 'bottom':
         case 'bottom-center':
         case 'bottom-middle':
         case 'center-bottom':
         case 'middle-bottom':
             $x = intval($this->width / 2);
             $y = $this->height - $offset_y;
             break;
         case 'bottom-right':
         case 'right-bottom':
             $x = $this->width - $offset_x;
             $y = $this->height - $offset_y;
             break;
         case 'center':
         case 'middle':
         case 'center-center':
         case 'middle-middle':
             $x = intval($this->width / 2);
             $y = intval($this->height / 2);
             break;
         default:
         case 'top-left':
         case 'left-top':
             $x = 0 + $offset_x;
             $y = 0 + $offset_y;
             break;
     }
     $this->pivot->setPosition($x, $y);
     return $this;
 }