|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Generera. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Moduler\Kluster; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Klass Generera. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Generera extends Kluster { |
|
16
|
|
|
/** |
|
17
|
|
|
* Generera rektanglar från koordinater. |
|
18
|
|
|
* @param array<int, int[]> $koordinater |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function rektanglar(array $koordinater): void { |
|
21
|
|
|
$rektanglar = []; |
|
22
|
|
|
foreach ($this->rektanglar as [$x_min, $y_min, $x_max, $y_max]) { |
|
23
|
|
|
$rektanglar[] = implode(',', [$x_min, $y_min, $x_max, $y_max]); |
|
24
|
|
|
foreach ($koordinater as $index => [$x, $y]) { |
|
25
|
|
|
if (in($x, $x_min, $x_max) && in($y, $y_min, $y_max)) { |
|
26
|
|
|
$this->klustrade_rader++; |
|
27
|
|
|
unset($koordinater[$index]); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->db_preferenser->spara_preferens('kluster.rektanglar', implode(',', $rektanglar)); |
|
33
|
|
|
$this->db_preferenser->spara_preferens('kluster.area', (string) $this->area); |
|
34
|
|
|
$this->db_preferenser->spara_preferens('kluster.antal_rader', (string) $this->antal_rader); |
|
35
|
|
|
$this->db_preferenser->spara_preferens('kluster.klustrade_rader', (string) $this->klustrade_rader); |
|
36
|
|
|
$this->graf->spara_tipsgraf($this->kombinationsgraf); |
|
37
|
|
|
$this->odds->spel->db->logg->logga(self::class . ': ✅ Fann kluster.'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Generera kluster från hämtade koordinater. |
|
42
|
|
|
* @param array<int, int[]> $koordinater |
|
43
|
|
|
* @return array<int, mixed[]> |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function generera_kluster($koordinater): array { |
|
46
|
|
|
$kluster = []; |
|
47
|
|
|
while (count($koordinater)) { |
|
48
|
|
|
$kluster[] = $this->kluster((array) array_pop($koordinater), $koordinater); |
|
49
|
|
|
} |
|
50
|
|
|
rsort($kluster); |
|
51
|
|
|
return $kluster; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|