#include "vector2D.h" #include 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; } r <<= 1; b >>= 1; } q >>= 8; libnum::num32 ret; ret.v = q; return ret; } Vector2D::Vector2D() { this->x = libnum::num32(0); this->y = libnum::num32(0); } Vector2D::Vector2D(float x, float y) { this->x = libnum::num32(x); this->y = libnum::num32(y); } Vector2D::Vector2D(libnum::num32 x, libnum::num32 y) { this->x = x; this->y = y; } Vector2D::Vector2D(const Vector2D &v) { this->x = v.x; this->y = v.y; } Vector2D::~Vector2D() {} Vector2D Vector2D::Clone(void) { Vector2D NewVector(this->x, this->y); return NewVector; } Vector2D Vector2D::MakeVector(Vector2D A, Vector2D B) { Vector2D NewVector(B.x - A.x, B.y - A.y); return NewVector; } void Vector2D::AddVectors(Vector2D a, Vector2D b) { this->x = a.x + b.x; this->y = a.y + b.y; } void Vector2D::Add(Vector2D v, libnum::num32 scale) { this->x += v.x * scale; this->y += v.y * scale; } void Vector2D::SubtractVectors(Vector2D a, Vector2D b) { this->x = a.x - b.x; this->y = a.y - b.y; } void Vector2D::Subtract(Vector2D v, libnum::num32 scale) { this->x -= v.x * scale; this->y -= v.y * scale; } libnum::num32 Vector2D::Length(void) { return sqrt_num32(this->x * this->x + this->y * this->y); } void Vector2D::Scale(libnum::num32 scale) { this->x *= scale; this->y *= scale; } libnum::num32 Vector2D::Dot(Vector2D v) { return (this->x * v.x + this->y * v.y); } libnum::num32 Vector2D::Det(Vector2D v) { return (this->x * v.y - this->y * v.x); } Vector2D Vector2D::PerpCW(void) { Vector2D temp(-this->y, this->x); return temp; } Vector2D Vector2D::PerpCCW(void) { Vector2D temp(this->y, -this->x); return temp; } Border::Border() {} Border::~Border() {}