Completed
Push — dev ( 80a148...4ac9b0 )
by Jordan
03:47
created

Line::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Samsara\Fermat\Shapes\Base;
4
5
use Ds\Set;
6
use Samsara\Fermat\Values\CartesianCoordinate;
7
use Samsara\Fermat\Values\ImmutableNumber;
8
9
class Line
10
{
11
12
    /**
13
     * @var ImmutableNumber
14
     */
15
    private $length;
16
17
    /**
18
     * @var Set
19
     */
20
    private $points;
21
22
    public function __construct(CartesianCoordinate $coordinate1, CartesianCoordinate $coordinate2)
23
    {
24
        $this->points = new Set();
25
        $this->points->add($coordinate1);
26
        $this->points->add($coordinate2);
27
        $this->length = $coordinate1->distanceTo($coordinate2);
28
    }
29
30
    public function length()
31
    {
32
        return $this->length;
33
    }
34
35
    public function points()
36
    {
37
        return $this->points->toArray();
38
    }
39
40
    public function pointsIterator()
41
    {
42
        return $this->points->getIterator();
43
    }
44
45
}