xref: /plugin/dw2pdf/vendor/setasign/fpdi/src/Math/Vector.php (revision 01d4b863f647689752623420d92bf6c538d91460) !
1<?php
2
3/**
4 * This file is part of FPDI
5 *
6 * @package   setasign\Fpdi
7 * @copyright Copyright (c) 2024 Setasign GmbH & Co. KG (https://www.setasign.com)
8 * @license   http://opensource.org/licenses/mit-license The MIT License
9 */
10
11namespace setasign\Fpdi\Math;
12
13/**
14 * A simple 2D-Vector class
15 */
16class Vector
17{
18    /**
19     * @var float
20     */
21    protected $x;
22
23    /**
24     * @var float
25     */
26    protected $y;
27
28    /**
29     * @param int|float $x
30     * @param int|float $y
31     */
32    public function __construct($x = .0, $y = .0)
33    {
34        $this->x = (float)$x;
35        $this->y = (float)$y;
36    }
37
38    /**
39     * @return float
40     */
41    public function getX()
42    {
43        return $this->x;
44    }
45
46    /**
47     * @return float
48     */
49    public function getY()
50    {
51        return $this->y;
52    }
53
54    /**
55     * @param Matrix $matrix
56     * @return Vector
57     */
58    public function multiplyWithMatrix(Matrix $matrix)
59    {
60        list($a, $b, $c, $d, $e, $f) = $matrix->getValues();
61        $x = $a * $this->x + $c * $this->y + $e;
62        $y = $b * $this->x + $d * $this->y + $f;
63
64        return new self($x, $y);
65    }
66}
67