From 53004c3f042bbacd06e82c2ca774ca5b9d136ab4 Mon Sep 17 00:00:00 2001 From: xchaos Date: Sat, 16 Aug 2008 20:27:45 +0000 Subject: [PATCH] #3 improvement of objects-sample.c git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@78 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- demos/objects/objects-sample.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/demos/objects/objects-sample.c b/demos/objects/objects-sample.c index e0e8914..6b222fd 100644 --- a/demos/objects/objects-sample.c +++ b/demos/objects/objects-sample.c @@ -11,7 +11,7 @@ def_mem(Interface) str method(desc) (Shape self); void method(rename) (Shape self, str name); void method(reset) (Shape self, int x1, int y1, int x2, int y2, int x3, int y3); - int method(area) (Shape self); + float method(area) (Shape self); int count; }; @@ -110,32 +110,44 @@ void moveCirc(Shape community, int x, int y) str descTri(Shape community) { - return ""; + I_am(Tri); + + return self->name; } str descRect(Shape community) { - return ""; + I_am(Rect); + + return self->desc; } str descCirc(Shape community) { - return ""; + I_am(Circ); + + return self->comment; } -int calcAreaTri(Shape community) +float calcAreaTri(Shape community) { + I_am(Tri); + return 0; } -int calcAreaRect(Shape community) +float calcAreaRect(Shape community) { - return 0; + I_am(Rect); + + return (self->x2-self->x1)*(self->y2-self->y1); } -int calcAreaCirc(Shape community) +float calcAreaCirc(Shape community) { - return 0; + I_am(Circ); + + return 3.14159*self->r*self->r; } void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3) @@ -274,7 +286,7 @@ program append(one, all); one = get_mem(Object_list); - one->object = get_obj_as(Shape, Circ, circles, 10, 0, 5); + one->object = get_obj_as(Shape, Circ, circles, 0, 10, 1); append(one, all); printf("We have created %d triangles, %d rectangles and %d circles:\n", @@ -283,7 +295,7 @@ program for_each(one, all) { _(draw, one->object); - printf("Area of this %s is %d (square pixels).\n", _(desc, one->object), _(area, one->object)); + printf("Area of this %s is %f (square pixels).\n", _(desc, one->object), _(area, one->object)); printf("We have created %d instances of this type of object.\n", interface_of(one->object)->count); if(interface_of(one->object) == rectangles) -- 2.30.2