File: VCopyObj.c

package info (click to toggle)
acm 5.0-19
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,852 kB
  • ctags: 4,792
  • sloc: ansic: 42,427; makefile: 706; cpp: 293; perl: 280; sh: 198
file content (39 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "Vlib.h"

VObject  *
VCopyObject(VObject * obj)
{

	register int i;
	register VObject *newObj;

	newObj = (VObject *) Vmalloc(sizeof(VObject));
	newObj->name = obj->name;
	newObj->extent = obj->extent;
	newObj->center = obj->center;
	newObj->numPolys = obj->numPolys;
	newObj->polygon =
		(VPolygon **) Vmalloc(sizeof(VPolygon *) * newObj->numPolys);
	if (obj->order) {
		newObj->order = (unsigned short *)
			Vmalloc(sizeof(unsigned short) * NUM_ASPECTS *
					newObj->numPolys);

		memcpy((char *) newObj->order, (char *) obj->order,
			   sizeof(unsigned short) * NUM_ASPECTS *
			   newObj->numPolys);
	}
	else {
		newObj->order = (unsigned short *) NULL;
	}

	for (i = 0; i < obj->numPolys; ++i) {
		if ((newObj->polygon[i] = VCopyPolygon(obj->polygon[i]))
			== (VPolygon *) NULL) {
			fprintf(stderr, "VCopyObject: can't copy polygons\n");
			exit(1);
		}
	}

	return newObj;
}