#3 improvement of objects-sample.c
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Sat, 16 Aug 2008 20:27:45 +0000 (20:27 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Sat, 16 Aug 2008 20:27:45 +0000 (20:27 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@78 4bb87942-c103-4e5a-b51c-0ebff58f8515

demos/objects/objects-sample.c

index e0e8914280ae82eb4efa715b6190f455adcbf06f..6b222fd7f71355fb7def48c7f55f77516751ff33 100644 (file)
@@ -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)
This page took 0.234184 seconds and 4 git commands to generate.