Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
26 / 28 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
GeometryCalculator | |
92.86% |
26 / 28 |
|
50.00% |
1 / 2 |
16.09 | |
0.00% |
0 / 1 |
calculateOffsets | |
84.62% |
11 / 13 |
|
0.00% |
0 / 1 |
8.23 | |||
calculateExtents | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
8 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
4 | * presentations documents. |
5 | * |
6 | * PHPPresentation is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation; |
21 | |
22 | /** |
23 | * PhpOffice\PhpPresentation\GeometryCalculator. |
24 | */ |
25 | class GeometryCalculator |
26 | { |
27 | public const X = 'X'; |
28 | public const Y = 'Y'; |
29 | |
30 | /** |
31 | * Calculate X and Y offsets for a set of shapes within a container such as a slide or group. |
32 | * |
33 | * @return array<string, int> |
34 | */ |
35 | public static function calculateOffsets(ShapeContainerInterface $container): array |
36 | { |
37 | $offsets = [self::X => 0, self::Y => 0]; |
38 | |
39 | if (null !== $container && 0 != count($container->getShapeCollection())) { |
40 | $shapes = $container->getShapeCollection(); |
41 | if (null !== $shapes[0]) { |
42 | $offsets[self::X] = $shapes[0]->getOffsetX(); |
43 | $offsets[self::Y] = $shapes[0]->getOffsetY(); |
44 | } |
45 | |
46 | foreach ($shapes as $shape) { |
47 | if (null !== $shape) { |
48 | if ($shape->getOffsetX() < $offsets[self::X]) { |
49 | $offsets[self::X] = $shape->getOffsetX(); |
50 | } |
51 | |
52 | if ($shape->getOffsetY() < $offsets[self::Y]) { |
53 | $offsets[self::Y] = $shape->getOffsetY(); |
54 | } |
55 | } |
56 | } |
57 | } |
58 | |
59 | return $offsets; |
60 | } |
61 | |
62 | /** |
63 | * Calculate X and Y extents for a set of shapes within a container such as a slide or group. |
64 | * |
65 | * @return array<string, int> |
66 | */ |
67 | public static function calculateExtents(ShapeContainerInterface $container): array |
68 | { |
69 | /** @var array<string, int> $extents */ |
70 | $extents = [self::X => 0, self::Y => 0]; |
71 | |
72 | if (null !== $container && 0 != count($container->getShapeCollection())) { |
73 | $shapes = $container->getShapeCollection(); |
74 | if (null !== $shapes[0]) { |
75 | $extents[self::X] = (int) ($shapes[0]->getOffsetX() + $shapes[0]->getWidth()); |
76 | $extents[self::Y] = (int) ($shapes[0]->getOffsetY() + $shapes[0]->getHeight()); |
77 | } |
78 | |
79 | foreach ($shapes as $shape) { |
80 | if (null !== $shape) { |
81 | $extentX = (int) ($shape->getOffsetX() + $shape->getWidth()); |
82 | $extentY = (int) ($shape->getOffsetY() + $shape->getHeight()); |
83 | |
84 | if ($extentX > $extents[self::X]) { |
85 | $extents[self::X] = $extentX; |
86 | } |
87 | |
88 | if ($extentY > $extents[self::Y]) { |
89 | $extents[self::Y] = $extentY; |
90 | } |
91 | } |
92 | } |
93 | } |
94 | |
95 | return $extents; |
96 | } |
97 | } |