Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "figura.h"
- #include <math.h>
- #include <stdlib.h>
- static const float PI = 3.1415926;
- void przesun(Figura *f, float x, float y)
- {
- f->xA += x;
- f->xB += x;
- f->xC += x;
- f->xD += x;
- f->yA += y;
- f->yB += y;
- f->yC += y;
- f->yD += y;
- }
- float pole(Figura *f)
- {
- switch(f->typfig)
- {
- case SQUARE:
- {
- return fabs((f->xB - f->xA) * (f->yC - f->yA));
- }
- case TRIANGLE:
- {
- float a = fabs(f->xA - f->xB);
- float h = fabs(f->yC - f->yA);
- return a*h/2;
- }
- case CIRCLE:
- {
- float x = fabs(f->xA - f->xB);
- float y = fabs(f->yA - f->yB);
- float rKw = (x*x + y*y);
- return PI * rKw;
- }
- }
- }
- float sumapol(Figura** f, int size)
- {
- float r = 0.0f;
- for(int i = 0; i < size; i++)
- {
- r += pole(f[i]);
- }
- return r;
- }
- static Figura* stworzFigure(enum FIG_TYPES t,float xA, float yA, float xB, float yB, float xC, float yC, float xD, float yD)
- {
- Figura* f = (Figura*)malloc(sizeof(Figura));
- f->typfig = t;
- f->xA = xA;
- f->xB = xB;
- f->xC = xC;
- f->xD = xD;
- f->yA = yA;
- f->yB = yB;
- f->yC = yC;
- f->yD = yD;
- return f;
- }
- Figura* stworzKwadrat(float xA, float yA, float bok)
- {
- return stworzFigure(SQUARE, xA, yA, xA+bok, yA, xA+bok, yA+bok, xA, yA+bok);
- }
- Figura* stworzKolo(float xA, float yA, float r)
- {
- return stworzFigure(CIRCLE, xA, yA, xA+r, yA, 0, 0, 0, 0);
- }
- Figura* stworzTrojkat(float xA, float yA, float xB, float xC, float yC)
- {
- if(xB == xA || yC == yA) return NULL;
- return stworzFigure(TRIANGLE, xA, yA, xB, yA, xC, yC, 0, 0);
- }
- void zniszczFigure(Figura* f)
- {
- free(f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement