xref: /webtrees/app/Report/ReportBaseLine.php (revision 728c8c2714cc197d45bad7363eb52e0bff3297bb)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 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 <https://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    // Start horizontal position, current position (default)
30    public float $x1 = ReportBaseElement::CURRENT_POSITION;
31
32    // Start vertical position, current position (default)
33    public float $y1 = ReportBaseElement::CURRENT_POSITION;
34
35    // End horizontal position, maximum width (default)
36    public float $x2 = ReportBaseElement::CURRENT_POSITION;
37
38    // End vertical position
39    public float $y2 = ReportBaseElement::CURRENT_POSITION;
40
41    /**
42     * Create a line class - Base
43     *
44     * @param float $x1
45     * @param float $y1
46     * @param float $x2
47     * @param float $y2
48     */
49    public function __construct(float $x1, float $y1, float $x2, float $y2)
50    {
51        $this->x1 = $x1;
52        $this->y1 = $y1;
53        $this->x2 = $x2;
54        $this->y2 = $y2;
55    }
56
57    /**
58     * Get the height of the line.
59     *
60     * @param HtmlRenderer|PdfRenderer $renderer
61     *
62     * @return float
63     */
64    public function getHeight($renderer): float
65    {
66        return abs($this->y2 - $this->y1);
67    }
68
69    /**
70     * Get the width of the line.
71     *
72     * @param HtmlRenderer|PdfRenderer $renderer
73     *
74     * @return array{0:float,1:int,2:float}
75     */
76    public function getWidth($renderer): array
77    {
78        return [abs($this->x2 - $this->x1), 1, $this->getHeight($renderer)];
79    }
80}
81