0.1.12 Angle

This commit is contained in:
rob tillaart 2021-12-13 13:48:16 +01:00
parent 33fc580c54
commit a4bea59866
7 changed files with 59 additions and 36 deletions

View File

@ -1,14 +1,14 @@
//
// FILE: Angle.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.11
// VERSION: 0.1.12
// PURPOSE: library for Angle math for Arduino
// URL: https://github.com/RobTillaart/Angle
// http://forum.arduino.cc/index.php?topic=339402
//
// HISTORY
// 0.1.00 initial version
// 0.1.01 cleanup a bit
// 0.1.01 clean up a bit
// 0.1.02 added toRadians() + fix compare()
// 0.1.03 added URL, fromRadians [TEST]
// 0.1.04 changed thousands in tenthousands, string constructor
@ -16,16 +16,21 @@
// 0.1.06 fixed bug negative values.
// 0.1.7 2020-03-26 refactor #pragma once
// 0.1.8 2020-05-27 update library.json
// 0.1.9 2020-12-10 Arduino ci
// 0.1.9 2020-12-10 Arduino CI
// 0.1.10 2021-01-16 readme.md + minor refactor
// 0.1.11 2021-10-17 update build-ci,
// 0.1.11 2021-10-17 update build-CI,
// 0.1.12 2021-12-12 update library.json, license, minor edits
#include "Angle.h"
AngleFormat::AngleFormat( const Angle &ref, AngleFormatMode format )
: angle(ref), mode(format) {}
: angle(ref), mode(format)
{
}
size_t AngleFormat::printTo(Print& p) const
{
@ -33,7 +38,7 @@ size_t AngleFormat::printTo(Print& p) const
}
Angle::Angle(int dd, int mm, int ss, int tt) // todo optimize
Angle::Angle(int dd, int mm, int ss, int tt) // TODO optimize
{
neg = false;
d = dd;
@ -77,13 +82,13 @@ Angle::Angle(const double alpha)
}
Angle::Angle(char * str)
Angle::Angle(const char * str)
{
uint32_t yy = 0;
uint8_t d_cnt = 0;
neg = false;
// parse whole degrees
char *p = str;
char *p = (char *) str;
d = 0;
// skip crap
while (!isdigit(*p) && (*p != '-')) p++;
@ -321,7 +326,7 @@ int Angle::compare(const Angle &a, const Angle &b)
}
void Angle::normalize() // TOCHECK
void Angle::normalize() // TODO CHECK
{
while (t < 0) { s--; t += 10000; }
while (t >= 10000) { s++; t -= 10000; }
@ -354,4 +359,5 @@ void Angle::normalize() // TOCHECK
if (d == 0 && m == 0 && s == 0 && t == 0) neg = false;
}
// --- END OF FILE ---

View File

@ -2,7 +2,7 @@
//
// FILE: Angle.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.11
// VERSION: 0.1.12
// PURPOSE: angle library for Arduino
// HISTORY: See angle.cpp
//
@ -15,7 +15,7 @@
#include "Printable.h"
#define ANGLE_LIB_VERSION (F("0.1.11"))
#define ANGLE_LIB_VERSION (F("0.1.12"))
class Angle;
@ -24,6 +24,7 @@ enum AngleFormatMode{
D = 1, M, S, T
};
struct AngleFormat : Printable{
AngleFormat( const Angle &ref, AngleFormatMode format );
@ -33,12 +34,13 @@ struct AngleFormat : Printable{
AngleFormatMode mode;
};
class Angle: public Printable
{
public:
Angle(int dd=0, int mm=0, int ss=0, int tt=0);
Angle(int dd = 0, int mm = 0, int ss = 0, int tt = 0);
Angle(double alpha);
Angle(char * str);
Angle(const char * str);
int sign() { return neg ? -1 : 1; };
int degree() { return d; };
@ -88,10 +90,12 @@ private:
Angle subHelper(const Angle &a);
bool neg; // angle is negative
int d; // whole degrees
int m; // minutes
int s; // seconds
int t; // tenhousands
int d; // whole degrees
int m; // minutes
int s; // seconds
int t; // ten thousands
};
// -- END OF FILE

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2015-2021 Rob Tillaart
Copyright (c) 2015-2022 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

@ -23,53 +23,62 @@ and comparisons ( == != < <= > >= ) are added to the class.
The library implements the Printable interface, allowing one to call
**Serial.println(angle)** or **SD.print(angle)**
**Serial.println(angle)** or **SD.print(angle)**.
## Interface
### Constructors
- **Angle(int dd=0, int mm=0, int ss=0, int tt=0)** create an Angle, default is zero.
- **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
- **int sign()** returns -1 or 1
- **int degree()** returns # degrees
- **int minute()** returns # minutes
- **int second()** returns # seconds
- **int tenthousand()** returns # ten-thousands of a second
- **int sign()** returns -1 or 1.
- **int degree()** returns # degrees.
- **int minute()** returns # minutes.
- **int second()** returns # seconds.
- **int tenthousand()** returns # ten-thousands of a second.
### 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)
- **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.
### Equality operators
The library supports equality operator "==", "!=", "<" "<=" ">" and ">="
The library supports equality operator "==", "!=", "<" "<=" ">" and ">=" .
### Math operators
- **negate** -angle
- **addition** and **subtract** add angles to angles
- **multiplication** and **division** multiply an angle with a double
- **ratio** ratio = Angle/Angle;
- **negate** returns -angle.
- **addition** and **subtract** add angles to angles.
- **multiplication** and **division** multiply an angle with a double.
- **ratio** ratio = Angle/Angle.
## Operation
See examples
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.
## Future
- improve documentation
- test more
- optimize code where possible

View File

@ -20,8 +20,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/Angle.git"
},
"version": "0.1.11",
"version": "0.1.12",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "Angle.h"
}

View File

@ -1,5 +1,5 @@
name=Angle
version=0.1.11
version=0.1.12
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

@ -45,8 +45,11 @@ unittest_teardown()
{
}
unittest(test_constructors)
{
fprintf(stderr, "ANGLE_LIB_VERSION: %s\n", (char *) ANGLE_LIB_VERSION);
Angle a(1, 2, 3, 4);
Angle b(-45, 30);
Angle n(0);