mirror of
https://github.com/aclist/dztui.git
synced 2026-08-31 12:16:55 +02:00
Compare commits
5 Commits
abd2e0e369
...
c594c944bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c594c944bc | ||
|
|
c8e9f8f1fc | ||
|
|
e73617c2f4 | ||
|
|
67b0559058 | ||
|
|
dfe65aacd4 |
@ -15,6 +15,7 @@
|
||||
|
||||
## Changed
|
||||
- Optimize time cost of setup checks
|
||||
- Location of notes file
|
||||
|
||||
## [6.0.0-beta.7] 2025-09-20
|
||||
## Added
|
||||
|
||||
2
dzgui.sh
2
dzgui.sh
@ -618,7 +618,7 @@ fetch_helpers_by_sum(){
|
||||
["funcs"]="6ae3ead7034dc8e7543472bddee75c63"
|
||||
["query_v2.py"]="55d339ba02512ac69de288eb3be41067"
|
||||
["servers.py"]="ed442c3aecf33f777d59dcf53650d263"
|
||||
["ui.py"]="f03879f088ad074f2ce3c92607c30202"
|
||||
["ui.py"]="8d05bbd7b8e15a97fae568e9a3dbf4d6"
|
||||
["vdf2json.py"]="2f49f6f5d3af919bebaab2e9c220f397"
|
||||
["pefile.py"]="21531f2c0d9dfa5f110cf6779f9d22c0"
|
||||
)
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define R 6371
|
||||
#define TO_RAD (3.1415926536 / 180)
|
||||
double dist(double th1, double ph1, double th2, double ph2)
|
||||
{
|
||||
double dx, dy, dz;
|
||||
ph1 -= ph2;
|
||||
ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD;
|
||||
|
||||
dz = sin(th1) - sin(th2);
|
||||
dx = cos(ph1) * cos(th1) - cos(th2);
|
||||
dy = sin(ph1) * cos(th1);
|
||||
return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R;
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
if(argc < 5 || argc > 5){
|
||||
return 1;
|
||||
}
|
||||
float coords[4];
|
||||
for(int i=1;i<5;i++){
|
||||
if(atof(argv[i]) == 0){
|
||||
return 1;
|
||||
}
|
||||
coords[i] = atof(argv[i]);
|
||||
}
|
||||
|
||||
double d = dist(coords[1], coords[2], coords[3], coords[4]);
|
||||
printf("%.1f\n", d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
helpers/tools/.gitignore
vendored
Normal file
1
helpers/tools/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
latlon
|
||||
24
helpers/tools/Makefile
Normal file
24
helpers/tools/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
bin := latlon
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wextra
|
||||
CFLAGS += -Wpedantic
|
||||
CFLAGS += -std=c23
|
||||
CFLAGS += -O3
|
||||
|
||||
LDFLAGS += -lm
|
||||
|
||||
PREFIX ?= $(HOME)/.local/share/dzgui
|
||||
|
||||
all: $(bin)
|
||||
|
||||
install: $(bin)
|
||||
install -Dm 755 $(bin) $(PREFIX)
|
||||
|
||||
$(bin): latlon.c
|
||||
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(bin)
|
||||
74
helpers/tools/latlon.c
Normal file
74
helpers/tools/latlon.c
Normal file
@ -0,0 +1,74 @@
|
||||
// This small program computes the distance between two points on the Earths
|
||||
// surface. The algorithm used for computing is called haversine formula.
|
||||
// Source for the algorithm can be found here:
|
||||
// https://en.wikipedia.org/wiki/Haversine_formula
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Earths radius in meters
|
||||
#define RADIUS ((12756L / 2.0L) * 1000L)
|
||||
|
||||
// PI natural constant
|
||||
#define PI 3.1415926536L
|
||||
|
||||
// coordinates struct for storing points
|
||||
struct Coordinate {
|
||||
double latitude;
|
||||
double longitude;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Calculates a radian value from an angle
|
||||
*/
|
||||
double radian_from(const double angle) {
|
||||
return (angle * PI) / 180;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate the haversine function from an angle in radian
|
||||
*/
|
||||
double haversine(const double angle) { return ((1.0L - cos(angle)) / 2); }
|
||||
|
||||
/**
|
||||
* @brief Calculate the distance between two coordinates
|
||||
*/
|
||||
double great_circle_distance(const struct Coordinate a,
|
||||
const struct Coordinate b) {
|
||||
|
||||
// calculate longitude and latitude differences
|
||||
struct Coordinate diff_coord = {
|
||||
.longitude = a.longitude - b.longitude,
|
||||
.latitude = a.latitude - b.latitude,
|
||||
};
|
||||
|
||||
// calculate haversine(theta) value, where theta is the angle between the
|
||||
// two coordinates
|
||||
double hav_theta = haversine(diff_coord.latitude)
|
||||
+ cos(a.latitude) * cos(b.latitude) * haversine(diff_coord.longitude);
|
||||
|
||||
// calculate distance from radius, and haversine(theta) values
|
||||
double distance = 2 * RADIUS * asin(sqrt(hav_theta));
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
if (argc < 5 || argc > 5) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const struct Coordinate a = {
|
||||
.latitude = radian_from(atof(argv[1])),
|
||||
.longitude = radian_from(atof(argv[2])),
|
||||
};
|
||||
const struct Coordinate b = {
|
||||
.latitude = radian_from(atof(argv[3])),
|
||||
.longitude = radian_from(atof(argv[4])),
|
||||
};
|
||||
|
||||
printf("%.1f\n", great_circle_distance(a, b));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -78,7 +78,7 @@ servers_path = f"{cache_path}/{app_name_abbr}.servers"
|
||||
config_path = f"{user_path}/.config/dztui"
|
||||
config_file = f"{config_path}/dztuirc"
|
||||
history_file = f"{state_path}/{app_name_abbr}.history"
|
||||
notes_file = f"{state_path}/{app_name_abbr}.notes.json"
|
||||
notes_file = f"{config_path}/{app_name_abbr}.notes.json"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
log_file = f"{log_path}/{app_name}_DEBUG.log"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user