0.1.14 Angle

This commit is contained in:
rob tillaart 2023-01-31 15:29:30 +01:00
parent 203420f91d
commit 1b628ab9bf
13 changed files with 398 additions and 29 deletions

View File

@ -6,7 +6,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

View File

@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:

View File

@ -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; }

View File

@ -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;

View File

@ -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

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2015-2022 Rob Tillaart
Copyright (c) 2015-2023 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -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
#### Should
- Test normalize code
- unit tests, sketch?
- test more
- optimize code where possible
- performance sketch
- 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

View File

@ -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 --

View File

@ -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...

View File

@ -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": "*",

View File

@ -1,5 +1,5 @@
name=Angle
version=0.1.13
version=0.1.14
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library to convert between floating point angle to minutes hours representation.

View File

@ -42,6 +42,7 @@ unittest_setup()
fprintf(stderr, "ANGLE_LIB_VERSION: %s\n", (char *) ANGLE_LIB_VERSION);
}
unittest_teardown()
{
}
@ -182,4 +183,6 @@ unittest(test_compare)
unittest_main()
// --------
// -- END OF FILE --