Skip to content

Commit

Permalink
add changelog.md (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Oct 29, 2022
1 parent 28a23a9 commit 4118e5a
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 64 deletions.
21 changes: 19 additions & 2 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
Expand All @@ -7,5 +22,7 @@ compile:
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560
- esp8266
# - mega2560
- rpipico

88 changes: 40 additions & 48 deletions Angle.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
//
// FILE: Angle.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.12
// VERSION: 0.1.13
// 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 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
// 0.1.05 added AngleFormat proxy added 03/03/15 by Christoper Andrews.
// 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.10 2021-01-16 readme.md + minor refactor
// 0.1.11 2021-10-17 update build-CI,
// 0.1.12 2021-12-12 update library.json, license, minor edits

// HISTORY: see changelog.md


#include "Angle.h"
Expand All @@ -38,23 +24,25 @@ 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)
{
neg = false;
d = dd;
m = mm;
s = ss;
t = tt;
// TODO
// normalize();
// assume only one (largest) parameter is negative at most...
// TODO
// normalize();
// assume only one (largest) parameter is negative at most...
if (d < 0) { d = -d; neg = true; }
if (m < 0) { m = -m; neg = true; }
if (s < 0) { s = -s; neg = true; }
if (t < 0) { t = -t; neg = true; }
// modulo might be faster
while (t >= 10000) { s++; t -= 10000; }
while (s >= 60) { m++; s -= 60; }
while (m >= 60) { d++; m -= 60; }
// check special case 0
if (d == 0 && m == 0 && s == 0 && t == 0) neg = false;
}

Expand All @@ -67,18 +55,20 @@ Angle::Angle(const double alpha)

d = int(a);
a = a - d;
// unsigned long p = a * 3600000L;
// 3600 000 = 2^7 • 3^2 • 5^5 = 128 * 28125
// 2^7 = 128 will only affect exponent - no loss precision
// 28125 is less digits so less loss of significant digits.
// upgraded to 4 decimal seconds
// 36 000 000L = 256 * 140625
// unsigned long p = a * 3600000L;
// 3600 000 = 2^7 • 3^2 • 5^5 = 128 * 28125
// 2^7 = 128 will only affect exponent - no loss precision
// 28125 is less digits so less loss of significant digits.
// upgraded to 4 decimal seconds
// 36 000 000L = 256 * 140625
a = a * 256;
unsigned long p = round(a * 140625.0);
t = p % 10000UL;
p = p / 10000UL;
s = p % 60UL;
m = p / 60UL;
// check special case 0
if (d == 0 && m == 0 && s == 0 && t == 0) neg = false;
}


Expand All @@ -87,26 +77,26 @@ Angle::Angle(const char * str)
uint32_t yy = 0;
uint8_t d_cnt = 0;
neg = false;
// parse whole degrees
// parse whole degrees
char *p = (char *) str;
d = 0;
// skip crap
// skip crap
while (!isdigit(*p) && (*p != '-')) p++;
// process sign
// process sign
if (*p == '-')
{
neg = true;
p++;
}
if (*p == '+') p++;
// parse whole part into degrees;
// parse whole part into degrees;
while (isdigit(*p))
{
d *= 10;
d += (*p - '0');
p++;
}
// parse decimal part into an uint32_t
// parse decimal part into an uint32_t
if (*p != '\0')
{
p++; // skip .
Expand All @@ -118,29 +108,31 @@ Angle::Angle(const char * str)
p++;
}
}
// make sure we have 9 decimal places.
// make sure we have 9 decimal places.
while (d_cnt < 9)
{
d_cnt++;
yy *= 10;
}
// convert float to degrees. 1000000000 ~> 36000000 -> /250 * 9
// yy = yy * 4 / 125 + yy / 250; // just keeps the maths within 32 bits
// convert float to degrees. 1000000000 ~> 36000000 -> /250 * 9
// yy = yy * 4 / 125 + yy / 250; // just keeps the maths within 32 bits
yy = yy * 4 / 125;
yy = yy + (yy + 4)/ 8; // just keeps the maths within 32 bits
// split yy in m, s, tt
yy = yy + (yy + 4)/ 8; // just keeps the maths within 32 bits
// split yy in m, s, tt
t = yy % 10000UL;
yy = yy / 10000UL;
s = yy % 60;
m = yy / 60;
// check special case 0
if (d == 0 && m == 0 && s == 0 && t == 0) neg = false;
}


// PRINTING
// PRINTING
size_t Angle::printTo(Print& p, AngleFormatMode mode) const
{
unsigned char c = mode;
char separator[4] = ".\'\""; // "..."; // ALT-0176 = ° 179.59.59.9999
char separator[4] = ".\'\""; // "..."; // ALT-0176 = ° 179.59.59.9999

size_t n = 0;
if (neg) n += p.print('-');
Expand Down Expand Up @@ -178,7 +170,7 @@ double Angle::toDouble(void)
}


// NEGATE
// NEGATE
Angle Angle::operator - ()
{
Angle temp = *this;
Expand All @@ -194,7 +186,7 @@ Angle Angle::operator - ()
};


// BASIC MATH
// BASIC MATH
Angle Angle::operator + (const Angle &a) // TOCHECK
{
return addHelper(a);
Expand Down Expand Up @@ -231,20 +223,20 @@ Angle Angle::addHelper(const Angle &a) // TOCHECK
}


Angle Angle::operator - (const Angle &a) // TOCHECK
Angle Angle::operator - (const Angle &a) // TOCHECK
{
return subHelper(a);
}


Angle& Angle::operator -= (const Angle &a) // TOCHECK
Angle& Angle::operator -= (const Angle &a) // TOCHECK
{
*this = subHelper(a);
return *this;
}


Angle Angle::subHelper(const Angle &a) // TOCHECK
Angle Angle::subHelper(const Angle &a) // TOCHECK
{
Angle temp = *this;
if (temp.neg == a.neg)
Expand Down Expand Up @@ -292,7 +284,7 @@ Angle& Angle::operator /= (const double dd)
}


// !! can divide by zero
// !! can divide by zero
double Angle::operator / (Angle& a)
{
double f = this->toDouble();
Expand All @@ -303,14 +295,14 @@ double Angle::operator / (Angle& a)

///////////////////////////////////////////////////////////
//
// PRIVATE
// PRIVATE
//
int Angle::compare(const Angle &a, const Angle &b)
{
// check sign first
// check sign first
if (!a.neg && b.neg) return 1;
if (a.neg && !b.neg) return -1;
// check abs value
// check abs value
int rv = 0;
if (a.d > b.d) rv = 1;
else if (a.d < b.d) rv = -1;
Expand All @@ -326,7 +318,7 @@ int Angle::compare(const Angle &a, const Angle &b)
}


void Angle::normalize() // TODO CHECK
void Angle::normalize() // TODO CHECK
{
while (t < 0) { s--; t += 10000; }
while (t >= 10000) { s++; t -= 10000; }
Expand Down
20 changes: 10 additions & 10 deletions Angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: Angle.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.12
// VERSION: 0.1.13
// PURPOSE: angle library for Arduino
// HISTORY: See angle.cpp
//
Expand All @@ -15,7 +15,7 @@
#include "Printable.h"


#define ANGLE_LIB_VERSION (F("0.1.12"))
#define ANGLE_LIB_VERSION (F("0.1.13"))


class Angle;
Expand Down Expand Up @@ -57,15 +57,15 @@ class Angle: public Printable
double toRadians() { return toDouble() * PI / 180.0; };
void fromRadians(double rad) { *this = rad * 180.0/PI; };

// EQUALITIES
// EQUALITIES
bool operator == (const Angle& a) { return compare(*this, a) == 0; };
bool operator != (const Angle& a) { return compare(*this, a) != 0; };
bool operator < (const Angle& a) { return compare(*this, a) < 0; };
bool operator <= (const Angle& a) { return compare(*this, a) <= 0; };
bool operator > (const Angle& a) { return compare(*this, a) > 0; };
bool operator >= (const Angle& a) { return compare(*this, a) >= 0; };

// NEGATE
// NEGATE
Angle operator - ();

Angle operator + (const Angle&);
Expand All @@ -80,7 +80,7 @@ class Angle: public Printable
Angle operator / (const double);
Angle& operator /= (const double);

double operator / (Angle&); // ratio
double operator / (Angle&); // ratio

private:
void normalize();
Expand All @@ -89,11 +89,11 @@ class Angle: public Printable
Angle addHelper(const Angle &a);
Angle subHelper(const Angle &a);

bool neg; // angle is negative
int d; // whole degrees
int m; // minutes
int s; // seconds
int t; // ten thousands
bool neg; // angle is negative
int d; // whole degrees
int m; // minutes
int s; // seconds
int t; // ten thousands
};


Expand Down
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Change Log Angle

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.1.13] - 2022-10-12
- Add RP2040 support to build-CI
- Add CHANGELOG.md
- minor change unit test
- minor edits (comments)
- Add zero tests to two constructors (zero is not negative)

## [0.1.12] - 2021-12-12
- update library.json
- update license
- minor edits

## [0.1.11] - 2021-10-17
- update build-CI

## [0.1.10] - 2021-01-16
- update readme.md
- minor refactor

## [0.1.9] - 2020-12-10
- Add build Arduino CI

## [0.1.8] - 2020-05-27
- update library.json

## [0.1.7] - 2020-03-26
- refactor #pragma once

## [0.1.06]
- fixed bug negative values

## [0.1.05] 2015-03-03
- added AngleFormat
- proxy added 03/03/15 by Christoper Andrews

## [0.1.04]
- changed thousands in tenthousands
- add string constructor

## [0.1.03]
- added URL
- fromRadians (test)

## [0.1.02]
- added toRadians()
- fix compare()

## [0.1.01]
- clean up a bit

## [0.1.00]
- initial version

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,10 @@ bugs. Especially the constructor does not check input so use it carefully.
- improve documentation
- test more
- optimize code where possible
- performance sketch
- improve code quality
- fix TODO in code
- use better variable names in code
- move all code to .cpp


Loading

0 comments on commit 4118e5a

Please sign in to comment.