Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Matrix
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 multiply
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 transpose
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 quaternionToRotation
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\GLTFHandler\Parser;
4
5use function array_fill;
6
7final class Matrix {
8
9    public const IDENTITY4 = [
10        1, 0, 0, 0,
11        0, 1, 0, 0,
12        0, 0, 1, 0,
13        0, 0, 0, 1
14    ];
15
16    public static function multiply( array $matrix1, array $matrix2, int $size ): array {
17        $result = array_fill( 0, $size * $size, 0 );
18        for ( $row = 0; $row < $size; $row++ ) {
19            for ( $col = 0; $col < $size; $col++ ) {
20                for ( $k = 0; $k < $size; $k++ ) {
21                    $result[$row * $size + $col] += $matrix1[$row * $size + $k] * $matrix2[$k * $size + $col];
22                }
23            }
24        }
25        return $result;
26    }
27
28    public static function transpose( array $matrix, int $size = 4 ): array {
29        $result = [];
30        for ( $i = 0; $i < $size; $i++ ) {
31            for ( $j = 0; $j < $size; $j++ ) {
32                $result[$i * $size + $j] = $matrix[$j * $size + $i];
33            }
34        }
35        return $result;
36    }
37
38    public static function quaternionToRotation( array $matrix ): array {
39        [ $x, $y, $z, $w ] = $matrix;
40        return [
41            1 - 2 * ( $y * $y + $z * $z ), 2 * ( $x * $y - $z * $w ), 2 * ( $x * $z + $y * $w ), 0,
42            2 * ( $x * $y + $z * $w ), 1 - 2 * ( $x * $x + $z * $z ), 2 * ( $y * $z - $x * $w ), 0,
43            2 * ( $x * $z - $y * $w ), 2 * ( $y * $z + $x * $w ), 1 - 2 * ( $x * $x + $y * $y ), 0,
44            0, 0, 0, 1
45        ];
46    }
47
48    private function __construct() {
49    }
50}