Side::getTopLeft()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Image\Components;
6
7
use Minepic\Image\Point;
8
9
class Side
10
{
11
    public const TOP = 'TOP';
12
    public const BOTTOM = 'BOTTOM';
13
    public const FRONT = 'FRONT';
14
    public const BACK = 'BACK';
15
    public const RIGHT = 'RIGHT';
16
    public const LEFT = 'LEFT';
17
18
    public function __construct(protected Point $topLeft, protected Point $bottomRight)
19
    {
20
    }
21
22
    public function getTopLeft(): Point
23
    {
24
        return $this->topLeft;
25
    }
26
27
    public function getBottomRight(): Point
28
    {
29
        return $this->bottomRight;
30
    }
31
32
    public function getWidth(): int
33
    {
34
        return $this->bottomRight->getX() - $this->topLeft->getX();
35
    }
36
37
    public function getHeight(): int
38
    {
39
        return $this->bottomRight->getY() - $this->topLeft->getY();
40
    }
41
42
    public static function fromRawPoints(array $rawPoints): self
43
    {
44
        return new self(
45
            new Point($rawPoints[0][0], $rawPoints[0][1]),
46
            new Point($rawPoints[1][0], $rawPoints[1][1])
47
        );
48
    }
49
}
50