From 34685c90e880270907ace2dfac8b4f0fb0e50370 Mon Sep 17 00:00:00 2001 From: "Frank.Markwort" Date: Wed, 18 Sep 2024 10:27:19 +0300 Subject: [PATCH 1/5] Begin to remove sql migration from core to Module --- .../Cron/Logbook/migration/001-Logbook.sql | 16 +++ .../migration/001-WeatherStatistic.sql | 118 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 src/Modules/Module/Cron/Logbook/migration/001-Logbook.sql create mode 100644 src/Modules/Module/Cron/WeatherStatistic/migration/001-WeatherStatistic.sql diff --git a/src/Modules/Module/Cron/Logbook/migration/001-Logbook.sql b/src/Modules/Module/Cron/Logbook/migration/001-Logbook.sql new file mode 100644 index 0000000..f332c6f --- /dev/null +++ b/src/Modules/Module/Cron/Logbook/migration/001-Logbook.sql @@ -0,0 +1,16 @@ +create table positions +( + id int auto_increment primary key, + fid_wind_speed_hour int not null, + timestamp datetime default current_timestamp() not null, + latitude double not null, + longitude double not null, + cog double default 0 not null, + sog double default 0 not null, + `set` double default 0 not null, + drift double default 0 not null, + constraint positions_wind_speed_hour_id_fk + foreign key (fid_wind_speed_hour) references wind_speed_hour (id) + on update cascade on delete cascade +) + engine = InnoDB; \ No newline at end of file diff --git a/src/Modules/Module/Cron/WeatherStatistic/migration/001-WeatherStatistic.sql b/src/Modules/Module/Cron/WeatherStatistic/migration/001-WeatherStatistic.sql new file mode 100644 index 0000000..083d1c1 --- /dev/null +++ b/src/Modules/Module/Cron/WeatherStatistic/migration/001-WeatherStatistic.sql @@ -0,0 +1,118 @@ +create + definer = nmea2000@`%` function Vavg(avgSinDir float, avgCosDir float, is180Deg tinyint(1)) returns float + deterministic +begin + IF (avgSinDir = 0 AND avgCosDir = 0) THEN + return 0.0; + end if; + if (is180Deg) THEN + return mod(degrees(atan2(avgSinDir, avgCosDir)), 180); + end if; + if (avgSinDir < 0) then + return mod(degrees(atan2(avgSinDir, avgCosDir)) + 360, 360); + else + return mod(degrees(atan2(avgSinDir, avgCosDir)), 360); + end if; +end; + +create table wind_speed_hour +( + id int auto_increment + primary key, + date datetime default current_timestamp() not null, + avgTwd double not null, + maxTwd double not null, + minTwd double not null, + avgAws double not null, + maxAws double not null, + minAws double not null, + avgAwa double not null, + maxAwa double not null, + minAwa double not null, + avgTws double not null, + maxTws double not null, + minTws double not null, + avgTwa double not null, + maxTwa double not null, + minTwa double not null, + avgCog double not null, + maxCog double not null, + minCog double not null, + avgSog double not null, + maxSog double not null, + minSog double not null, + avgVesselHeading double not null, + maxVesselHeading double not null, + minVesselHeading double not null, + avgWaterTemperature double default 0 not null, + minWaterTemperature double default 0 not null, + maxWaterTemperature double default 0 not null, + constraint wind_speed_hour_pk + unique (date) +) + engine = InnoDB; + +create table wind_speed_minute_seq +( + next_not_cached_value bigint(21) not null, + minimum_value bigint(21) not null, + maximum_value bigint(21) not null, + start_value bigint(21) not null comment 'start value when sequences is created or value if RESTART is used', + increment bigint(21) not null comment 'increment value', + cache_size bigint(21) unsigned not null, + cycle_option tinyint(1) unsigned not null comment '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed', + cycle_count bigint(21) not null comment 'How many cycles have been done' +) + engine = InnoDB; + + + + +create table wind_speed_minute +( + id_minute int default nextval(`nmea2000`.`wind_speed_minute_seq`) not null + primary key, + timestamp time not null, + twd double not null, + aws double not null, + awa double not null, + tws double not null, + twa double not null, + cog double not null, + sog double not null, + vesselHeading double not null, + waterTemperature double default 0 not null +) + engine = InnoDB; + +create definer = nmea2000@`%` trigger generateHourStatistics + after insert + on wind_speed_minute + for each row +BEGIN + IF NEW.id_minute >= 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; + From c2be0510199acaea1743b3ae2c12cf6823813f6f Mon Sep 17 00:00:00 2001 From: "Frank.Markwort" Date: Wed, 18 Sep 2024 17:46:52 +0300 Subject: [PATCH 2/5] move Math to library --- composer.json | 3 +- composer.lock | 51 ++++- src/Core/Math/AbstractAngleRad.php | 121 ------------ src/Core/Math/EnumRange.php | 10 - src/Core/Math/Skalar/Rad.php | 24 --- src/Core/Math/Vector/Operator.php | 10 - src/Core/Math/Vector/PolarVector.php | 71 ------- src/Core/Math/Vector/PolarVectorOperation.php | 63 ------- src/Modules/External/AbstractFacade.php | 4 +- .../External/FromCache/LogBookFacade.php | 2 +- .../FromCache/WindStatisticFacade.php | 5 +- .../External/FromSocket/InstrumentsFacade.php | 4 +- .../Module/Cron/Logbook/Entity/Positions.php | 2 +- .../Entity/AbstractWindSpeedCourse.php | 6 +- .../Entity/WindSpeedCourse.php | 4 +- .../Instruments/AbstractWindSpeedCourse.php | 6 +- .../Realtime/Instruments/WindSpeedCourse.php | 4 +- test/Core/Math/Skalar/RadTest.php | 58 ------ .../Math/Vector/PolarVectorOperationTest.php | 125 ------------ test/Core/Math/Vector/PolarVectorTest.php | 178 ------------------ 20 files changed, 69 insertions(+), 682 deletions(-) delete mode 100644 src/Core/Math/AbstractAngleRad.php delete mode 100644 src/Core/Math/EnumRange.php delete mode 100644 src/Core/Math/Skalar/Rad.php delete mode 100644 src/Core/Math/Vector/Operator.php delete mode 100644 src/Core/Math/Vector/PolarVector.php delete mode 100644 src/Core/Math/Vector/PolarVectorOperation.php delete mode 100644 test/Core/Math/Skalar/RadTest.php delete mode 100644 test/Core/Math/Vector/PolarVectorOperationTest.php delete mode 100644 test/Core/Math/Vector/PolarVectorTest.php 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..af0f667 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,53 @@ "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.0", + "source": { + "type": "git", + "url": "https://github.com/FrankMarkwort/Math.git", + "reference": "7b4263ff03801fe18bded99a03fdbf5cb3568c49" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FrankMarkwort/Math/zipball/7b4263ff03801fe18bded99a03fdbf5cb3568c49", + "reference": "7b4263ff03801fe18bded99a03fdbf5cb3568c49", + "shasum": "" + }, + "require": { + "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", + "support": { + "issues": "https://github.com/FrankMarkwort/Math/issues", + "source": "https://github.com/FrankMarkwort/Math/tree/1.0" + }, + "time": "2024-09-15T14:53:12+00:00" + } + ], "packages-dev": [ { "name": "myclabs/deep-copy", @@ -1654,5 +1699,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/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/LogBookFacade.php b/src/Modules/External/FromCache/LogBookFacade.php index 7a76505..38bff1a 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 Math\Vector\PolarVector; use Core\Cache\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..225fa09 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 Math\Skalar\Rad; +use Math\Vector\PolarVector; + use Core\Cache\CacheInterface; 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/Module/Cron/Logbook/Entity/Positions.php b/src/Modules/Module/Cron/Logbook/Entity/Positions.php index 74a8762..d30a6a7 100644 --- a/src/Modules/Module/Cron/Logbook/Entity/Positions.php +++ b/src/Modules/Module/Cron/Logbook/Entity/Positions.php @@ -3,7 +3,7 @@ namespace Modules\Module\Cron\Logbook\Entity; -use Core\Math\Vector\PolarVector; +use Math\Vector\PolarVector; class Positions implements ComparableInterface { diff --git a/src/Modules/Module/Cron/WeatherStatistic/Entity/AbstractWindSpeedCourse.php b/src/Modules/Module/Cron/WeatherStatistic/Entity/AbstractWindSpeedCourse.php index 5621f30..5cdcb34 100644 --- a/src/Modules/Module/Cron/WeatherStatistic/Entity/AbstractWindSpeedCourse.php +++ b/src/Modules/Module/Cron/WeatherStatistic/Entity/AbstractWindSpeedCourse.php @@ -4,9 +4,9 @@ namespace Modules\Module\Cron\WeatherStatistic\Entity; //TODO remove from Module -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/Cron/WeatherStatistic/Entity/WindSpeedCourse.php b/src/Modules/Module/Cron/WeatherStatistic/Entity/WindSpeedCourse.php index 002372d..c7b0bb0 100644 --- a/src/Modules/Module/Cron/WeatherStatistic/Entity/WindSpeedCourse.php +++ b/src/Modules/Module/Cron/WeatherStatistic/Entity/WindSpeedCourse.php @@ -4,8 +4,8 @@ namespace Modules\Module\Cron\WeatherStatistic\Entity; //TODO remove from Module -use Core\Math\EnumRange; -use Core\Math\Skalar\Rad; +use Math\EnumRange; +use Math\Skalar\Rad; class WindSpeedCourse extends AbstractWindSpeedCourse { 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/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))); - } -} From dd12324622adcd81d0eb39bdb93eb681eface8de Mon Sep 17 00:00:00 2001 From: "Frank.Markwort" Date: Wed, 18 Sep 2024 17:51:24 +0300 Subject: [PATCH 3/5] move Math to library --- test/Core/Database/Mapper/WindSpeedCourseTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From b20f8a35cd4e8db913aaf33034d9ff807925e84b Mon Sep 17 00:00:00 2001 From: "Frank.Markwort" Date: Wed, 18 Sep 2024 23:36:16 +0300 Subject: [PATCH 4/5] move code from core to modules --- src/Modules/External/FromCache/AnchorFacade.php | 2 +- src/Modules/External/FromCache/LogBookFacade.php | 2 +- src/Modules/External/FromCache/WindStatisticFacade.php | 2 +- src/Modules/Internal/Interfaces/CacheInterface.php | 7 +++++++ .../WeatherStatistic/Entity/AbstractWindSpeedCourse.php | 1 - .../Cron/WeatherStatistic/Entity/WindSpeedCourse.php | 1 - 6 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/Modules/Internal/Interfaces/CacheInterface.php 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 38bff1a..4a6a59f 100644 --- a/src/Modules/External/FromCache/LogBookFacade.php +++ b/src/Modules/External/FromCache/LogBookFacade.php @@ -7,7 +7,7 @@ use Modules\Internal\Pgns\SetAndDrift129291; use Modules\Internal\Pgns\SogCog129026; use Math\Vector\PolarVector; -use Core\Cache\CacheInterface; +use Modules\Internal\Interfaces\CacheInterface; use Core\Config\ConfigException; use Core\Parser\ParserException; diff --git a/src/Modules/External/FromCache/WindStatisticFacade.php b/src/Modules/External/FromCache/WindStatisticFacade.php index 225fa09..ddf7ef0 100644 --- a/src/Modules/External/FromCache/WindStatisticFacade.php +++ b/src/Modules/External/FromCache/WindStatisticFacade.php @@ -7,10 +7,10 @@ use Modules\Internal\Pgns\SogCog129026; use Modules\Internal\Pgns\Temperature130312; use Modules\Internal\Pgns\Wind130306; +use Modules\Internal\Interfaces\CacheInterface; use Math\Skalar\Rad; use Math\Vector\PolarVector; -use Core\Cache\CacheInterface; use Core\Config\ConfigException; use Core\Parser\ParserException; 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 @@ + Date: Thu, 19 Sep 2024 02:13:33 +0300 Subject: [PATCH 5/5] Move bi2dec to packet Math --- composer.lock | 15 +- src/Core/Parser/Decode/DecodeNmea2000.php | 2 +- src/Core/Parser/Lib/BinDec.php | 136 ------------------ test/Core/Parser/Data/DataPartTest.php | 2 +- test/Core/Parser/DataFacadeFactoryTest.php | 2 +- test/Core/Parser/DataFacadeTest.php | 2 +- .../Core/Parser/Decode/DecodeNmea2000Test.php | 2 +- test/Core/Parser/Lib/BinDecTest.php | 97 ------------- test/miniTest32BitSystem.php | 8 -- 9 files changed, 13 insertions(+), 253 deletions(-) delete mode 100644 src/Core/Parser/Lib/BinDec.php delete mode 100644 test/Core/Parser/Lib/BinDecTest.php delete mode 100644 test/miniTest32BitSystem.php diff --git a/composer.lock b/composer.lock index af0f667..82581a1 100644 --- a/composer.lock +++ b/composer.lock @@ -8,19 +8,20 @@ "packages": [ { "name": "poseidon2/math", - "version": "1.0.0", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/FrankMarkwort/Math.git", - "reference": "7b4263ff03801fe18bded99a03fdbf5cb3568c49" + "reference": "70999367939f953b9fe640799ee482d16b0cd920" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FrankMarkwort/Math/zipball/7b4263ff03801fe18bded99a03fdbf5cb3568c49", - "reference": "7b4263ff03801fe18bded99a03fdbf5cb3568c49", + "url": "https://api.github.com/repos/FrankMarkwort/Math/zipball/70999367939f953b9fe640799ee482d16b0cd920", + "reference": "70999367939f953b9fe640799ee482d16b0cd920", "shasum": "" }, "require": { + "ext-bcmath": "*", "php": ">= 8.3" }, "require-dev": { @@ -43,12 +44,12 @@ "role": "Developer" } ], - "description": "Math vector", + "description": "Math-Vector library", "support": { "issues": "https://github.com/FrankMarkwort/Math/issues", - "source": "https://github.com/FrankMarkwort/Math/tree/1.0" + "source": "https://github.com/FrankMarkwort/Math/tree/1.0.3" }, - "time": "2024-09-15T14:53:12+00:00" + "time": "2024-09-18T22:53:05+00:00" } ], "packages-dev": [ 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/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 @@ -