commit e2b64b8fe8a8ea161c376bd22ae4a14f1550863f
parent b9a8f304d0a16434188b379e9abd5410c0d3b301
Author: hhvn <dev@hhvn.uk>
Date: Tue, 6 Dec 2022 17:29:15 +0000
Move vector functions to coords.c
Diffstat:
4 files changed, 20 insertions(+), 23 deletions(-)
diff --git a/src/coords.c b/src/coords.c
@@ -18,6 +18,20 @@ vectorize_at(Vector at, Polar p) {
};
}
+Vector
+vector_diff(Vector a, Vector b) {
+ return (Vector){
+ fabsf(a.x - b.x),
+ fabsf(a.y - b.y)
+ };
+}
+
+float
+vector_dist(Vector a, Vector b) {
+ Vector d = vector_diff(a, b);
+ return hypotf(d.x, d.y);
+}
+
Polar
polarize(Vector v) {
return (Polar) {
diff --git a/src/main.h b/src/main.h
@@ -73,6 +73,8 @@ void editins(wchar_t *str, int *len, int *cur, int size, wchar_t c);
/* coords.c */
Vector vectorize(Polar p);
Vector vectorize_at(Vector at, Polar p);
+Vector vector_diff(Vector a, Vector b);
+float vector_dist(Vector a, Vector b);
Polar polarize(Vector v);
Polar polarize_at(Vector at, Vector vector);
Polar polar_add(Polar abs, Polar rel);
@@ -131,8 +133,6 @@ void ui_draw_circle(int x, int y, float r, Color col);
void ui_draw_line(int sx, int sy, int ex, int ey, float thick, Color col);
void ui_draw_line_v(Vector start, Vector end, float thick, Color col);
void ui_draw_tabbed_window(int x, int y, int w, int h, Tabs *tabs);
-Vector ui_vectordiff(Vector a, Vector b);
-float ui_vectordist(Vector a, Vector b);
/* gui.c */
#define BUTTON_HEIGHT (PAD + FONT_SIZE)
diff --git a/src/ui.c b/src/ui.c
@@ -142,7 +142,7 @@ ui_onscreen(Vector point) {
int
ui_onscreen_ring(Vector centre, float r) {
- float d = ui_vectordist(centre, screen.centre);
+ float d = vector_dist(centre, screen.centre);
if (!pane_visible(centre.y - r, centre.y + r))
return 0;
@@ -274,23 +274,6 @@ ui_draw_border_around(int x, int y, int w, int h, int px) {
ui_draw_border(x - px, y - px, w + px * 2, h + px * 2, px);
}
-Vector
-ui_vectordiff(Vector a, Vector b) {
- float x = a.x - b.x;
- float y = a.y - b.y;
- if (x < 0)
- x *= -1;
- if (y < 0)
- y *= -1;
- return (Vector) {x, y};
-}
-
-float
-ui_vectordist(Vector a, Vector b) {
- Vector diff = ui_vectordiff(a, b);
- return sqrtf(diff.x * diff.x + diff.y * diff.y);
-}
-
void
ui_draw_tabbed_window(int x, int y, int w, int h, Tabs *tabs) {
ui_draw_rect(x, y, w, h, col_bg);
diff --git a/src/views/main.c b/src/views/main.c
@@ -152,7 +152,7 @@ draw_orbit(Body *body) {
return;
parent = kmtopx(body->parent->vector);
- pxrad = ui_vectordist(parent, body->pxloc);
+ pxrad = vector_dist(parent, body->pxloc);
if (pxrad < min_body_rad[body->parent->type])
return;
@@ -195,7 +195,7 @@ draw_body(Body *body) {
/ v->kmperpx < ui_textsize(body->name))
return;
if (body->parent && body->type != BODY_STAR &&
- ui_vectordist(body->vector, body->parent->vector) <
+ vector_dist(body->vector, body->parent->vector) <
min_body_rad[body->type] * v->kmperpx)
return;
if (isdigit(*body->name) || *body->name == '(') {
@@ -253,7 +253,7 @@ view_main_draw(void) {
if (v->ruler.held) {
ruler = kmtopx(v->ruler.origin);
ui_draw_line_v(ruler, mouse.vector, 1, col_info);
- dist = ui_vectordist(v->ruler.origin, mousekm);
+ dist = vector_dist(v->ruler.origin, mousekm);
ui_print(mouse.x + PAD, mouse.y - PAD, col_info, "%s (%s)", strkm(dist), strly(dist));
}