2023-05-03 22:50:46 +02:00
|
|
|
#include "vector2D.h"
|
|
|
|
#include <num/num.h>
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
libnum::num32 sqrt_num32(libnum::num32 v) {
|
|
|
|
uint32_t t, q, b, r;
|
|
|
|
r = v.v;
|
|
|
|
b = 0x40000000;
|
|
|
|
q = 0;
|
|
|
|
while (b > 0x40) {
|
|
|
|
t = q + b;
|
|
|
|
if (r >= t) {
|
|
|
|
r -= t;
|
|
|
|
q = t + b;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
2023-05-26 18:14:13 +02:00
|
|
|
r <<= 1;
|
|
|
|
b >>= 1;
|
|
|
|
}
|
|
|
|
q >>= 8;
|
|
|
|
libnum::num32 ret;
|
|
|
|
ret.v = q;
|
|
|
|
return ret;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D::Vector2D() {
|
|
|
|
this->x = libnum::num32(0);
|
|
|
|
this->y = libnum::num32(0);
|
2023-05-03 22:50:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D::Vector2D(float x, float y) {
|
|
|
|
this->x = libnum::num32(x);
|
|
|
|
this->y = libnum::num32(y);
|
2023-05-03 22:50:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D::Vector2D(libnum::num32 x, libnum::num32 y) {
|
|
|
|
this->x = x;
|
|
|
|
this->y = y;
|
2023-05-03 22:50:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D::Vector2D(const Vector2D &v) {
|
|
|
|
this->x = v.x;
|
|
|
|
this->y = v.y;
|
2023-05-24 22:28:26 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D::~Vector2D() {}
|
2023-05-22 00:26:08 +02:00
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D Vector2D::Clone(void) {
|
|
|
|
Vector2D NewVector(this->x, this->y);
|
|
|
|
return NewVector;
|
2023-05-03 22:50:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D Vector2D::MakeVector(Vector2D A, Vector2D B) {
|
|
|
|
Vector2D NewVector(B.x - A.x, B.y - A.y);
|
|
|
|
return NewVector;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
void Vector2D::AddVectors(Vector2D a, Vector2D b) {
|
|
|
|
this->x = a.x + b.x;
|
|
|
|
this->y = a.y + b.y;
|
2023-05-22 22:54:49 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
void Vector2D::Add(Vector2D v, libnum::num32 scale) {
|
|
|
|
this->x += v.x * scale;
|
|
|
|
this->y += v.y * scale;
|
2023-05-03 22:50:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
void Vector2D::SubtractVectors(Vector2D a, Vector2D b) {
|
|
|
|
this->x = a.x - b.x;
|
|
|
|
this->y = a.y - b.y;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
void Vector2D::Subtract(Vector2D v, libnum::num32 scale) {
|
|
|
|
this->x -= v.x * scale;
|
|
|
|
this->y -= v.y * scale;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
libnum::num32 Vector2D::Length(void) {
|
|
|
|
return sqrt_num32(this->x * this->x + this->y * this->y);
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
void Vector2D::Scale(libnum::num32 scale) {
|
|
|
|
this->x *= scale;
|
|
|
|
this->y *= scale;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
libnum::num32 Vector2D::Dot(Vector2D v) {
|
|
|
|
return (this->x * v.x + this->y * v.y);
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
libnum::num32 Vector2D::Det(Vector2D v) {
|
|
|
|
return (this->x * v.y - this->y * v.x);
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D Vector2D::PerpCW(void) {
|
|
|
|
Vector2D temp(-this->y, this->x);
|
|
|
|
return temp;
|
2023-05-24 22:28:26 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Vector2D Vector2D::PerpCCW(void) {
|
|
|
|
Vector2D temp(this->y, -this->x);
|
|
|
|
return temp;
|
2023-05-06 22:35:15 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Border::Border() {}
|
2023-05-06 22:35:15 +02:00
|
|
|
|
2023-05-26 18:14:13 +02:00
|
|
|
Border::~Border() {}
|