interference/src/tools.c

19 lines
321 B
C
Raw Normal View History

2021-12-23 10:00:55 +01:00
#include "tools.h"
2022-01-08 19:19:02 +01:00
#include <math.h>
#include <stdlib.h>
2021-12-23 10:00:55 +01:00
int
sign(int x)
{
return (x > 0) - (x < 0); /* from jtmm2 */
}
2022-01-08 19:19:02 +01:00
int
2022-01-09 18:54:15 +01:00
length(struct Vec2 *a, struct Vec2 *b)
2022-01-08 19:19:02 +01:00
{
2022-01-09 18:54:15 +01:00
const int dist_x = abs(a->x - b->x);
const int dist_y = abs(a->y - b->y);
2022-01-08 19:19:02 +01:00
const float dist = sqrt(dist_x * dist_x + dist_y * dist_y);
return dist;
}