EE445M RTOS
Taken at the University of Texas Spring 2015
shape.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdarg.h>
3 
4 #include "shape.h"
5 
7  point* p = malloc(sizeof(point));
8  p->x = x;
9  p->y = y;
10  p->shade = shade;
11  return p;
12 }
13 
15 
16  return shape_create(3, p0, p1, p2);
17 }
18 
19 shape* shape_create_quad(point* top_left_corner, uchar width, uchar height) {
20 
21  ushort x = top_left_corner->x;
22  ushort y = top_left_corner->y;
23  shade_t shade = top_left_corner->shade;
24  return shape_create(4,
25  top_left_corner,
26  shape_create_point(x+width, y, shade),
27  shape_create_point(x+width, y+height, shade),
28  shape_create_point(x, y+height, shade));
29 }
30 
31 shape* shape_create(ushort num_points, ...) {
32 
33  unsigned char i;
34  shape* sh = (shape*) calloc(1, sizeof(shape));
35  point** pts = (point**) calloc(num_points, sizeof(point*));
36  va_list args;
37 
38  va_start(args, num_points);
39  for(i=0; i < num_points; ++i) {
40  pts[i] = va_arg(args, point*);
41  }
42  va_end(args); /* clean up the list */
43 
44  sh->num_points = num_points;
45  sh->points = pts;
46  return sh;
47 }
48 
50 
51  ushort i;
52  for(i=0; i<sh->num_points; ++i) {
53  free(sh->points[i]);
54  }
55  free(sh->points);
56 }
57 
59 
60  circle* cir = (circle*) calloc(1, sizeof(circle));
61  cir->center = center;
62  cir->radius = radius;
63  return cir;
64 }
65 
67 
68  ushort i;
69  shape* dup = (shape*) calloc(1, sizeof(shape));
70 
71  dup->num_points = s->num_points;
72  dup->points = (point**) calloc(dup->num_points, sizeof(point*));
73 
74  for(i=0; i < dup->num_points; ++i) {
75  dup->points[i] = s->points[i];
76  }
77  return dup;
78 }
unsigned short num_points
Definition: shape.h:28
unsigned short y
Definition: shape.h:16
ushort radius
Definition: shape.h:41
Representation of a circle.
Definition: shape.h:37
shape * shape_create(ushort num_points,...)
Definition: shape.c:31
Representation of a shape.
Definition: shape.h:26
shade_t shade
Definition: shape.h:18
shape * shape_create_quad(point *top_left_corner, uchar width, uchar height)
Definition: shape.c:19
point * center
Definition: shape.h:40
shape * shape_create_triangle(point *p0, point *p1, point *p2)
Definition: shape.c:14
unsigned short ushort
Definition: defines.h:35
point ** points
Definition: shape.h:29
unsigned char uchar
Definition: defines.h:34
point * shape_create_point(ushort x, ushort y, shade_t shade)
Definition: shape.c:6
shape * shape_duplicate_shape(shape *s)
Definition: shape.c:66
Representation of an ordered pair with a shade.
Definition: shape.h:13
void shape_destroy_shape(shape *sh)
Definition: shape.c:49
#define shade_t
Definition: defines.h:41
circle * shape_create_circle(ushort radius, point *center)
Definition: shape.c:58
unsigned short x
Definition: shape.h:15