From c2be0510199acaea1743b3ae2c12cf6823813f6f Mon Sep 17 00:00:00 2001 From: "Frank.Markwort" Date: Wed, 18 Sep 2024 17:46:52 +0300 Subject: [PATCH] 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))); - } -}