QuadTreeMask   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 52
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getBoxes() 0 4 1
A add() 0 8 1
A overlaps() 0 9 2
1
<?php
2
3
namespace SixtyNine\Cloud\Usher;
4
5
use Imagine\Image\PointInterface;
6
use SixtyNine\Cloud\Factory\Logger;
7
use SixtyNine\DataTypes\Box;
8
use SixtyNine\DataTypes\QuadTree;
9
10
class QuadTreeMask implements MaskInterface
11
{
12
    /** @var QuadTree */
13
    protected $tree;
14
    /** @var \SixtyNine\Cloud\Factory\Logger */
15
    protected $logger;
16
17
    /**
18
     * @param int $width
19
     * @param int $height
20
     */
21 6
    public function __construct($width, $height)
22
    {
23 6
        $this->logger = Logger::getInstance();
24 6
        $this->tree = new QuadTree(new Box(0, 0, $width, $height));
25 6
    }
26
27
    /**
28
     * @return array
29
     */
30 2
    public function getBoxes()
31
    {
32 2
        return $this->tree->getAllObjects();
33
    }
34
35
    /**
36
     * @param \Imagine\Image\PointInterface $position
37
     * @param Box $box
38
     */
39 6
    public function add(PointInterface $position, Box $box)
40
    {
41 6
        $box = $box->move($position->getX(), $position->getY());
42
43 6
        $this->logger->log('  Box added to mask ' . $box, Logger::DEBUG);
44
45 6
        $this->tree->insert($box);
46 6
    }
47
48
    /**
49
     * @param Box $box
50
     * @return bool
51
     */
52 6
    public function overlaps(Box $box)
53
    {
54 6
        $collides = $this->tree->collides($box);
55 6
        $this->logger->log(sprintf(
56 6
            '  Overlap test %s --> %s', $box, $collides ? 'COLLISION' : 'NO COLLISION'
57 6
        ), Logger::DEBUG);
58
59 6
        return $collides;
60
    }
61
}
62