summaryrefslogtreecommitdiff
path: root/src/math/vec2.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-12-04 00:07:32 +0800
committerchai <chaifix@163.com>2019-12-04 00:07:32 +0800
commit2e82e2ddd0852b8063a3d6645366f53ee844e273 (patch)
tree41ec10760f2d2c9f1f782a918f48e1287da2a4b4 /src/math/vec2.c
+init
Diffstat (limited to 'src/math/vec2.c')
-rw-r--r--src/math/vec2.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/math/vec2.c b/src/math/vec2.c
new file mode 100644
index 0000000..86192dc
--- /dev/null
+++ b/src/math/vec2.c
@@ -0,0 +1,36 @@
+#include "math.h"
+#include "../util/assert.h"
+#include "../core/mem.h"
+
+void vec2_scale(Vec2* v, float k, Vec2* out) {
+ ssr_assert(v && out);
+ out->x = v->x * k;
+ out->y = v->y * k;
+}
+
+void vec2_plus(Vec2* v1, Vec2* v2, Vec2* out) {
+ ssr_assert(v1 && v2 && out);
+ out->x = v1->x + v2->x;
+ out->y = v1->y + v2->y;
+}
+
+void vec2_offset(Vec2* v, float offset, Vec2* out) {
+ ssr_assert(v && out);
+ out->x = v->x + offset;
+ out->y = v->y + offset;
+}
+
+float vec2_dot(Vec2* v1, Vec2* v2) {
+ ssr_assert(v1 && v2);
+ float d = v1->x * v2->x + v1->y * v2->y;
+ return d;
+}
+
+void vec2_tostring(Vec2* v, char buf[]) {
+ sprintf(buf, "%8.3f %8.3f", v->x, v->y);
+}
+
+void vec2_print(Vec2* v) {
+ vec2_tostring(v, printbuffer);
+ printf("%s", printbuffer);
+} \ No newline at end of file