Completed
Push — master ( e6cea0...5c122a )
by Marcin
01:53
created

Vector::getLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
16
namespace mrcnpdlk\Grandstream\XMLApp\Helper;
17
18
/**
19
 * Class Vector
20
 *
21
 * @package mrcnpdlk\Grandstream\XMLApp\Helper
22
 */
23
class Vector
24
{
25
    /**
26
     * @var integer
27
     */
28
    private $iX;
29
    /**
30
     * @var integer
31
     */
32
    private $iY;
33
34
    /**
35
     * Vector constructor.
36
     *
37
     * @param int $iX
38
     * @param int $iY
39
     */
40 2
    public function __construct(int $iX, int $iY)
41
    {
42 2
        $this->iX = $iX;
43 2
        $this->iY = $iY;
44 2
    }
45
46
    /**
47
     * @return float
48
     */
49 1
    public function getLength()
50
    {
51 1
        return sqrt(pow($this->getDeltaX(), 2) + pow($this->getDeltaY(), 2));
52
    }
53
54
    /**
55
     * @return int
56
     */
57 2
    public function getDeltaX()
58
    {
59 2
        return $this->iX;
60
    }
61
62
    /**
63
     * @return int
64
     */
65 2
    public function getDeltaY()
66
    {
67 2
        return $this->iY;
68
    }
69
70
    /**
71
     * @param Vector $oVector
72
     *
73
     * @return Vector
74
     */
75 1
    public function add(Vector $oVector)
76
    {
77 1
        return new Vector($this->getDeltaX() + $oVector->getDeltaX(), $this->getDeltaY() + $oVector->getDeltaY());
78
    }
79
}
80