Completed
Push — develop ( 8942af...2c4b35 )
by Franck
24:31
created

GeometryCalculator   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
wmc 16
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 74
ccs 38
cts 42
cp 0.9048
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
C calculateOffsets() 0 26 8
C calculateExtents() 0 29 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
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation;
19
20
/**
21
 * PhpOffice\PhpPresentation\GeometryCalculator
22
 */
23
class GeometryCalculator
24
{
25
    const X = 'X';
26
    const Y = 'Y';
27
28
    /**
29
    * Calculate X and Y offsets for a set of shapes within a container such as a slide or group.
30
    *
31
    * @param  \PhpOffice\PhpPresentation\ShapeContainerInterface $container
32
    * @return array
33
    */
34 109
    public static function calculateOffsets(ShapeContainerInterface $container)
35
    {
36 109
        $offsets = array(self::X => 0, self::Y => 0);
37
38 109
        if ($container !== null && count($container->getShapeCollection()) != 0) {
39 80
            $shapes = $container->getShapeCollection();
40 80
            if ($shapes[0] !== null) {
41 80
                $offsets[self::X] = $shapes[0]->getOffsetX();
42 80
                $offsets[self::Y] = $shapes[0]->getOffsetY();
43 80
            }
44
45 80
            foreach ($shapes as $shape) {
46 80
                if ($shape !== null) {
47 80
                    if ($shape->getOffsetX() < $offsets[self::X]) {
48
                        $offsets[self::X] = $shape->getOffsetX();
49
                    }
50
51 80
                    if ($shape->getOffsetY() < $offsets[self::Y]) {
52
                        $offsets[self::Y] = $shape->getOffsetY();
53
                    }
54 80
                }
55 80
            }
56 80
        }
57
58 109
        return $offsets;
59
    }
60
61
    /**
62
    * Calculate X and Y extents for a set of shapes within a container such as a slide or group.
63
    *
64
    * @param  \PhpOffice\PhpPresentation\ShapeContainerInterface $container
65
    * @return array
66
    */
67 109
    public static function calculateExtents(ShapeContainerInterface $container)
68
    {
69 109
        $extents = array(self::X => 0, self::Y => 0);
70
71 109
        if ($container !== null && count($container->getShapeCollection()) != 0) {
72 80
            $shapes = $container->getShapeCollection();
73 80
            if ($shapes[0] !== null) {
74 80
                $extents[self::X] = $shapes[0]->getOffsetX() + $shapes[0]->getWidth();
75 80
                $extents[self::Y] = $shapes[0]->getOffsetY() + $shapes[0]->getHeight();
76 80
            }
77
78 80
            foreach ($shapes as $shape) {
79 80
                if ($shape !== null) {
80 80
                    $extentX = $shape->getOffsetX() + $shape->getWidth();
81 80
                    $extentY = $shape->getOffsetY() + $shape->getHeight();
82
83 80
                    if ($extentX > $extents[self::X]) {
84 1
                        $extents[self::X] = $extentX;
85 1
                    }
86
87 80
                    if ($extentY > $extents[self::Y]) {
88 1
                        $extents[self::Y] = $extentY;
89 1
                    }
90 80
                }
91 80
            }
92 80
        }
93
94 109
        return $extents;
95
    }
96
}
97