1
|
|
|
<?php |
2
|
|
|
/** @formatter:off |
3
|
|
|
* ****************************************************************** |
4
|
|
|
* Created by Marko Kungla on Jun 27, 2016 - 2:54:40 AM |
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 DefaultMethods.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\Position\Methods; |
25
|
|
|
|
26
|
|
|
class DefaultMethods |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* When any position component methods are called then init others |
30
|
|
|
* |
31
|
|
|
* @param array $dom_attributes |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
15 |
|
private function init(array &$dom_attributes) |
35
|
|
|
{ |
36
|
15 |
|
$dom_attributes['x'] = $dom_attributes['x'] ?? 0; |
37
|
15 |
|
$dom_attributes['y'] = $dom_attributes['y'] ?? 0; |
38
|
15 |
|
$dom_attributes['z'] = $dom_attributes['z'] ?? 0; |
39
|
15 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Negative X axis extends left. |
43
|
|
|
* Positive X Axis extends right. |
44
|
|
|
* |
45
|
|
|
* @param array $dom_attributes |
46
|
|
|
* @param double $x_axis |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
15 |
|
public function positionX(array &$dom_attributes, float $x_axis) |
50
|
|
|
{ |
51
|
15 |
|
$this->init($dom_attributes); |
52
|
15 |
|
$dom_attributes['x'] = $x_axis; |
53
|
15 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Negative Y axis extends up. |
57
|
|
|
* Positive Y Axis extends down. |
58
|
|
|
* |
59
|
|
|
* @param array $dom_attributes |
60
|
|
|
* @param double $y_axis |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
14 |
|
public function positionY(array &$dom_attributes, float $y_axis) |
64
|
|
|
{ |
65
|
14 |
|
$this->init($dom_attributes); |
66
|
14 |
|
$dom_attributes['y'] = $y_axis; |
67
|
14 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Negative Z axis extends in. |
71
|
|
|
* Positive Z Axis extends out. |
72
|
|
|
* |
73
|
|
|
* @param array $dom_attributes |
74
|
|
|
* @param double $z_axis |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
14 |
|
public function positionZ(array &$dom_attributes, float $z_axis) |
78
|
|
|
{ |
79
|
14 |
|
$this->init($dom_attributes); |
80
|
14 |
|
$dom_attributes['z'] = $z_axis; |
81
|
14 |
|
} |
82
|
|
|
} |
83
|
|
|
|
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.