Lines
100.00%
9 / 9
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| isHigherThan | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| isWithinAzimuth | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 4 | ||
| normalizeAzimuth | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 7 | final readonly class SunPosition | |
| 8 | { | |
| 9 | private const float FULL_TURN_DEGREES = 360.0; | |
| 10 | ||
| 11 | public function __construct( | |
| 12 | public float $azimuthDegrees, | |
| 13 | public float $elevationDegrees, | |
| 14 | ) {} | |
| 15 | ||
| 16 | public function isHigherThan(float $elevationDegrees): bool | |
| 17 | { | |
| 18 | return $this->elevationDegrees > $elevationDegrees; | |
| 19 | } | |
| 20 | ||
| 21 | public function isWithinAzimuth(float $fromDegrees, float $toDegrees): bool | |
| 22 | { | |
| 23 | $azimuth = self::normalizeAzimuth($this->azimuthDegrees); | |
| 24 | $from = self::normalizeAzimuth($fromDegrees); | |
| 25 | $to = self::normalizeAzimuth($toDegrees); | |
| 26 | ||
| 27 | if ($from <= $to) { | |
| 28 | return $azimuth >= $from && $azimuth <= $to; | |
| 29 | } | |
| 30 | ||
| 31 | return $azimuth >= $from || $azimuth <= $to; | |
| 32 | } | |
| 33 | ||
| 34 | private static function normalizeAzimuth(float $degrees): float | |
| 35 | { | |
| 36 | return $degrees - self::FULL_TURN_DEGREES * floor($degrees / self::FULL_TURN_DEGREES); | |
| 37 | } | |
| 38 | } |