summaryrefslogtreecommitdiff
path: root/includes/point.c
diff options
context:
space:
mode:
authorJonas Kohl <gitlab@jonaskohl.de>2024-08-29 17:00:11 +0200
committerJonas Kohl <gitlab@jonaskohl.de>2024-08-29 17:00:11 +0200
commit84ad096896e9948c722a957d07ed6868e252a9f7 (patch)
treeb8ad1afadd89f1dc7599436cfb0f7f5fb0c177b6 /includes/point.c
Initial commit
Diffstat (limited to 'includes/point.c')
-rw-r--r--includes/point.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/includes/point.c b/includes/point.c
new file mode 100644
index 0000000..a68fcf2
--- /dev/null
+++ b/includes/point.c
@@ -0,0 +1,31 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "point.h"
+
+#define TYPE Point
+
+DEFINE_OBJECT_STRUCTURE(TYPE) {
+ float x;
+ float y;
+};
+
+CONSTRUCTOR_IMPLEMENT(TYPE);
+
+void METHOD_ARG(TYPE, init, float x, float y) {
+ CATCH_SELF_NULL(TYPE_init);
+ self->x = x;
+ self->y = y;
+}
+
+int METHOD_ARG(TYPE, toString, char* buffer) {
+ CATCH_SELF_NULL(TYPE_toString);
+ return sprintf(buffer, NAMEOF(TYPE) " { x = %.2f, y = %.2f }", self->x, self->y);
+}
+
+GETTER_IMPLEMENT(TYPE, float, x);
+SETTER_IMPLEMENT(TYPE, float, x);
+
+GETTER_IMPLEMENT(TYPE, float, y);
+SETTER_IMPLEMENT(TYPE, float, y);
+
+#undef TYPE