Completed
Push — dev ( 021c9f...a2bcd2 )
by Jordan
02:02
created

TwoDimensionNonCurved   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 33 8
A isClosed() 0 4 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
    /** @var Set  */
12
    private $lines;
13
14
    /** @var Set  */
15
    private $points;
16
17
    /** @var Map  */
18
    private $linesByPoint;
19
20
    /** @var bool */
21
    private $closed;
22
23
    public function __construct(Line ...$lines)
24
    {
25
        $this->lines = new Set($lines);
26
        $this->points = new Set();
27
        $this->linesByPoint = new Map();
28
29
        foreach ($lines as $line) {
30
            /** @var CartesianCoordinate $point */
31
            foreach ($line->pointsIterator() as $point) {
32
                if (!$this->points->contains($point)) {
33
                    $this->points->add($point);
34
                }
35
36
                if (!$this->linesByPoint->hasKey($point)) {
37
                    $this->linesByPoint->put($point, new Set());
38
                }
39
40
                if (!$this->linesByPoint->get($point)->contains($line)) {
41
                    $this->linesByPoint->get($point)->add($line);
42
                }
43
            }
44
        }
45
46
        $this->closed = true;
47
48
        /** @var Set $pointLines */
49
        foreach ($this->linesByPoint as $pointLines) {
50
            if ($pointLines->count() < 2) {
51
                $this->closed = false;
52
                break;
53
            }
54
        }
55
    }
56
57
    public function isClosed()
58
    {
59
        return $this->closed;
60
    }
61
62
}