diff --git a/Angle.cpp b/Angle.cpp index a821fd7..1788650 100644 --- a/Angle.cpp +++ b/Angle.cpp @@ -1,12 +1,10 @@ // // FILE: Angle.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.13 +// VERSION: 0.1.14 // PURPOSE: library for Angle math for Arduino // URL: https://github.com/RobTillaart/Angle // http://forum.arduino.cc/index.php?topic=339402 -// -// HISTORY: see changelog.md #include "Angle.h" @@ -31,7 +29,6 @@ Angle::Angle(int dd, int mm, int ss, int tt) m = mm; s = ss; t = tt; - // TODO // normalize(); // assume only one (largest) parameter is negative at most... if (d < 0) { d = -d; neg = true; } @@ -318,7 +315,7 @@ int Angle::compare(const Angle &a, const Angle &b) } -void Angle::normalize() // TODO CHECK +void Angle::normalize() { while (t < 0) { s--; t += 10000; } while (t >= 10000) { s++; t -= 10000; } diff --git a/Angle.h b/Angle.h index 8223eef..d0b4cac 100644 --- a/Angle.h +++ b/Angle.h @@ -2,9 +2,10 @@ // // FILE: Angle.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.13 +// VERSION: 0.1.14 // PURPOSE: angle library for Arduino -// HISTORY: See angle.cpp +// URL: https://github.com/RobTillaart/Angle +// http://forum.arduino.cc/index.php?topic=339402 // // AngleFormat proxy added 03/03/15 by Christoper Andrews. // @@ -15,7 +16,7 @@ #include "Printable.h" -#define ANGLE_LIB_VERSION (F("0.1.13")) +#define ANGLE_LIB_VERSION (F("0.1.14")) class Angle; @@ -97,5 +98,5 @@ class Angle: public Printable }; -// -- END OF FILE +// -- END OF FILE diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3eb07..5416332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.14] - 2023-01-31 +- update GitHub actions +- update license 2023 +- update readme.md +- add performance sketch (initial version) + + ## [0.1.13] - 2022-10-12 - Add RP2040 support to build-CI - Add CHANGELOG.md diff --git a/README.md b/README.md index a8c585d..696fa4b 100644 --- a/README.md +++ b/README.md @@ -25,17 +25,31 @@ The library implements the Printable interface, allowing one to call **Serial.println(angle)** or **SD.print(angle)**. +Degree sign ° = ALT-0176 (Windows) + + +#### Related + +- https://github.com/RobTillaart/AngleConvertor +- https://github.com/RobTillaart/AverageAngle +- https://github.com/RobTillaart/Angle +- https://github.com/RobTillaart/runningAngle + ## Interface -### Constructors +```cpp +#include "Angle.h" +``` + +#### Constructors - **Angle(int dd = 0, int mm = 0, int ss = 0, int tt = 0)** create an Angle, default is zero. - **Angle(double alpha)** create an Angle from a double. - **Angle(char \* str)** create an Angle from a string e.g. "45.31234". -### base +#### Base - **int sign()** returns -1 or 1. - **int degree()** returns # degrees. @@ -44,19 +58,21 @@ The library implements the Printable interface, allowing one to call - **int tenthousand()** returns # ten-thousands of a second. -### Conversions +#### Conversions - **double toDouble()** returns the angle as a double (0..360.0, float on UNO). - **double toRadians()** returns the angle in radians (0..TWO_PI). - **void fromRadian(double rad)** create an angle from radians. +More conversions - https://github.com/RobTillaart/AngleConvertor + -### Equality operators +#### Equality operators The library supports equality operator "==", "!=", "<" "<=" ">" and ">=" . -### Math operators +#### Math operators - **negate** returns -angle. - **addition** and **subtract** add angles to angles. @@ -71,19 +87,33 @@ See examples. ## Note -The library has not been tested extensively and it could still contain -bugs. Especially the constructor does not check input so use it carefully. +The library has not been tested extensively and it could still contain bugs. +Especially the constructor does not check input so use it carefully. ## Future +#### Must + - improve documentation -- test more -- optimize code where possible - - performance sketch + +#### Should + +- Test normalize code + - unit tests, sketch? +- test more + - TOCHECK in code - improve code quality - - fix TODO in code - use better variable names in code - - move all code to .cpp + + +#### Could + +- optimize code where possible + - low priority +- move all code to .cpp +- change output format to confirm standard 4°12'14.1234" + +#### Wont diff --git a/examples/Angle_performance/Angle_performance.ino b/examples/Angle_performance/Angle_performance.ino new file mode 100644 index 0000000..d7b0aee --- /dev/null +++ b/examples/Angle_performance/Angle_performance.ino @@ -0,0 +1,268 @@ +// +// FILE: Angle_performance.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo sketch to test angle class +// URL: https://github.com/RobTillaart/Angle.git +// + + +#include "Angle.h" + + +Angle a(1, 2, 3, 4); +Angle b(45, 30); +Angle c(2, 3, 4, 5); +Angle n(0); +Angle z(5.5); + +Angle aa(-1, 2, 3, 45); +Angle bb(0, -2, 3, 45); +Angle cc(0, 0, -3, 45); +Angle dd(0, 0, 0, -45); + +uint32_t start, stop; + + +void testConstructors() +{ + Serial.println(__FUNCTION__); + char str1[] = "-45.987654321"; + + delay(100); + start = micros(); + Angle s(str1); + stop = micros(); + Serial.println(stop - start); + Serial.println(s); + + delay(100); + start = micros(); + Angle t = str1; + stop = micros(); + Serial.println(stop - start); + Serial.println(t); + + Serial.println(); +} + + +void testToDouble() +{ + Serial.println(__FUNCTION__); + + delay(100); + start = micros(); + float s = a.toDouble(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + delay(100); + start = micros(); + s = aa.toDouble(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + delay(100); + start = micros(); + aa.fromRadians(2 * PI); + stop = micros(); + Serial.println(stop - start); + Serial.println(aa); + + Serial.println(); +} + + +void testParts() +{ + Serial.println(__FUNCTION__); + + delay(100); + start = micros(); + float s = c.sign(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + delay(100); + start = micros(); + s = c.degree(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + delay(100); + start = micros(); + s = c.minute(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + delay(100); + start = micros(); + s = c.second(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + delay(100); + start = micros(); + s = c.tenthousand(); + stop = micros(); + Serial.println(stop - start); + Serial.println(s, 7); + + Serial.println(); +} + + +void testCompare() +{ + Serial.println(__FUNCTION__); + + delay(100); + start = micros(); + bool b = (a == a); + stop = micros(); + Serial.println(stop - start); + Serial.println(b); + + + Serial.println(); +} + + +void testNegate() +{ + Serial.println(__FUNCTION__); + + delay(100); + start = micros(); + a = -a; + stop = micros(); + Serial.println(stop - start); + Serial.println(b); + + Serial.println(); +} + + +void testAdd() +{ + Serial.println(__FUNCTION__); + + delay(100); + start = micros(); + Angle d = a + b; + stop = micros(); + Serial.println(stop - start); + Serial.println(d); + + float rnd = random(36000) / 100.0 - 180; + delay(100); + start = micros(); + d = a + rnd; + stop = micros(); + Serial.println(stop - start); + Serial.println(d); + + Serial.println(); +} + + +void testMultiply() +{ + Serial.println(__FUNCTION__); + + a = 5.25; + delay(100); + start = micros(); + a = a * 5.5; + stop = micros(); + Serial.println(stop - start); + Serial.println(a); + + float rnd = random(36000) / 100.0 - 180; + delay(100); + start = micros(); + a = a * rnd; + stop = micros(); + Serial.println(stop - start); + Serial.println(a); + + Serial.println(); +} + + + + +void testDivide() +{ + Serial.println(__FUNCTION__); + + a = 5.25; + delay(100); + start = micros(); + a = a / 5.5; + stop = micros(); + Serial.println(stop - start); + Serial.println(a); + + float rnd = random(36000) / 100.0 - 180; + delay(100); + start = micros(); + a = a / rnd; + stop = micros(); + Serial.println(stop - start); + Serial.println(a); + + Serial.println(); +} + + +void testRatio() +{ + Serial.println(__FUNCTION__); + + a = 7.50; + b = 57.456789; + delay(100); + start = micros(); + float s = a / b; + stop = micros(); + Serial.println(stop - start); + Serial.println(s); + + Serial.println(); +} + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("ANGLE_LIB_VERSION: "); + Serial.println(ANGLE_LIB_VERSION); + + testConstructors(); + testToDouble(); + testParts(); + testNegate(); + testCompare(); + testAdd(); + testMultiply(); + testDivide(); + testRatio(); + + Serial.println("\nDone..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/examples/Angle_performance/performance_0.1.14.txt b/examples/Angle_performance/performance_0.1.14.txt new file mode 100644 index 0000000..48b8c06 --- /dev/null +++ b/examples/Angle_performance/performance_0.1.14.txt @@ -0,0 +1,63 @@ +Arduino UNO +IDE 1.8.19 + +Angle_performance.ino +ANGLE_LIB_VERSION: 0.1.14 +testConstructors +212 +-45.59'15"5555 +220 +-45.59'15"5555 + +testToDouble +40 +1.0341668 +40 +-1.0341678 +164 +360.00'00"0000 + +testParts +4 +1.0000000 +8 +2.0000000 +8 +3.0000000 +8 +4.0000000 +8 +5.0000000 + +testNegate +12 +45.30'00"0000 + +testCompare +4 +1 + +testAdd +52 +44.27'56"9996 +272 +-12.57'50"9740 + +testMultiply +216 +28.52'30"0000 +300 +360.38'56"0230 + +testDivide +236 +0.57'16"3636 +312 +0.01'24"3694 + +testRatio +96 +0.13 + + +Done... diff --git a/library.json b/library.json index 77fb759..e220d49 100644 --- a/library.json +++ b/library.json @@ -20,7 +20,7 @@ "type": "git", "url": "https://github.com/RobTillaart/Angle.git" }, - "version": "0.1.13", + "version": "0.1.14", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index a633ca9..b94e9ea 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Angle -version=0.1.13 +version=0.1.14 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library to convert between floating point angle to minutes hours representation. diff --git a/test/unit_test_001.cpp b/test/unit_test_001.cpp index 961cd19..dbd0072 100644 --- a/test/unit_test_001.cpp +++ b/test/unit_test_001.cpp @@ -42,6 +42,7 @@ unittest_setup() fprintf(stderr, "ANGLE_LIB_VERSION: %s\n", (char *) ANGLE_LIB_VERSION); } + unittest_teardown() { } @@ -131,7 +132,7 @@ unittest(test_Radians) } -// mainly tests if operators still work, not a quality test (yet) +// mainly tests if operators still work, not a quality test (yet) unittest(test_math) { Angle a(1, 2, 3, 4); @@ -182,4 +183,6 @@ unittest(test_compare) unittest_main() -// -------- + +// -- END OF FILE -- +