EuclideanDistance::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Undemanding\Difference\Method;
4
5
class EuclideanDistance
6
{
7
    /**
8
     * RGB color distance for the same pixel in two images.
9
     *
10
     * @link https://en.wikipedia.org/wiki/Euclidean_distance
11
     *
12
     * @param array $p
13
     * @param array $q
14
     *
15
     * @return float
16
     */
17 1
    public function __invoke(array $p, array $q)
18
    {
19 1
        $r = $p["r"] - $q["r"];
20 1
        $r *= $r;
21
22 1
        $g = $p["g"] - $q["g"];
23 1
        $g *= $g;
24
25 1
        $b = $p["b"] - $q["b"];
26 1
        $b *= $b;
27
28 1
        return (float) sqrt($r + $g + $b);
29
    }
30
}
31