Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
45.45% |
10 / 22 |
|
22.22% |
2 / 9 |
CRAP | |
0.00% |
0 / 1 |
Area | |
45.45% |
10 / 22 |
|
22.22% |
2 / 9 |
22.15 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
create | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
left | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
top | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
right | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
bottom | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
width | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
height | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\Core\Image; |
6 | |
7 | use Stringable; |
8 | use PeServer\Core\Code; |
9 | use PeServer\Core\Image\Point; |
10 | use PeServer\Core\Text; |
11 | |
12 | /** |
13 | * 上下左右の座標を保持。 |
14 | */ |
15 | readonly class Area implements Stringable |
16 | { |
17 | /** |
18 | * 生成 |
19 | * |
20 | * @param Point $leftTop 左上座標 |
21 | * @param Point $leftBottom 左下座標 |
22 | * @param Point $rightBottom 右下座標 |
23 | * @param Point $rightTop 右上座標 |
24 | */ |
25 | public function __construct( |
26 | public Point $leftTop, |
27 | public Point $leftBottom, |
28 | public Point $rightBottom, |
29 | public Point $rightTop |
30 | ) { |
31 | } |
32 | |
33 | #region function |
34 | |
35 | /** |
36 | * 配列から生成。 |
37 | * |
38 | * 配列の元になる以下から呼び出される前提処理。 |
39 | * |
40 | * * `Graphics::calculateTextArea` |
41 | * * `Graphics::drawString` |
42 | * |
43 | * @param int[] $areaArray |
44 | * * 0 :左下角の X 座標 |
45 | * * 1 :左下角の Y 座標 |
46 | * * 2 :右下角の X 座標 |
47 | * * 3 :右下角の Y 座標 |
48 | * * 4 :右上角の X 座標 |
49 | * * 5 :右上角の Y 座標 |
50 | * * 6 :左上角の X 座標 |
51 | * * 7 :左上角の Y 座標 |
52 | * @phpstan-param non-empty-array<int> $areaArray |
53 | * @return Area |
54 | */ |
55 | public static function create(array $areaArray): self |
56 | { |
57 | return new self( |
58 | new Point($areaArray[6], $areaArray[7]), |
59 | new Point($areaArray[0], $areaArray[1]), |
60 | new Point($areaArray[2], $areaArray[3]), |
61 | new Point($areaArray[4], $areaArray[5]), |
62 | ); |
63 | } |
64 | |
65 | /** |
66 | * 左辺のX軸を取得。 |
67 | * |
68 | * @return int |
69 | */ |
70 | public function left(): int |
71 | { |
72 | return min($this->leftTop->x, $this->leftBottom->x); |
73 | } |
74 | /** |
75 | * 上辺のY軸を取得。 |
76 | * |
77 | * @return int |
78 | */ |
79 | public function top(): int |
80 | { |
81 | return min($this->leftTop->y, $this->rightTop->y); |
82 | } |
83 | /** |
84 | * 右辺のX軸を取得。 |
85 | * |
86 | * @return int |
87 | */ |
88 | public function right(): int |
89 | { |
90 | return max($this->rightTop->x, $this->rightBottom->x); |
91 | } |
92 | /** |
93 | * 下辺のY軸を取得。 |
94 | * |
95 | * @return int |
96 | */ |
97 | public function bottom(): int |
98 | { |
99 | return max($this->leftBottom->y, $this->rightBottom->y); |
100 | } |
101 | |
102 | /** |
103 | * 幅を取得。 |
104 | * |
105 | * @return int |
106 | */ |
107 | public function width(): int |
108 | { |
109 | return $this->rightTop->x - $this->leftBottom->x; |
110 | } |
111 | /** |
112 | * 高さを取得。 |
113 | * |
114 | * @return int |
115 | */ |
116 | public function height(): int |
117 | { |
118 | return $this->leftBottom->y - $this->rightTop->y; |
119 | } |
120 | |
121 | #endregion |
122 | |
123 | #region Stringable |
124 | |
125 | public function __toString(): string |
126 | { |
127 | return Code::toString( |
128 | $this, |
129 | [ |
130 | 'leftTop', |
131 | 'leftBottom', |
132 | 'rightBottom', |
133 | 'rightTop', |
134 | ] |
135 | ); |
136 | } |
137 | |
138 | #endregion |
139 | } |