xref: /webtrees/app/Report/ReportBaseLine.php (revision bb88f16b1377db732afb12b8b709b3f5f899347a)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Report;
21
22use function abs;
23
24/**
25 * Class ReportBaseLine
26 */
27class ReportBaseLine extends ReportBaseElement
28{
29    /**
30     * Start horizontal position, current position (default)
31     *
32     * @var float
33     */
34    public $x1 = ReportBaseElement::CURRENT_POSITION;
35    /**
36     * Start vertical position, current position (default)
37     *
38     * @var float
39     */
40    public $y1 = ReportBaseElement::CURRENT_POSITION;
41    /**
42     * End horizontal position, maximum width (default)
43     *
44     * @var float
45     */
46    public $x2 = ReportBaseElement::CURRENT_POSITION;
47    /**
48     * End vertical position
49     *
50     * @var float
51     */
52    public $y2 = ReportBaseElement::CURRENT_POSITION;
53
54    /**
55     * Create a line class - Base
56     *
57     * @param mixed $x1
58     * @param mixed $y1
59     * @param mixed $x2
60     * @param mixed $y2
61     */
62    public function __construct($x1, $y1, $x2, $y2)
63    {
64        $this->x1 = $x1;
65        $this->y1 = $y1;
66        $this->x2 = $x2;
67        $this->y2 = $y2;
68    }
69
70    /**
71     * Get the height of the line.
72     *
73     * @param HtmlRenderer|PdfRenderer $renderer
74     *
75     * @return float
76     */
77    public function getHeight($renderer): float
78    {
79        return abs($this->y2 - $this->y1);
80    }
81
82    /**
83     * Get the width of the line.
84     *
85     * @param HtmlRenderer|PdfRenderer $renderer
86     *
87     * @return float|array
88     */
89    public function getWidth($renderer)
90    {
91        return abs($this->x2 - $this->x1);
92    }
93}
94