Completed
Push — master ( 2b6dad...c372fe )
by WEBEWEB
01:12
created

Line::originallyOrdered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2020 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Geometry;
13
14
/**
15
 * Line.
16
 *
17
 * @author webeweb <https://github.com/webeweb>
18
 * @package WBW\Library\Core\Geometry
19
 */
20
class Line {
21
22
    /**
23
     * Point "A".
24
     *
25
     * @var Point
26
     */
27
    private $a;
28
29
    /**
30
     * Point "B".
31
     *
32
     * @var Point
33
     */
34
    private $b;
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param Point $a The point "A".
40
     * @param Point $b The point "B".
41
     */
42
    public function __construct(Point $a = null, Point $b = null) {
43
        $this->setA($a);
44
        $this->setB($b);
45
    }
46
47
    /**
48
     * Get the point "A".
49
     *
50
     * @return Point Returns the point "A".
51
     */
52
    public function getA() {
53
        return $this->a;
54
    }
55
56
    /**
57
     * Get the point "B".
58
     *
59
     * @return Point Returns the point "B".
60
     */
61
    public function getB() {
62
        return $this->b;
63
    }
64
65
    /**
66
     * Originally abscissa y = mx + b.
67
     *
68
     * @return Point Returns the originally abscissa.
69
     */
70
    public function originallyAbscissa() {
71
72
        $m = $this->getB()->m($this->getA());
73
        $b = $this->originallyOrdered()->getY();
74
75
        // x = (y - b) / m
76
        $x = (0 - $b) / $m;
77
78
        return new Point($x, 0);
79
    }
80
81
    /**
82
     * Originally ordered y = mx + b.
83
     *
84
     * @return Point Returns the originally ordered.
85
     */
86
    public function originallyOrdered() {
87
88
        $m  = $this->getB()->m($this->getA());
89
        $mx = $m * $this->getB()->getX();
90
91
        // b = y - mx
92
        $b = $this->getB()->getY() - $mx;
93
94
        return new Point(0, $b);
95
    }
96
97
    /**
98
     * Set the point "A".
99
     *
100
     * @param Point $a The point "A".
101
     * @return Line Returns this line.
102
     */
103
    public function setA(Point $a = null) {
104
        $this->a = $a;
105
        return $this;
106
    }
107
108
    /**
109
     * Set the point "B".
110
     *
111
     * @param Point $b The point "B".
112
     * @return Line Returns this line.
113
     */
114
    public function setB(Point $b = null) {
115
        $this->b = $b;
116
        return $this;
117
    }
118
}
119