interference/src/tools.c

19 lines
313 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
length(int x1, int y1, int x2, int y2)
{
const int dist_x = abs(x1 - x2);
2022-01-09 16:53:21 +01:00
const int dist_y = abs(y1 - y2);
2022-01-08 19:19:02 +01:00
const float dist = sqrt(dist_x * dist_x + dist_y * dist_y);
return dist;
}