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

TwoDimensionNonCurved   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 6
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
}