Specification   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 146
rs 10
c 0
b 0
f 0
wmc 17

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setPattern() 0 7 3
A getSize() 0 6 4
A __construct() 0 10 2
A getLayout() 0 3 1
A setLayout() 0 5 1
A setType() 0 4 1
A getType() 0 3 1
A setTileSize() 0 5 1
A getTileSize() 0 3 1
A computeSize() 0 5 1
A getPattern() 0 3 1
1
<?php
2
3
namespace AmaTeam\Image\Projection;
4
5
use AmaTeam\Image\Projection\API\SpecificationInterface;
6
use AmaTeam\Image\Projection\Filesystem\Pattern;
7
use AmaTeam\Image\Projection\Geometry\Box;
8
9
/**
10
 * Specification describes single projection: it's type, path (pattern) and
11
 * sizes (tile size, overall size, number of tiles in face row and column).
12
 */
13
class Specification implements SpecificationInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $type;
19
20
    /**
21
     * Projection path (if applicable).
22
     *
23
     * @var Pattern
24
     */
25
    private $pattern;
26
27
    /**
28
     * Width and height of single tile in pixels (texels?)
29
     *
30
     * @var Box
31
     */
32
    private $tileSize;
33
34
    /**
35
     * Projection face layout: number of tiles in row and column.
36
     *
37
     * @var Box
38
     */
39
    private $layout;
40
41
    /**
42
     * Overall size of single face (basically tileSize x layout)
43
     *
44
     * @var Box
45
     */
46
    private $size;
47
48
    /**
49
     * @param string|null $type
50
     * @param string|null $pattern
51
     * @param Box|null $tileSize
52
     * @param Box|null $layout
53
     */
54
    public function __construct(
55
        $type = null,
56
        $pattern = null,
57
        $tileSize = null,
58
        $layout = null
59
    ) {
60
        $this->type = $type;
61
        $this->setPattern($pattern);
62
        $this->tileSize = $tileSize;
63
        $this->layout = $layout ?: new Box(1, 1);
64
    }
65
    
66
    /**
67
     * @return string
68
     */
69
    public function getType()
70
    {
71
        return $this->type;
72
    }
73
74
    /**
75
     * @param string $type
76
     * @return $this
77
     */
78
    public function setType($type)
79
    {
80
        $this->type = $type;
81
        return $this;
82
    }
83
84
    /**
85
     * @return Pattern
86
     */
87
    public function getPattern()
88
    {
89
        return $this->pattern;
90
    }
91
92
    /**
93
     * @param string|Pattern $pattern
94
     * @return $this
95
     */
96
    public function setPattern($pattern)
97
    {
98
        if ($pattern !== null && !($pattern instanceof Pattern)) {
99
            $pattern = new Pattern($pattern);
100
        }
101
        $this->pattern = $pattern;
102
        return $this;
103
    }
104
105
    /**
106
     * @return Box
107
     */
108
    public function getLayout()
109
    {
110
        return $this->layout;
111
    }
112
113
    /**
114
     * @param Box $layout
115
     * @return $this
116
     */
117
    public function setLayout(Box $layout)
118
    {
119
        $this->layout = $layout;
120
        $this->size = null;
121
        return $this;
122
    }
123
124
    /**
125
     * @return Box
126
     */
127
    public function getTileSize()
128
    {
129
        return $this->tileSize;
130
    }
131
132
    /**
133
     * @param Box $tileSize
134
     * @return $this
135
     */
136
    public function setTileSize(Box $tileSize)
137
    {
138
        $this->tileSize = $tileSize;
139
        $this->size = null;
140
        return $this;
141
    }
142
143
    /**
144
     * @return Box
145
     */
146
    public function getSize()
147
    {
148
        if (!$this->size && $this->layout && $this->tileSize) {
149
            $this->size = self::computeSize($this->layout, $this->tileSize);
150
        }
151
        return $this->size;
152
    }
153
154
    private static function computeSize(Box $layout, Box $tileSize)
155
    {
156
        return new Box(
157
            $layout->getWidth() * $tileSize->getWidth(),
158
            $layout->getHeight() * $tileSize->getHeight()
159
        );
160
    }
161
}
162