RaycasterComponent::objects()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/** @formatter:off
3
 * ******************************************************************
4
 * Created by   Marko Kungla on Jul 7, 2016 - 3:52:28 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         RaycasterComponent.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\Raycaster;
25
26
use \AframeVR\Interfaces\Core\Components\RaycasterCMPTIF;
27
use \AframeVR\Core\Helpers\ComponentAbstract;
28
29
class RaycasterComponent extends ComponentAbstract implements RaycasterCMPTIF
30
{
31
32
    /**
33
     * Initialize Component
34
     *
35
     * {@inheritdoc}
36
     *
37
     * @return bool
38
     */
39 5
    public function initializeComponent(): bool
40
    {
41 5
        $this->setDomAttribute('raycaster');
42 5
        return true;
43
    }
44
45
    /**
46
     * Maximum distance
47
     *
48
     * Maximum distance under which resulting entities are returned. Cannot be lower then near.
49
     *
50
     * @param string $distance            
51
     * @return RaycasterCMPTIF
52
     */
53 3
    public function far(string $distance = 'Infinity'): RaycasterCMPTIF
54
    {
55 3
        $this->dom_attributes['far'] = $distance;
56 3
        return $this;
57
    }
58
59
    /**
60
     * Number of milliseconds
61
     *
62
     * Number of milliseconds to wait in between each intersection test. Lower number is better for faster updates.
63
     * Higher number is better for performance.
64
     *
65
     * @param int $ms            
66
     * @return RaycasterCMPTIF
67
     */
68 2
    public function interval(int $ms = 100): RaycasterCMPTIF
69
    {
70 2
        $this->dom_attributes['interval'] = $ms;
71 2
        return $this;
72
    }
73
74
    /**
75
     * Minimum distance
76
     *
77
     * Minimum distance over which resuilting entities are returned. Cannot be lower than 0.
78
     *
79
     * @param int $distance            
80
     * @return RaycasterCMPTIF
81
     */
82 1
    public function near(int $distance = 0): RaycasterCMPTIF
83
    {
84 1
        $this->dom_attributes['near'] = $distance;
85 1
        return $this;
86
    }
87
88
    /**
89
     * Query selector
90
     *
91
     * Query selector to pick which objects to test for intersection. If not specified, all entities will be tested.
92
     *
93
     * @param null|string $selector            
94
     * @return RaycasterCMPTIF
95
     */
96 1
    public function objects(string $selector = null): RaycasterCMPTIF
97
    {
98 1
        $this->dom_attributes['objects'] = $selector;
99 1
        return $this;
100
    }
101
102
    /**
103
     * Recursive
104
     *
105
     * Checks all children of objects if set. Else only checks intersections with root objects.
106
     *
107
     * @param bool $r            
108
     * @return RaycasterCMPTIF
109
     */
110 1
    public function recursive(bool $r = true): RaycasterCMPTIF
111
    {
112 1
        $this->dom_attributes['recursive'] = $r ? 'true' : 'false';
113 1
        return $this;
114
    }
115
}
116