Skip to content

Commit

Permalink
Add missing offset calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Oct 21, 2023
1 parent 00d53e2 commit fb161a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Geometry/Rectangle.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0
case 'top-middle':
case 'center-top':
case 'middle-top':
$x = intval($this->getWidth() / 2);
$x = intval($this->getWidth() / 2) + $offset_x;
$y = 0 + $offset_y;
break;

Expand All @@ -107,7 +107,7 @@ public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0
case 'center-left':
case 'middle-left':
$x = 0 + $offset_x;
$y = intval($this->getHeight() / 2);
$y = intval($this->getHeight() / 2) + $offset_y;
break;

case 'right':
Expand All @@ -116,7 +116,7 @@ public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0
case 'center-right':
case 'middle-right':
$x = $this->getWidth() - $offset_x;
$y = intval($this->getHeight() / 2);
$y = intval($this->getHeight() / 2) + $offset_y;
break;

case 'bottom-left':
Expand All @@ -130,7 +130,7 @@ public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0
case 'bottom-middle':
case 'center-bottom':
case 'middle-bottom':
$x = intval($this->getWidth() / 2);
$x = intval($this->getWidth() / 2) + $offset_x;
$y = $this->getHeight() - $offset_y;
break;

Expand Down
8 changes: 4 additions & 4 deletions tests/Geometry/RectangleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testAlignPivot(): void
$this->assertEquals(3, $box->getPivot()->getY());

$box->movePivot('top', 3, 3);
$this->assertEquals(320, $box->getPivot()->getX());
$this->assertEquals(323, $box->getPivot()->getX());
$this->assertEquals(3, $box->getPivot()->getY());

$box->movePivot('top-right', 3, 3);
Expand All @@ -145,22 +145,22 @@ public function testAlignPivot(): void

$box->movePivot('left', 3, 3);
$this->assertEquals(3, $box->getPivot()->getX());
$this->assertEquals(240, $box->getPivot()->getY());
$this->assertEquals(243, $box->getPivot()->getY());

$box->movePivot('center', 3, 3);
$this->assertEquals(323, $box->getPivot()->getX());
$this->assertEquals(243, $box->getPivot()->getY());

$box->movePivot('right', 3, 3);
$this->assertEquals(637, $box->getPivot()->getX());
$this->assertEquals(240, $box->getPivot()->getY());
$this->assertEquals(243, $box->getPivot()->getY());

$box->movePivot('bottom-left', 3, 3);
$this->assertEquals(3, $box->getPivot()->getX());
$this->assertEquals(477, $box->getPivot()->getY());

$box->movePivot('bottom', 3, 3);
$this->assertEquals(320, $box->getPivot()->getX());
$this->assertEquals(323, $box->getPivot()->getX());
$this->assertEquals(477, $box->getPivot()->getY());

$result = $box->movePivot('bottom-right', 3, 3);
Expand Down

0 comments on commit fb161a9

Please sign in to comment.