diff options
Diffstat (limited to 'includes/point.c')
-rw-r--r-- | includes/point.c | 31 |
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 |