diff --git a/composer.json b/composer.json index 25f3f7e..58db18d 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "ext-memcached": "*", "ext-bcmath": "*", "ext-sockets": "*", - "ext-pdo": "*" + "ext-pdo": "*", + "poseidon2/math": "^1.0" } } diff --git a/composer.lock b/composer.lock index cb5cc10..82581a1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,54 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "de6611697421c8a1e0cd2c91771606ea", - "packages": [], + "content-hash": "65b1980d0c89fecdd433059df4035310", + "packages": [ + { + "name": "poseidon2/math", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/FrankMarkwort/Math.git", + "reference": "70999367939f953b9fe640799ee482d16b0cd920" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FrankMarkwort/Math/zipball/70999367939f953b9fe640799ee482d16b0cd920", + "reference": "70999367939f953b9fe640799ee482d16b0cd920", + "shasum": "" + }, + "require": { + "ext-bcmath": "*", + "php": ">= 8.3" + }, + "require-dev": { + "phpunit/phpunit": "^11.3.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Math\\": "src/Math/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Frank Markwort", + "email": "frank.markwort@gmail.com", + "role": "Developer" + } + ], + "description": "Math-Vector library", + "support": { + "issues": "https://github.com/FrankMarkwort/Math/issues", + "source": "https://github.com/FrankMarkwort/Math/tree/1.0.3" + }, + "time": "2024-09-18T22:53:05+00:00" + } + ], "packages-dev": [ { "name": "myclabs/deep-copy", @@ -1654,5 +1700,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Core/Math/AbstractAngleRad.php b/src/Core/Math/AbstractAngleRad.php deleted file mode 100644 index 4c5d1bb..0000000 --- a/src/Core/Math/AbstractAngleRad.php +++ /dev/null @@ -1,121 +0,0 @@ -omega = $omega; - - return $this; - } - - public function getOmega(EnumRange $range = EnumRange::G360): float - { - return $this->getRadInRange($this->omega, $range); - } - - protected function getRadInRange(float $rad, EnumRange $range = EnumRange::G360): float - { - if ($range === EnumRange::G180) { - - return $this->getRad180($rad); - } - - return $this->getRad360($rad); - } - protected function getRad360(float $rad):float - { - - if ($this->isEquals2PiOrZero($rad)) { - - return 0; - - } elseif ($rad > 2 * pi()) { - - return fmod($rad, 2 * pi()) ; - - } elseif ($rad < 0) { - - return 2 * pi() + fmod($rad, 2 * pi()) ; - } - - return $rad; - } - - protected function getRad180(float $rad):float - { - if ($this->isEquals2PiOrZero($rad)) { - - return 0; - - } elseif ($this->isEqualsPi($rad)) { - - return pi(); - - } elseif ($this->isBetween0AndPi($rad)) { - - return $rad; - - } elseif ($rad > 2 * pi()) { - - return fmod($rad, 2 * pi()); - - } elseif ($this->isBetween0And2Pi($rad)) { - - return (2 * pi() - fmod($rad, 2 * pi())) * (-1); - - } elseif ($rad > -pi() && $rad < 0 ) { - - return fmod($rad, pi()); - - } elseif ($rad < -2 * pi() && $rad < -pi() ) { - if ($this->isEqualsPi(abs(fmod($rad, 2 * pi())))) - { - return abs(fmod($rad, 2 * pi())); - - } else { - - return fmod($rad, 2 * pi()); - } - } elseif ($rad < -pi() && $rad > - 2 * pi()) { - - return abs(fmod($rad, pi())); - } - - return $rad; - } - - protected function isBetween0And2Pi(float $rad):bool - { - return $rad > 0 && $rad < 2 * pi(); - } - - protected function isBetween0AndPi(float $rad):bool - { - return $rad > 0 && $rad < pi(); - } - - protected function isEqualsPi(float $rad): bool - { - return $this->isEqualsWithDelta(abs($rad), pi()); - } - - protected function isEquals2PiOrZero(float $rad): bool - { - return ($this->isEqualsWithDelta(abs($rad),2 * pi()) || $this->isEqualsWithDelta(abs($rad),0)); - } - - protected function isEqualsWithDelta(float $number1, float $number2 , float $delta = self::DELTA): bool - { - return abs($number1 - $number2) < $delta; - } - - abstract public function rotate(float $rad):self; -} diff --git a/src/Core/Math/EnumRange.php b/src/Core/Math/EnumRange.php deleted file mode 100644 index c4e6bc0..0000000 --- a/src/Core/Math/EnumRange.php +++ /dev/null @@ -1,10 +0,0 @@ -getOmega($range)); - } - - /** - * @throws Exception - */ - public function rotate(float $rad): Rad - { - throw new Exception('not implemented'); - } -} diff --git a/src/Core/Math/Vector/Operator.php b/src/Core/Math/Vector/Operator.php deleted file mode 100644 index de0a167..0000000 --- a/src/Core/Math/Vector/Operator.php +++ /dev/null @@ -1,10 +0,0 @@ -r; - } - - public function setR(float $r): PolarVector - { - $this->r = $r; - - return $this; - } - - public function againstVector( bool $clone = false):PolarVector - { - return $this->rotate(pi(), $clone); - } - - public function rotate(float $rad , bool $clone = false): PolarVector - { - $r = $this->getR(); - $omega = $this->getOmega(); - $x = $r * cos( $omega ) * cos($rad) - $r * sin( $omega ) * sin($rad); - $y = $r * cos( $omega ) * sin($rad) + $r * sin($omega) * cos($rad); - $newOmega = atan2($y, $x); - if ($x < 0 && $y < 0) { - $newOmega = 2 * pi() + $newOmega; - } elseif ($x > 0 && $y < 0) { - $newOmega = 2 * pi() + $newOmega; - } - $newR = sqrt(pow($x,2) + pow($y,2)); - if ($clone) { - $newVector = clone $this; - $newVector->setR($newR); - $newVector->setOmega($newOmega); - - return $newVector; - } - - $this->setR($newR); - $this->setOmega($newOmega); - - return $this; - } - - public function setOmega(float $omega): PolarVector - { - parent::setOmega($omega); - - return $this; - } - - public function getVector(EnumRange $range = EnumRange::G360):array - { - return [ - $this->getR(), - $this->getOmega($range) - ]; - } -} \ No newline at end of file diff --git a/src/Core/Math/Vector/PolarVectorOperation.php b/src/Core/Math/Vector/PolarVectorOperation.php deleted file mode 100644 index 7620a21..0000000 --- a/src/Core/Math/Vector/PolarVectorOperation.php +++ /dev/null @@ -1,63 +0,0 @@ -getOmega($vector1, $vector2, $operator); - $r = $this->getR($vector1, $vector2, $operator); - - return (new PolarVector())->setOmega($omega)->setR($r); - } - - private function getR(PolarVector $vector1, PolarVector $vector2, Operator $operator): float - { - $omega1 = $vector1->getOmega(); - $omega2 = $vector2->getOmega(); - $r1 = $vector1->getR(); - $r2 = $vector2->getR(); - $part1 = pow($r1,2) + pow($r2,2); - $part2 = 2 * abs($r1) * abs($r2) * cos($omega1 - $omega2); - if ($operator == Operator::PLUS) { - $z = sqrt($part1 + $part2); - } else { - //TODO sqrt(-x ) - $z = sqrt($part1 - $part2); - } - - return $z; - } - - private function getOmega(PolarVector $vector1, PolarVector $vector2, Operator $operator): float - { - $omega1 = $vector1->getOmega(); - $omega2 = $vector2->getOmega(); - $r1 = $vector1->getR(); - $r2 = $vector2->getR(); - $yPart1 = abs($r1) * sin($omega1); - $yPart2 = abs($r2) * sin($omega2); - $xPart1 = abs($r1) * cos($omega1); - $xPart2 = abs($r2) * cos($omega2); - if ($operator == Operator::PLUS) { - $y = $yPart1 + $yPart2; - $x = $xPart1 + $xPart2; - } else { - $y = $yPart1 - $yPart2; - $x = $xPart1 - $xPart2; - } - if ($x == 0 && $y == 0) { - - return 0; - } - - return ($y < 0 )? atan2($y , $x) + 2 * pi() : atan2($y , $x); - } -} \ No newline at end of file diff --git a/src/Core/Parser/Decode/DecodeNmea2000.php b/src/Core/Parser/Decode/DecodeNmea2000.php index f475e4b..b851ad0 100644 --- a/src/Core/Parser/Decode/DecodeNmea2000.php +++ b/src/Core/Parser/Decode/DecodeNmea2000.php @@ -5,7 +5,7 @@ use Exception; use Core\Parser\ParserException; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; class DecodeNmea2000 implements DecoderInterface { diff --git a/src/Core/Parser/Lib/BinDec.php b/src/Core/Parser/Lib/BinDec.php deleted file mode 100644 index b970de1..0000000 --- a/src/Core/Parser/Lib/BinDec.php +++ /dev/null @@ -1,136 +0,0 @@ -= 1; - } - - /** - * @throws Exception - */ - private static function validBitLength(string $bin):void - { - if (! in_array(strlen($bin), [4 ,8, 16 ,32 ,64])) { - throw new Exception('can only convert 4 ,8, 16 ,32 ,64 length to dec'); - } - } - - private static function bitFlip(string $bin):string - { - for($i = 0; $i < strlen($bin); $i++) { - $bin[$i] = $bin[$i] == '1' ? '0' : '1'; - } - - return $bin; - } - - private static function is_32bit():bool - { - return PHP_INT_SIZE === 4; - } -} diff --git a/src/Modules/External/AbstractFacade.php b/src/Modules/External/AbstractFacade.php index d4b86f3..6927649 100644 --- a/src/Modules/External/AbstractFacade.php +++ b/src/Modules/External/AbstractFacade.php @@ -2,8 +2,8 @@ namespace Modules\External; -use Core\Math\Skalar\Rad; -use Core\Math\Vector\PolarVector; +use Math\Skalar\Rad; +use Math\Vector\PolarVector; abstract class AbstractFacade { diff --git a/src/Modules/External/FromCache/AnchorFacade.php b/src/Modules/External/FromCache/AnchorFacade.php index 20eb751..3a1e4d1 100644 --- a/src/Modules/External/FromCache/AnchorFacade.php +++ b/src/Modules/External/FromCache/AnchorFacade.php @@ -7,7 +7,7 @@ use Modules\Internal\Pgns\Heading127250; use Modules\Internal\Pgns\WaterDepth128267; use Modules\Internal\Pgns\Wind130306; -use Core\Cache\CacheInterface; +use Modules\Internal\Interfaces\CacheInterface; use Core\Config\ConfigException; use Core\Parser\ParserException; diff --git a/src/Modules/External/FromCache/LogBookFacade.php b/src/Modules/External/FromCache/LogBookFacade.php index 7a76505..4a6a59f 100644 --- a/src/Modules/External/FromCache/LogBookFacade.php +++ b/src/Modules/External/FromCache/LogBookFacade.php @@ -6,9 +6,9 @@ use Modules\Internal\Pgns\Gps129025; use Modules\Internal\Pgns\SetAndDrift129291; use Modules\Internal\Pgns\SogCog129026; -use Core\Cache\CacheInterface; +use Math\Vector\PolarVector; +use Modules\Internal\Interfaces\CacheInterface; use Core\Config\ConfigException; -use Core\Math\Vector\PolarVector; use Core\Parser\ParserException; class LogBookFacade extends AbstractFacade diff --git a/src/Modules/External/FromCache/WindStatisticFacade.php b/src/Modules/External/FromCache/WindStatisticFacade.php index 9698614..ddf7ef0 100644 --- a/src/Modules/External/FromCache/WindStatisticFacade.php +++ b/src/Modules/External/FromCache/WindStatisticFacade.php @@ -7,10 +7,11 @@ use Modules\Internal\Pgns\SogCog129026; use Modules\Internal\Pgns\Temperature130312; use Modules\Internal\Pgns\Wind130306; -use Core\Cache\CacheInterface; +use Modules\Internal\Interfaces\CacheInterface; +use Math\Skalar\Rad; +use Math\Vector\PolarVector; + use Core\Config\ConfigException; -use Core\Math\Skalar\Rad; -use Core\Math\Vector\PolarVector; use Core\Parser\ParserException; class WindStatisticFacade extends AbstractFacade diff --git a/src/Modules/External/FromSocket/InstrumentsFacade.php b/src/Modules/External/FromSocket/InstrumentsFacade.php index 37dca51..d4eca85 100644 --- a/src/Modules/External/FromSocket/InstrumentsFacade.php +++ b/src/Modules/External/FromSocket/InstrumentsFacade.php @@ -4,8 +4,8 @@ use Modules\External\AbstractFacade; use Core\Config\ConfigException; -use Core\Math\Skalar\Rad; -use Core\Math\Vector\PolarVector; +use Math\Skalar\Rad; +use Math\Vector\PolarVector; use Core\Parser\DataFacadeFactory; use Core\Parser\ParserException; use Core\Parser\Data\DataFacade; diff --git a/src/Modules/Internal/Interfaces/CacheInterface.php b/src/Modules/Internal/Interfaces/CacheInterface.php new file mode 100644 index 0000000..df7fd48 --- /dev/null +++ b/src/Modules/Internal/Interfaces/CacheInterface.php @@ -0,0 +1,7 @@ += 60 THEN + insert into wind_speed_hour( + avgTwd, maxTwd, minTwd, + avgAws, maxAws, minAws, + avgAwa, maxAwa, minAwa, + avgTws, maxTws, minTws, + avgTwa, maxTwa, minTwa, + avgCog, maxCog, minCog, + avgSog, maxSog, minSog, + avgVesselHeading, maxVesselHeading, minVesselHeading, + avgWaterTemperature, maxWaterTemperature, minWaterTemperature + ) + select + vavg(sin(RADIANS(twd)), cos(RADIANS(twd)), false), max(twd), min(twd), + avg(aws), max(aws), min(aws), + vavg(sin(RADIANS(awa)), cos(RADIANS(awa)), true), max(awa), min(awa), + avg(tws), max(tws), min(tws), + vavg(sin(RADIANS(twa)), cos(RADIANS(twa)), true), max(twa), min(twa), + vavg(sin(RADIANS(cog)), cos(RADIANS(cog)), false), max(cog), min(cog), + avg(sog), max(sog), min(sog), + vavg(sin(RADIANS(vesselHeading)), cos(RADIANS(vesselHeading)), false), max(vesselHeading), min(vesselHeading), + avg(waterTemperature), max(waterTemperature), min(waterTemperature) + from wind_speed_minute; + END IF; +END; + diff --git a/src/Modules/Module/Realtime/Instruments/AbstractWindSpeedCourse.php b/src/Modules/Module/Realtime/Instruments/AbstractWindSpeedCourse.php index 33ebb04..27a74ae 100644 --- a/src/Modules/Module/Realtime/Instruments/AbstractWindSpeedCourse.php +++ b/src/Modules/Module/Realtime/Instruments/AbstractWindSpeedCourse.php @@ -3,9 +3,9 @@ namespace Modules\Module\Realtime\Instruments; -use Core\Math\Skalar\Rad; -use Core\Math\Vector\PolarVector; -use Core\Math\Vector\PolarVectorOperation; +use Math\Skalar\Rad; +use Math\Vector\PolarVector; +use Math\Vector\PolarVectorOperation; abstract class AbstractWindSpeedCourse { diff --git a/src/Modules/Module/Realtime/Instruments/WindSpeedCourse.php b/src/Modules/Module/Realtime/Instruments/WindSpeedCourse.php index 279f05e..402b6f5 100644 --- a/src/Modules/Module/Realtime/Instruments/WindSpeedCourse.php +++ b/src/Modules/Module/Realtime/Instruments/WindSpeedCourse.php @@ -2,8 +2,8 @@ declare(strict_types=1); namespace Modules\Module\Realtime\Instruments; -use Core\Math\EnumRange; -use Core\Math\Skalar\Rad; +use Math\EnumRange; +use Math\Skalar\Rad; class WindSpeedCourse extends AbstractWindSpeedCourse { diff --git a/test/Core/Database/Mapper/WindSpeedCourseTest.php b/test/Core/Database/Mapper/WindSpeedCourseTest.php index 88dbda4..c730955 100644 --- a/test/Core/Database/Mapper/WindSpeedCourseTest.php +++ b/test/Core/Database/Mapper/WindSpeedCourseTest.php @@ -4,8 +4,8 @@ use Modules\Module\Cron\WeatherStatistic\Entity\WindSpeedCourse; use Core\Database\Database; -use Core\Math\Skalar\Rad; -use Core\Math\Vector\PolarVector; +use Math\Skalar\Rad; +use Math\Vector\PolarVector; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; diff --git a/test/Core/Math/Skalar/RadTest.php b/test/Core/Math/Skalar/RadTest.php deleted file mode 100644 index 01a3ee7..0000000 --- a/test/Core/Math/Skalar/RadTest.php +++ /dev/null @@ -1,58 +0,0 @@ - [EnumRange::G360 ,0.0 , 0.0], - 'G360 90' => [EnumRange::G360 ,90 , 90], - 'G360 180' => [EnumRange::G360 ,180 , 180 ], - 'G360 270' => [EnumRange::G360 ,270 , 270], - 'G360 360' => [EnumRange::G360 ,360, 0 ], - 'G360 450' => [EnumRange::G360 ,450, 90 ], - 'G360 -0' => [EnumRange::G360 ,-0.0 , 0.0], - 'G360 -90' => [EnumRange::G360 ,-90 , 270 ], - 'G360 -180' => [EnumRange::G360 ,-180 , 180 ], - 'G360 -270' => [EnumRange::G360 ,-270, 90 ], - 'G360 -360' => [EnumRange::G360 ,-360, 0 ], - 'G360 -450' => [EnumRange::G360 ,-450, 270 ], - - 'G180 0' => [EnumRange::G180 ,0.0 , 0.0], - 'G180 p90' => [EnumRange::G180 , 90, 90 ], - 'G180 120' => [EnumRange::G180 , 120, 120 ], - 'G180 180' => [EnumRange::G180 ,180 , 180 ], - 'G180 360' => [EnumRange::G180 , 360, 0 ], - 'G180 270' => [EnumRange::G180 , 270, -90 ], - 'G180 450' => [EnumRange::G180 , 450, 90 ], - 'G180 540' => [EnumRange::G180 ,540, 180.0], - 'G180 -0' => [EnumRange::G180 ,-0.0 , 0.0], - - 'G180 -10' => [EnumRange::G180 , -10 , -10 ], - 'G180 -90' => [EnumRange::G180 , -90 , -90 ], - 'G180 -120' => [EnumRange::G180, -120 , -120 ], - 'G180 -180' => [EnumRange::G180 , -180 , 180 ], - 'G180 -270' => [EnumRange::G180 , -270 , 90 ], - 'G180 -360' => [EnumRange::G180, -360, 0 ], - 'G180 -450' => [EnumRange::G180, -450, -90 ], - 'G180 -540' => [EnumRange::G180, -540, 180 ] - - ]; - } - - #[DataProvider('dataProvider')] - public function testGetRad(EnumRange $range, float $actual, float $expected) - { - $rad = new Rad(); - $rad->setOmega(deg2rad($actual)); - $this->assertEquals($expected, rad2deg($rad->getOmega($range)), $actual); - $this->assertEquals($rad->getDegOmega($range), rad2deg($rad->getOmega($range))); - } -} diff --git a/test/Core/Math/Vector/PolarVectorOperationTest.php b/test/Core/Math/Vector/PolarVectorOperationTest.php deleted file mode 100644 index cb60217..0000000 --- a/test/Core/Math/Vector/PolarVectorOperationTest.php +++ /dev/null @@ -1,125 +0,0 @@ - [10 ,45, 10, 45 , 20.00 , 45.0, EnumRange::G180, Operator::PLUS], - 'P1' => [10 ,45, 10, 90 , 18.48 , 67.5, EnumRange::G180, Operator::PLUS], - 'P2' => [10 ,45, 10, 180 , 7.65 , 112.50, EnumRange::G180, Operator::PLUS], - 'P3' => [10 ,45, 10, 220 , 0.87 , 132.50, EnumRange::G180, Operator::PLUS], - 'P4' => [10 ,170, 10, 220 , 18.13 , -165.00,EnumRange::G180, Operator::PLUS], - 'P5' => [10 ,170, 10, 220 , 18.13 , 195.00, EnumRange::G360, Operator::PLUS], - 'P6' => [10 ,190, 10, 220 , 19.32 , -155, EnumRange::G180, Operator::PLUS], - 'P7' => [10 ,190, 10, 220 , 19.32 , 205, EnumRange::G360, Operator::PLUS], - 'M0' => [10 , 45, 10, 45 , 0 , 0 , EnumRange::G360, Operator::MINUS], - 'M1' => [10 , 90, 20, 90 , 10 , -90 , EnumRange::G180, Operator::MINUS], - 'M2' => [10 , 90, 20, 180 , 22.36 , 26.57 , EnumRange::G180, Operator::MINUS], - 'M3' => [10 , 50, 10, -170 , 18.79, 30.00, EnumRange::G180, Operator::MINUS], - 'M4' => [10 , 50, 10, -170 , 18.79, 30.00, EnumRange::G360, Operator::MINUS], - 'M5' => [10 , 50, 10, 220, 19.92, 45, EnumRange::G360, Operator::MINUS], - 'M6' => [10 , 50, 10, 220, 19.92, 45, EnumRange::G360, Operator::MINUS], - 'M7' => [ 10, -130, 10, -120, 19.9239, -125, EnumRange::G180, Operator::PLUS], - 'M8' => [ 10, -130, 10, -120, 19.9239, 235, EnumRange::G360, Operator::PLUS], - ]; - - } - - #[DataProvider('dataProvider')] - public function testAdd(float $r1, float $o1, float $r2, float $o2, float $r, float $o, EnumRange $range= EnumRange::G360,Operator $operator= Operator::PLUS) - { - $addierer = new PolarVectorOperation(); - $vector1 = (new PolarVector())->setR($r1)->setOmega(deg2rad($o1)); - $vector2 = (new PolarVector())->setR($r2)->setOmega(deg2rad($o2)); - $vector3 = $addierer($vector1, $vector2, $operator); - $this->assertEqualsWithDelta($r, $vector3->getR(), 0.1); - $this->assertEqualsWithDelta($o, rad2deg($vector3->getOmega($range)), 0.01); - } - public function test__invoke() - { - $addierer = new PolarVectorOperation(); - $vector1 = (new PolarVector())->setR(10)->setOmega(deg2rad(0)); - $vector2 = (new PolarVector())->setR(10)->setOmega(deg2rad(90)); - - $vector3 = $addierer($vector1, $vector2); - $this->assertEquals([14.142135623730951 ,0.7853981633974483], $vector3->getVector()); - $this->assertEquals(45, rad2deg($vector3->getOmega())); - $this->assertEquals(14.142135623730951, $vector3->getR()); - - $vector4 = (new PolarVector())->setOmega(deg2rad(180))->setR(20); - $vector5 = $addierer($vector3, $vector4); - $this->assertEqualsWithDelta(135, rad2deg($vector5->getOmega()), 0.01); - $this->assertEquals(14.142135623730951, $vector5->getR()); - - $vector6 = (new PolarVector())->setOmega(deg2rad(270))->setR(20); - $vector7 = $addierer($vector5, $vector6); - - $this->assertEquals(225, round(rad2deg($vector7->getOmega()),0)); - $this->assertEqualsWithDelta(14.142135623730951, $vector7->getR(),0.01 ); - - $vector8 = (new PolarVector())->setOmega(deg2rad(0))->setR(20); - $vector9 = $addierer($vector7, $vector8); - - $this->assertEquals(315, round(rad2deg($vector9->getOmega()),0)); - $this->assertEqualsWithDelta(14.142135623730951, $vector9->getR(), 0.00000000001); - - $vector10 = (new PolarVector())->setOmega(deg2rad(90))->setR(20); - $vector11 = $addierer($vector9, $vector10); - - $this->assertEquals(45, round(rad2deg($vector11->getOmega()),0)); - $this->assertEqualsWithDelta(14.142135623730951, $vector11->getR(), 0.00000000001); - - - - #$r = $vector9->getR(); - #$o = rad2deg($vector9->getOmega()) ; - #echo "[$r, $o]\n"; - - } - - public function testMinus() - { - $addierer = new PolarVectorOperation(); - $vector1 = (new PolarVector())->setR(10)->setOmega(deg2rad(90)); - $vector2 = (new PolarVector())->setR(10)->setOmega(deg2rad(90)); - $vector3 = (new PolarVector())->setR(9)->setOmega(deg2rad(90)); - $vector50 = $addierer($vector1, $vector2,Operator::MINUS); - $this->assertEquals(0, round(rad2deg($vector50->getOmega()),0)); - $this->assertEquals(0, $vector50->getR()); - $vector50 = $addierer($vector1, $vector3,Operator::MINUS); - $this->assertEquals(90, round(rad2deg($vector50->getOmega()),0)); - $this->assertEquals(1, $vector50->getR()); - } - - public function testReal() - { - $addierer = new PolarVectorOperation(); - $aw = (new PolarVector())->setR(0)->setOmega(deg2rad(71)); - $course = (new PolarVector())->setR($this->kn2ms(3.1))->setOmega(deg2rad(-61)); - $tw = $addierer($aw, $aw, Operator::MINUS); - $this->assertEquals(0, round(rad2deg($tw->getOmega()), 0)); - $this->assertEquals(0, $tw->getR()); - // I need a rotation - // (x´,y´) = (x·cosθ – y·sinθ, x·sinθ + y·cosθ) - // (x´,y´) = (r × cos( omega )·cosθ – r × sin( omega )·sin θ, r × cos( Omega )·sinθ + r × sin( Omega )·cosθ) - //x = r × cos( θ ) - //y = r × sin( θ ) - } - - private function kn2ms(float $kn):float - { - return $kn / 1.94384; - } -} diff --git a/test/Core/Math/Vector/PolarVectorTest.php b/test/Core/Math/Vector/PolarVectorTest.php deleted file mode 100644 index 7ce469b..0000000 --- a/test/Core/Math/Vector/PolarVectorTest.php +++ /dev/null @@ -1,178 +0,0 @@ -setR(10 )->setOmega(deg2rad(45)); - $beAgainstVector = $vector->againstVector(true); - $this->assertEquals(10, $vector->getR()); - $this->assertEquals(45, rad2deg($vector->getOmega())); - $this->assertEquals(10, $beAgainstVector->getR()); - $this->assertEqualsWithDelta(-135, rad2deg($beAgainstVector->getOmega(EnumRange::G180)), 0.01); - $this->assertEqualsWithDelta(225, rad2deg($beAgainstVector->getOmega(EnumRange::G360)), 0.01); - - - } - public function testRotateNeg() - { - $vector = (new PolarVector())->setR(10)->setOmega(deg2rad(-170)); - $this->assertEquals(10, $vector->getR()); - $this->assertEquals(-170, rad2deg($vector->getOmega(EnumRange::G180))); - $this->assertEquals(190, rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEqualsWithDelta(20, rad2deg($vector->rotate(deg2rad(-170))->getOmega(EnumRange::G360)),0.01); - $this->assertEqualsWithDelta(20, rad2deg($vector->getOmega(EnumRange::G180)), 0.01); - } - public function testGetPositivOmega() - { - $vector = new PolarVector(); - $vector->setOmega(0); - $this->assertEquals(0 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(0, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(pi()/2); - $this->assertEquals(90 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(90, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(pi()); - $this->assertEquals(180 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(180, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(pi() * 3 / 2); - $this->assertEquals(270 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(-90, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(2 * pi()); - $this->assertEquals(0 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(0, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(3 * pi()); - $this->assertEquals(180 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(180, rad2deg($vector->getOmega(EnumRange::G180))); - } - - public function testZeroR() - { - $vector = new PolarVector(); - $vector->setR(0); - $vector->setOmega( deg2rad(0)); - $this->assertEquals(0 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(0, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega( deg2rad(90)); - $this->assertEquals(90 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(90, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega( deg2rad(180)); - $this->assertEquals(180 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(180, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega( deg2rad(270)); - $this->assertEquals(270 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(-90, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega( deg2rad(255)); - $vector->setR(0.07); - $this->assertEquals(255 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEqualsWithDelta(-105, rad2deg($vector->getOmega(EnumRange::G180)), 0.1); - } - - public function testRotate() - { - $vector = new PolarVector(); - $vector->setOmega(deg2rad(90)); - $vector->setR(20); - $this->assertEquals(90, rad2deg($vector->getOmega())); - $this->assertEquals(20, $vector->getR()); - $vector->rotate(deg2rad(10)); - $this->assertEquals(100, rad2deg($vector->getOmega())); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(80)); - $this->assertEquals(180, rad2deg($vector->getOmega())); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(10)); - $this->assertEquals(190, rad2deg($vector->getOmega())); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(80)); - $this->assertEqualsWithDelta(270, rad2deg($vector->getOmega()), 0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(80)); - $this->assertEqualsWithDelta(350, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(11)); - $this->assertEqualsWithDelta(1, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - - $vector->rotate(deg2rad(-2)); - $this->assertEqualsWithDelta(359, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-89)); - $this->assertEqualsWithDelta(270, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-89)); - $this->assertEqualsWithDelta(181, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-1)); - $this->assertEqualsWithDelta(180, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-45)); - $this->assertEqualsWithDelta(135, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-45)); - $this->assertEqualsWithDelta(90, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-45)); - $this->assertEqualsWithDelta(45, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - $vector->rotate(deg2rad(-45)); - $this->assertEqualsWithDelta(0, rad2deg($vector->getOmega()),0.0001); - $this->assertEqualsWithDelta(20, $vector->getR(), 0.0001); - - } - - public function testRotateZeroR() - { - $vector = new PolarVector(); - $vector->setOmega(deg2rad(90)); - $vector->setR(0); - $this->assertEquals(90, rad2deg($vector->getOmega())); - $this->assertEquals(0, $vector->getR()); - $vector->rotate(deg2rad(90)); - $this->assertEquals(0, rad2deg($vector->getOmega())); - $this->assertEquals(0, $vector->getR()); - } - - public function testGetNegativOmega() - { - $vector = new PolarVector(); - $vector->setOmega(0); - $this->assertEquals(0 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(0, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(-pi()/2); - $this->assertEquals(270 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(-90, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(pi()); - $this->assertEquals(180 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(180, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(-pi() * 3 / 2); - $this->assertEquals(90 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(90, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(-2 * pi()); - $this->assertEquals(0 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(0, rad2deg($vector->getOmega(EnumRange::G180))); - - $vector->setOmega(-3 * pi()); - $this->assertEquals(180 , rad2deg($vector->getOmega(EnumRange::G360))); - $this->assertEquals(180, rad2deg($vector->getOmega(EnumRange::G180))); - } -} diff --git a/test/Core/Parser/Data/DataPartTest.php b/test/Core/Parser/Data/DataPartTest.php index 31139af..408296c 100644 --- a/test/Core/Parser/Data/DataPartTest.php +++ b/test/Core/Parser/Data/DataPartTest.php @@ -5,7 +5,7 @@ use Core\Parser\Decode\DecodeNmea2000; use Core\Config\ConfigPgn; use Core\Config\PngFieldConfig; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/Core/Parser/DataFacadeFactoryTest.php b/test/Core/Parser/DataFacadeFactoryTest.php index 8591e42..fccb05c 100644 --- a/test/Core/Parser/DataFacadeFactoryTest.php +++ b/test/Core/Parser/DataFacadeFactoryTest.php @@ -9,7 +9,7 @@ use Core\Parser\Data\DataPart; use Core\Parser\Data\MainPart; use Core\Parser\Decode\DecodeNmea2000; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Core\Parser\DataFacadeFactory; diff --git a/test/Core/Parser/DataFacadeTest.php b/test/Core/Parser/DataFacadeTest.php index 5059ffd..288d90d 100644 --- a/test/Core/Parser/DataFacadeTest.php +++ b/test/Core/Parser/DataFacadeTest.php @@ -11,7 +11,7 @@ use Core\Parser\Data\MainPart; use Core\Parser\DataFacadeFactory; use Core\Parser\Decode\DecodeNmea2000; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; diff --git a/test/Core/Parser/Decode/DecodeNmea2000Test.php b/test/Core/Parser/Decode/DecodeNmea2000Test.php index 2716878..f781697 100644 --- a/test/Core/Parser/Decode/DecodeNmea2000Test.php +++ b/test/Core/Parser/Decode/DecodeNmea2000Test.php @@ -2,7 +2,7 @@ namespace TestCore\Parser\Decode; use Core\Parser\Decode\Request; -use Core\Parser\Lib\BinDec; +use Math\Bin\BinDec; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\CoversClass; use Core\Parser\Decode\DecodeNmea2000; diff --git a/test/Core/Parser/Lib/BinDecTest.php b/test/Core/Parser/Lib/BinDecTest.php deleted file mode 100644 index 7cf601b..0000000 --- a/test/Core/Parser/Lib/BinDecTest.php +++ /dev/null @@ -1,97 +0,0 @@ -assertEquals(1, BinDec::bin2dec('0001', true)); - $this->assertEquals(1, BinDec::bin2dec('0001', false)); - $this->assertEquals(2, BinDec::bin2dec('0010', true)); - $this->assertEquals(2, BinDec::bin2dec('0010', false)); - $this->assertEquals(3, BinDec::bin2dec('0011', true)); - $this->assertEquals(3, BinDec::bin2dec('0011', false)); - $this->assertEquals(7, BinDec::bin2dec('0111', true)); - $this->assertEquals(7, BinDec::bin2dec('0111', false)); - $this->assertEquals(-1, BinDec::bin2dec('1111', true)); - $this->assertEquals(15, BinDec::bin2dec('1111', false)); - $this->assertEquals(-7, BinDec::bin2dec('1001', true)); - $this->assertEquals(9, BinDec::bin2dec('1001', false)); - $this->assertEquals(-6, BinDec::bin2dec('1010', true)); - $this->assertEquals(10, BinDec::bin2dec('1010', false)); - $this->assertEquals(-5, BinDec::bin2dec('1011', true)); - $this->assertEquals(11, BinDec::bin2dec('1011', false)); - $this->assertEquals(22, BinDec::bin2dec('1011', false, 2)); - } - - public static function dataProviderbindec64BitSame():array - { - return [ - ['1111'], - ['11111111'], - ['1111111111111111'], - ['11111111111111111111111111111111'], - ['1111111111111111111111111111111111111111111111111111111111111111'], - ['0111011111110001111001111110001111111011111111110111111111111111'] - ]; - } - #[DataProvider('dataProviderbindec64BitSame')] - public function testInternelAgainst64BitSame(string $bin) - { - $this->assertEquals(bindec($bin), BinDec::bin2dec64BitSystem($bin), strlen($bin)); - } - public static function dataProvider32And64BitSame():array - { - return [ - ['1111'], - ['11111111'], - ['1111111111111111'], - ['11111111111111111111111111111111'], - ['1111111111111111111111111111111111111111111111111111111111111111'], - ['1111', true], - ['11111111',true], - ['1111111111111111',true], - ['11111111111111111111111111111111',true], - ['1111111111111111111111111111111111111111111111111111111111111111',true], - ['1111', true], - ['11111111',true], - ['1111111111111111',true], - ['11111111111111111111111111111111',true], - ['1111111111111111111111111111111111111111111111111111111111111111',true, 1E-16], - ['0000010100100111000110011101010111110100010111111100001000000000',true, 1E-16], - ['1000000000000000000000000000000000000000000000000000000000000000',true, 0,001] - ]; - } - #[DataProvider('dataProvider32And64BitSame')] - public function test32And64BitSame(string $bin, bool $signed = false, float $resolution = 1) - { - $this->assertEquals(BinDec::bin2dec64BitSystem($bin, $signed, $resolution), BinDec::bin2dec32BitSystem($bin, $signed, $resolution), strlen($bin)); - } - - public function testResult32BitSystem() - { - $this->assertEquals(37.1293901, BinDec::bin2dec32BitSystem('0000010100100111000110011101010111110100010111111100001000000000', true, 1E-16)); - $this->assertEquals(37.1293901, BinDec::bin2dec64BitSystem('0000010100100111000110011101010111110100010111111100001000000000', true, 1E-16)); - } - - public function testIsNotBinaryException() - { - $this->expectException('\Exception'); - BinDec::bin2dec('0a01', true); - } - - public function testWrongLengt() - { - $this->expectException('\Exception'); - BinDec::bin2dec('00011', true); - } -} diff --git a/test/miniTest32BitSystem.php b/test/miniTest32BitSystem.php deleted file mode 100644 index 3b0951b..0000000 --- a/test/miniTest32BitSystem.php +++ /dev/null @@ -1,8 +0,0 @@ -