1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 25, 2016 - 7:51:42 PM |
5
|
|
|
* Contact [email protected] |
6
|
|
|
* @copyright 2016 Marko Kungla - https://github.com/mkungla |
7
|
|
|
* @license The MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* @category AframeVR |
10
|
|
|
* @package aframe-php |
11
|
|
|
* |
12
|
|
|
* Lang PHP (php version >= 7) |
13
|
|
|
* Encoding UTF-8 |
14
|
|
|
* File ScaleComponent.php |
15
|
|
|
* Code format PSR-2 and 12 |
16
|
|
|
* @link https://github.com/mkungla/aframe-php |
17
|
|
|
* @issues https://github.com/mkungla/aframe-php/issues |
18
|
|
|
* ******************************************************************** |
19
|
|
|
* Contributors: |
20
|
|
|
* @author Marko Kungla <[email protected]> |
21
|
|
|
* ******************************************************************** |
22
|
|
|
* Comments: |
23
|
|
|
* @formatter:on */ |
24
|
|
|
namespace AframeVR\Core\Components\Scale; |
25
|
|
|
|
26
|
|
|
use \AframeVR\Interfaces\Core\Components\ScaleCMPTIF; |
27
|
|
|
use \AframeVR\Core\Helpers\ComponentAbstract; |
28
|
|
|
use \AframeVR\Core\Helpers\ComponentHelper; |
29
|
|
|
|
30
|
|
View Code Duplication |
class ScaleComponent extends ComponentAbstract implements ScaleCMPTIF |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
use ComponentHelper; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initialize Scale Component |
36
|
|
|
* |
37
|
|
|
* The scale component defines a shrinking, stretching, or skewing transformation of an entity. |
38
|
|
|
* It takes three scaling factors for the X, Y, and Z axes. |
39
|
|
|
* |
40
|
|
|
* Scale compnent dom attribute is scale |
41
|
|
|
* |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
67 |
|
public function initializeComponent(): bool |
47
|
|
|
{ |
48
|
67 |
|
$this->setDomAttribute('scale'); |
49
|
67 |
|
return true; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Scaling factor in the X direction. |
54
|
|
|
* |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
* |
57
|
|
|
* @param double $scale_x |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
10 |
|
public function scaleX(float $scale_x) |
61
|
|
|
{ |
62
|
10 |
|
$this->setValues(); |
63
|
10 |
|
$this->dom_attributes['x'] = $scale_x; |
64
|
10 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Scaling factor in the Y direction.. |
68
|
|
|
* |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
* |
71
|
|
|
* @param double $scale_y |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
9 |
|
public function scaleY(float $scale_y) |
75
|
|
|
{ |
76
|
9 |
|
$this->setValues(); |
77
|
9 |
|
$this->dom_attributes['y'] = $scale_y; |
78
|
9 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Scaling factor in the Z direction. |
82
|
|
|
* |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
* |
85
|
|
|
* @param double $scale_z |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
9 |
|
public function scaleZ(float $scale_z) |
89
|
|
|
{ |
90
|
9 |
|
$this->setValues(); |
91
|
9 |
|
$this->dom_attributes['z'] = $scale_z; |
92
|
9 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get scale |
96
|
|
|
* |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
1 |
|
public function getScale(): string |
102
|
|
|
{ |
103
|
1 |
|
return $this->getDomAttributeString(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Return DOM attribute contents |
108
|
|
|
* |
109
|
|
|
* Scale Components dom atribute contains coordinates |
110
|
|
|
* Ex: scale="1 1 1" |
111
|
|
|
* |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
4 |
|
public function getDomAttributeString(): string |
117
|
|
|
{ |
118
|
4 |
|
$attrs = $this->getDOMAttributesArray(); |
119
|
4 |
|
return $this->createCoordinateString($attrs['x'], $attrs['y'], $attrs['z']); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* When any scale component methods are called then init others |
124
|
|
|
* |
125
|
|
|
* @param array $dom_attributes |
|
|
|
|
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
10 |
|
private function setValues() |
129
|
|
|
{ |
130
|
10 |
|
$this->dom_attributes['x'] = $this->dom_attributes['x'] ?? 0; |
131
|
10 |
|
$this->dom_attributes['y'] = $this->dom_attributes['y'] ?? 0; |
132
|
10 |
|
$this->dom_attributes['z'] = $this->dom_attributes['z'] ?? 0; |
133
|
10 |
|
} |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.