Skip to content

Commit

Permalink
Calculate on the go
Browse files Browse the repository at this point in the history
  • Loading branch information
Wetitpig committed Sep 5, 2020
1 parent 5d39109 commit 5d1d33d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
1 change: 1 addition & 0 deletions include/geodesic.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Vector {
};

long double sqr(long double operand);
long double double_fac(int x);
long double atan2_modified(long double y, long double x);
long double normalise_a(long double x);
long double normalise_c(long double x);
Expand Down
13 changes: 13 additions & 0 deletions src/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ long double sqr(long double operand)
return operand * operand;
}

long double double_fac(int x)
{
if (x == -3)
return -1;
else {
long double y = 1;
while (x > 0) {
y *= x;
x -= 2;
}
return y;
}
}

long double atan2_modified(long double y, long double x)
{
Expand Down
15 changes: 1 addition & 14 deletions src/mpblock.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
#include <math.h>
#include "math.h"
#include "io.h"
#include "mpblock.h"

long double double_fac(int x)
{
if (x == -3)
return -1;
else {
long double y = 1;
while (x > 0) {
y *= x;
x -= 2;
}
return y;
}
}

int isblock(struct Coordinates *vertex)
{
int block = 1;
Expand Down
8 changes: 2 additions & 6 deletions src/vincenty.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "geodesic.h"
#include "vincenty.h"

const long double Alookup[5] = {25.0l/16384.0l, 1.0l/256.0l, 1.0l/64.0l, 1.0l/4.0l, 1.0l};

const long double Blookup[8][4] = {
{-1.0l/2.0l,3.0l/16.0l,-1.0l/32.0l,19.0l/2048.0l},
{-1.0l/16.0l,1.0l/32.0l,-9.0l/2048.0l,7.0l/4096.0l},
Expand Down Expand Up @@ -64,10 +62,8 @@ long double helmertA(long double calp)
usq = calp * ECC2;
k1 = sqrtl(1.0l + usq);
k1 = (k1 - 1.0l) / (k1 + 1.0l);
for (k = 0; k < 5; k++) {
A *= sqr(k1);
A += Alookup[k];
}
for (k = 0; k < 11; k++)
A += sqr(double_fac(2 * k - 3) / double_fac(2 * k) * powl(k1, k));
A /= (1 - k1);
return A;
}
Expand Down

0 comments on commit 5d1d33d

Please sign in to comment.