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

TwoDimensionNonCurved::__construct()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
rs 8.5906
cc 6
eloc 12
nc 10
nop 1
1
<?php
2
3
namespace Samsara\Fermat\Shapes\Base;
4
5
use Ds\Map;
6
use Ds\Set;
7
use Samsara\Fermat\Values\CartesianCoordinate;
8
9
class TwoDimensionNonCurved
10
{
11
    private $lines;
12
13
    private $points;
14
15
    private $linesByPoint;
16
17
    public function __construct(Line ...$lines)
18
    {
19
        $this->lines = new Set($lines);
20
        $this->points = new Set();
21
        $this->linesByPoint = new Map();
22
23
        foreach ($lines as $line) {
24
            /** @var CartesianCoordinate $point */
25
            foreach ($line->pointsIterator() as $point) {
26
                if (!$this->points->contains($point)) {
27
                    $this->points->add($point);
28
                }
29
30
                if (!$this->linesByPoint->hasKey($point)) {
31
                    $this->linesByPoint->put($point, new Set());
32
                }
33
34
                if (!$this->linesByPoint->get($point)->contains($line)) {
35
                    $this->linesByPoint->get($point)->add($line);
36
                }
37
            }
38
        }
39
    }
40
41
}