Browse Source

All units are complete and warnings removed.

develop
Kolan Sh 9 years ago
parent
commit
cf730f056d
6 changed files with 106 additions and 46 deletions
  1. +10
    -1
      Figure.c
  2. +2
    -2
      Makefile
  3. +28
    -14
      Polygon.c
  4. +8
    -3
      Polygon.h
  5. +55
    -23
      Rhomb.c
  6. +3
    -3
      Rhomb.h

+ 10
- 1
Figure.c View File

@ -4,14 +4,23 @@
void Figure_constructor (Figure *this)
{
// nothing here
// warnings stub
this = this;
}
void Figure_destructor (Figure *this)
{
// nothing here
// warnings stub
this = this;
}
void Figure_copy (struct Figure *dest, const struct Figure *src)
void Figure_copy (Figure *dest, const Figure *src)
{
// nothing here
// warnings stub
dest = (Figure *) src;
}

+ 2
- 2
Makefile View File

@ -1,4 +1,4 @@
# Makefile generated by command: smake.sh -t main
# Makefile generated by command: smake.sh -t main --ldflags=-lm
# This file is generated with smake.sh.
# You can use this make file with instruction make to
# use one of build mode: debug, profile, develop, release.
@ -20,7 +20,7 @@ CC=cc
CXX=c++
CFLAGS := $(CFLAGS)
CXXFLAGS := $(CXXFLAGS)
LDFLAGS := $(LDFLAGS)
LDFLAGS := -lm $(LDFLAGS)
LIBS=
SRC=
INCLUDES=


+ 28
- 14
Polygon.c View File

@ -5,11 +5,12 @@
#include "Polygon.h"
/* considered to be protected */
void Polygon_constructor (Polygon *this, const struct point *points, int npoints)
void Polygon_constructor (Polygon *this, const struct point *points, size_t npoints)
{
Figure_constructor ((Figure *) this);
this->npoints = npoints;
this->points = strdup (points, npoints * sizeof (struct point));
this->points = malloc (npoints * sizeof (struct point));
memcpy (this->points, points, npoints * sizeof (struct point));
}
void Polygon_destructor (Polygon *this)
@ -19,8 +20,10 @@ void Polygon_destructor (Polygon *this)
void Polygon_copy (Polygon *dest, const Polygon *src)
{
free (dest->points);
dest->npoints = src->npoints;
dest->points = strdup (src->points, src->npoints * sizeof (struct point));
dest->points = malloc (src->npoints * sizeof (struct point));
memcpy (dest->points, src->points, src->npoints * sizeof (struct point));
}
/* private */
@ -32,7 +35,7 @@ static const char* __Polygon_type ()
static Polygon* __Polygon_clone (const Polygon *this)
{
Polygon *poly = malloc (sizeof (Polygon));
memset (poly, 0, sizeof (
memset (poly, 0, sizeof (Polygon));
Polygon_copy (poly, this);
return poly;
}
@ -40,12 +43,12 @@ static Polygon* __Polygon_clone (const Polygon *this)
static void __Polygon_destroy (Polygon *this)
{
Polygon_destructor (this);
g_free (this);
free (this);
}
static void __Polygon_draw (const Polygon *this)
void __Polygon_draw (const Polygon *this)
{
int i = 0;
size_t i = 0;
for (i = 0; i < this->npoints; i++)
{
@ -54,10 +57,10 @@ static void __Polygon_draw (const Polygon *this)
printf ("{%f;%f}, ", this->points[0].x, this->points[0].y);
}
static double __Polygon_area (const Polygon *this)
double __Polygon_area (const Polygon *this)
{
double s = 0.0, x, y;
int i = 0;
double s = 0.0;
size_t i = 0;
for (i = 0; i < this->npoints; i++)
{
@ -70,13 +73,13 @@ static double __Polygon_area (const Polygon *this)
// S=abs(сумма{(x[i+1]-x[i])*(y[i+1]+y[i])/2})
}
static double __Polygon_max_diag (const Polygon *this)
double __Polygon_max_diag (const Polygon *this)
{
double diag = 0.0,
tmp = 0.0,
tmp1 = 0.0,
tmp2 = 0.0;
int i = 0, j = 0;
size_t i = 0, j = 0;
for (i = 0; i < this->npoints - 2; i++)
{
@ -96,9 +99,20 @@ static double __Polygon_max_diag (const Polygon *this)
}
/* public */
Polygon* Polygon_new (const struct point *points, int npoints)
Polygon* Polygon_new (const struct point *points, size_t npoints)
{
Polygon *poly = g_new0 (Polygon, 1);
static struct Polygon_vtable vtable = {
__Polygon_type,
__Polygon_clone,
__Polygon_destroy,
__Polygon_draw,
__Polygon_area,
__Polygon_max_diag
};
Polygon *poly = malloc (sizeof (Polygon));
memset (poly, 0, sizeof (Polygon));
Polygon_constructor (poly, points, npoints);
poly->vtable = &vtable;
return poly;
}

+ 8
- 3
Polygon.h View File

@ -1,6 +1,8 @@
#ifndef __POLYGON_H__
#define __POLYGON_H__
#include <stdlib.h>
#include "Figure.h"
typedef struct Polygon
@ -22,7 +24,7 @@ typedef struct Polygon
} *vtable;
/* Polygon fields */
int npoints;
size_t npoints;
struct point
{
@ -32,7 +34,7 @@ typedef struct Polygon
} Polygon;
Polygon* Polygon_new (const struct point *points, int npoints);
Polygon* Polygon_new (const struct point *points, size_t npoints);
static inline const char* Polygon_type (const Polygon *this)
{
@ -65,8 +67,11 @@ static inline double Polygon_max_diag (const Polygon *this)
}
/* considered to be protected */
void Polygon_constructor (Polygon *this, const struct point *points, int npoints);
void Polygon_constructor (Polygon *this, const struct point *points, size_t npoints);
void Polygon_destructor (Polygon *this);
void Polygon_copy (Polygon *dest, const Polygon *src);
void __Polygon_draw (const Polygon *this);
double __Polygon_area (const Polygon *this);
double __Polygon_max_diag (const Polygon *this);
#endif // __POLYGON_H__

+ 55
- 23
Rhomb.c View File

@ -1,5 +1,25 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "Rhomb.h"
/* considered to be protected */
void Rhomb_constructor (Rhomb *this, const struct point *points)
{
Polygon_constructor ((Polygon *) this, points, 4);
}
void Rhomb_destructor (Rhomb *this)
{
Polygon_destructor ((Polygon *) this);
}
void Rhomb_copy (Rhomb *dest, const Rhomb *src)
{
Polygon_copy ((Polygon *) dest, (Polygon *) src);
}
/* private */
static const char* __Rhomb_type ()
{
@ -8,52 +28,64 @@ static const char* __Rhomb_type ()
static Rhomb* __Rhomb_clone (const Rhomb *this)
{
Rhomb *rhomb = malloc (sizeof (Rhomb));
memset (rhomb, 0, sizeof (Rhomb));
Rhomb_copy (rhomb, this);
return rhomb;
}
static void __Rhomb_destroy (Rhomb *this)
{
Rhomb_destructor (this);
free (this);
}
static void __Rhomb_draw (const Rhomb *this)
{
__Polygon_draw ((Polygon *) this);
}
static double __Rhomb_area (const Rhomb *this)
{
return __Polygon_area ((Polygon *) this);
}
static double __Rhomb_max_diag (const Rhomb *this)
{
return __Polygon_max_diag ((Polygon *) this);
}
static int __Rhomb_is_square (const Rhomb *this)
{
double diag1, diag2, tmp1, tmp2;
tmp1 = this->points[0].x - this->points[2].x;
tmp2 = this->points[0].y - this->points[2].y;
diag1 = tmp1 * tmp1 + tmp2 * tmp2;
}
/* public */
Rhomb* Rhomb_new (const struct point *points, int npoints)
{
}
/* considered to be protected */
void Rhomb_constructor (Rhomb *this, const struct point *points, int npoints)
{
tmp1 = this->points[1].x - this->points[3].x;
tmp2 = this->points[1].y - this->points[3].y;
diag2 = tmp1 * tmp1 + tmp2 * tmp2;
return (diag1 == diag2);
}
void Rhomb_destructor (Rhomb *this)
{
}
void Rhomb_copy (Rhomb *dest, const Rhomb *src)
/* public */
Rhomb* Rhomb_new (const struct point *points)
{
static struct Rhomb_vtable vtable = {
__Rhomb_type,
__Rhomb_clone,
__Rhomb_destroy,
__Rhomb_draw,
__Rhomb_area,
__Rhomb_max_diag,
__Rhomb_is_square
};
Rhomb *rhomb = malloc (sizeof (Rhomb));
memset (rhomb, 0, sizeof (Rhomb));
Rhomb_constructor (rhomb, points);
rhomb->vtable = &vtable;
return rhomb;
}

+ 3
- 3
Rhomb.h View File

@ -25,13 +25,13 @@ typedef struct Rhomb
} *vtable;
/* derived from Polygon */
int npoints;
size_t npoints;
struct point *points;
} Rhomb;
Rhomb* Rhomb_new (const struct point *points, int npoints);
Rhomb* Rhomb_new (const struct point *points);
static inline const char* Rhomb_type (const Rhomb *this)
{
@ -69,7 +69,7 @@ static inline int Rhomb_is_square (const Rhomb *this)
}
/* considered to be protected */
void Rhomb_constructor (Rhomb *this, const struct point *points, int npoints);
void Rhomb_constructor (Rhomb *this, const struct point *points);
void Rhomb_destructor (Rhomb *this);
void Rhomb_copy (Rhomb *dest, const Rhomb *src);


Loading…
Cancel
Save