Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
/**
4
 * This file is part of FPDI
5
 *
6
 * @package   setasign\Fpdi
7
 * @copyright Copyright (c) 2023 Setasign GmbH & Co. KG (https://www.setasign.com)
8
 * @license   http://opensource.org/licenses/mit-license The MIT License
9
 */
10
 
11
namespace setasign\Fpdi\Math;
12
 
13
/**
14
 * A simple 2D-Matrix class
15
 */
16
class Matrix
17
{
18
    /**
19
     * @var float
20
     */
21
    protected $a;
22
 
23
    /**
24
     * @var float
25
     */
26
    protected $b;
27
 
28
    /**
29
     * @var float
30
     */
31
    protected $c;
32
 
33
    /**
34
     * @var float
35
     */
36
    protected $d;
37
 
38
    /**
39
     * @var float
40
     */
41
    protected $e;
42
 
43
    /**
44
     * @var float
45
     */
46
    protected $f;
47
 
48
    /**
49
     * @param int|float $a
50
     * @param int|float $b
51
     * @param int|float $c
52
     * @param int|float $d
53
     * @param int|float $e
54
     * @param int|float $f
55
     */
56
    public function __construct($a = 1, $b = 0, $c = 0, $d = 1, $e = 0, $f = 0)
57
    {
58
        $this->a = (float)$a;
59
        $this->b = (float)$b;
60
        $this->c = (float)$c;
61
        $this->d = (float)$d;
62
        $this->e = (float)$e;
63
        $this->f = (float)$f;
64
    }
65
 
66
    /**
67
     * @return float[]
68
     */
69
    public function getValues()
70
    {
71
        return [$this->a, $this->b, $this->c, $this->d, $this->e, $this->f];
72
    }
73
 
74
    /**
75
     * @param Matrix $by
76
     * @return Matrix
77
     */
78
    public function multiply(self $by)
79
    {
80
        $a =
81
            $this->a * $by->a
82
            + $this->b * $by->c
83
            //+ 0 * $by->e
84
        ;
85
 
86
        $b =
87
            $this->a * $by->b
88
            + $this->b * $by->d
89
            //+ 0 * $by->f
90
        ;
91
 
92
        $c =
93
            $this->c * $by->a
94
            + $this->d * $by->c
95
            //+ 0 * $by->e
96
        ;
97
 
98
        $d =
99
            $this->c * $by->b
100
            + $this->d * $by->d
101
            //+ 0 * $by->f
102
        ;
103
 
104
        $e =
105
            $this->e * $by->a
106
            + $this->f * $by->c
107
            + /*1 * */$by->e;
108
 
109
        $f =
110
            $this->e * $by->b
111
            + $this->f * $by->d
112
            + /*1 * */$by->f;
113
 
114
        return new self($a, $b, $c, $d, $e, $f);
115
    }
116
}