2018-03-08 00:58:26 +01:00
|
|
|
#include "vector2d.h"
|
|
|
|
|
|
|
|
bool
|
|
|
|
vector2d_equals(Vector2d v1, Vector2d v2)
|
|
|
|
{
|
|
|
|
return v1.x == v2.x && v1.y == v2.y;
|
2018-03-15 16:30:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
vector2d_is_opposite(Vector2d v1, Vector2d v2)
|
|
|
|
{
|
2018-03-16 10:04:43 +01:00
|
|
|
return ((v1.x > 0 && v2.x < 0) ^ (v1.y > 0 && v2.y < 0))
|
|
|
|
|| ((v1.x < 0 && v2.x > 0) ^ (v1.y < 0 && v2.y > 0));
|
2018-03-15 16:30:41 +01:00
|
|
|
}
|
2019-05-14 15:57:36 +02:00
|
|
|
|
2019-05-15 20:32:48 +02:00
|
|
|
void
|
|
|
|
vector2d_reverse(Vector2d *vec)
|
|
|
|
{
|
|
|
|
vec->x *= -1;
|
|
|
|
vec->y *= -1;
|
|
|
|
}
|
|
|
|
|
2019-05-14 15:57:36 +02:00
|
|
|
Vector2d
|
|
|
|
vector2d_to_direction(const Vector2d *vec)
|
|
|
|
{
|
|
|
|
Vector2d new = VEC2D(vec->x, vec->y);
|
|
|
|
|
|
|
|
if (new.x > 0)
|
|
|
|
new.x = 1;
|
2020-07-11 10:16:57 +02:00
|
|
|
else if (new.x < 0)
|
2019-05-14 15:57:36 +02:00
|
|
|
new.x = -1;
|
|
|
|
|
|
|
|
if (new.y > 0)
|
|
|
|
new.y = 1;
|
2020-07-11 10:16:57 +02:00
|
|
|
else if (new.y < 0)
|
2019-05-14 15:57:36 +02:00
|
|
|
new.y = -1;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|