void drawTri(Shape community)
{
- I_am(Tri);
+ I_am(self, Tri);
printf("Drawing %s: %d,%d - %d,%d - %d,%d .\n",
self->name, self->x1, self->y1, self->x2, self->y2, self->x3, self->y3);
void drawRect(Shape community)
{
- I_am(Rect);
+ I_am(self, Rect);
printf("Drawing %s: %d,%d - %d,%d .\n",
self->desc, self->x1, self->y1, self->x2, self->y2);
void drawCirc(Shape community)
{
- I_am(Circ);
+ I_am(self, Circ);
printf("Drawing %s: %d,%d - r=%d .\n",
self->comment, self->x1, self->y1, self->r);
void moveTri(Shape community, int x, int y)
{
- I_am(Tri);
+ I_am(self, Tri);
self->x1 += x;
self->y1 += y;
void moveRect(Shape community, int x, int y)
{
- I_am(Rect);
+ I_am(self, Rect);
self->x1 += x;
self->y1 += y;
void moveCirc(Shape community, int x, int y)
{
- I_am(Circ);
+ I_am(self, Circ);
self->x1 += x;
self->y1 += y;
str descTri(Shape community)
{
- I_am(Tri);
+ I_am(self, Tri);
return self->name;
}
str descRect(Shape community)
{
- I_am(Rect);
+ I_am(self, Rect);
return self->desc;
}
str descCirc(Shape community)
{
- I_am(Circ);
+ I_am(self, Circ);
return self->comment;
}
float calcAreaTri(Shape community)
{
- I_am(Tri);
+ I_am(self, Tri);
return 0;
}
float calcAreaRect(Shape community)
{
- I_am(Rect);
+ I_am(self, Rect);
- return (self->x2-self->x1)*(self->y2-self->y1);
+ return (self->x2 - self->x1)*(self->y2 - self->y1);
}
float calcAreaCirc(Shape community)
{
- I_am(Circ);
+ I_am(self, Circ);
- return 3.14159*self->r*self->r;
+ return PI * self->r * self->r;
}
void setTri(Shape community, int x1, int y1, int x2, int y2, int x3, int y3)
{
- I_am(Tri);
+ I_am(self, Tri);
self->x1 = x1;
self->y1 = y1;
void setRect(Shape community, int x1, int y1, int x2, int y2, int dummy1, int dummy2)
{
- I_am(Rect);
+ I_am(self, Rect);
self->x1 = x1;
self->y1 = y1;
void setCirc(Shape community, int x1, int y1, int r, int dummy1, int dummy2, int dummy3)
{
- I_am(Circ);
+ I_am(self, Circ);
self->x1 = x1;
self->y1 = y1;
void nameRect(Shape community, str name)
{
- I_am(Rect);
+ I_am(self, Rect);
self->desc = name;
}
/* Example of using object interface methods from inside constructor methods */
-construct(Tri) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3)
+construct(Tri,Interface) (Tri self, int x1, int y1, int x2, int y2, int x3, int y3)
{
self->name = "TRIANGLE";
interface_of(self)->count++;
return self;
}
-construct(Rect) (Rect self, int x1, int y1, int x2, int y2)
+construct(Rect,Interface) (Rect self, int x1, int y1, int x2, int y2)
{
self->desc = "rectangle";
interface_of(self)->count++;
return self;
}
-construct(Circ) (Circ self, int x1, int y1, int r)
+construct(Circ,Interface) (Circ self, int x1, int y1, int r)
{
self->comment = "Circle";
interface_of(self)->count++;