Line::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the CGI-Calc package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cgi\Calc\Point;
13
14
use Cgi\Calc\Func\LinearFunction;
15
use Cgi\Calc\Point;
16
17
class Line
18
{
19
    /** @var Point */
20
    private $startPoint;
21
22
    /** @var Point */
23
    private $endPoint;
24
25
    /**
26
     * @param Point $startPoint
27
     * @param Point $endPoint
28
     */
29
    public function __construct(Point $startPoint, Point $endPoint)
30
    {
31
        $this->startPoint = $startPoint;
32
        $this->endPoint = $endPoint;
33
    }
34
35
    /**
36
     * @param Point $a
37
     * @param Point $b
38
     *
39
     * @return Line
40
     */
41
    public static function combineToRisingLine(Point $a, Point $b)
42
    {
43
        $minX = min($a->getX(), $b->getX());
44
        $maxX = max($a->getX(), $b->getX());
45
        $minY = min($a->getY(), $b->getY());
46
        $maxY = max($a->getY(), $b->getY());
47
48
        return new self(new Point($minX, $minY), new Point($maxX, $maxY));
49
    }
50
51
    /**
52
     * @return Point
53
     */
54
    public function getStartPoint()
55
    {
56
        return $this->startPoint;
57
    }
58
59
    /**
60
     * @return Point
61
     */
62
    public function getEndPoint()
63
    {
64
        return $this->endPoint;
65
    }
66
67
    /**
68
     * @return LinearFunction
69
     */
70
    public function getLinearFunction()
71
    {
72
        return LinearFunction::fromTwoPoints($this->startPoint, $this->endPoint);
73
    }
74
}
75