mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
77 lines
1.5 KiB
PHP
77 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Imagine package.
|
|
*
|
|
* (c) Bulat Shakirzyanov <mallluhuct@gmail.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Imagine\Image\Point;
|
|
|
|
use Imagine\Image\BoxInterface;
|
|
use Imagine\Image\Point as OriginalPoint;
|
|
use Imagine\Image\PointInterface;
|
|
|
|
/**
|
|
* Point center
|
|
*/
|
|
final class Center implements PointInterface
|
|
{
|
|
/**
|
|
* @var BoxInterface
|
|
*/
|
|
private $box;
|
|
|
|
/**
|
|
* Constructs coordinate with size instance, it needs to be relative to
|
|
*
|
|
* @param BoxInterface $box
|
|
*/
|
|
public function __construct(BoxInterface $box)
|
|
{
|
|
$this->box = $box;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getX()
|
|
{
|
|
return ceil($this->box->getWidth() / 2);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getY()
|
|
{
|
|
return ceil($this->box->getHeight() / 2);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function in(BoxInterface $box)
|
|
{
|
|
return $this->getX() < $box->getWidth() && $this->getY() < $box->getHeight();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function move($amount)
|
|
{
|
|
return new OriginalPoint($this->getX() + $amount, $this->getY() + $amount);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function __toString()
|
|
{
|
|
return sprintf('(%d, %d)', $this->getX(), $this->getY());
|
|
}
|
|
}
|