#ifndef lint
static char *sccsid = "@(#)light.c	1.1 (Steve Hill) 3/9/90";
#endif

/* light.c
 *
 * Routines to create destroy and manipulate lights and light lists.
 *
 * Lights are described by their location, and thier colour.
 */

#include <stdio.h>

#include "basetype.h"
#include "error.h"
#include "malloc.h"
#include "colour.h"
#include "matrix.h"
#include "point.h"
#include "list.h"
#include "light.h"


/* Light
 *
 * Allocate and initialise a light.
 */

light_t *
Light(point, colour)
point_t		*point;
colour_t	*colour;
{
	light_t	*light;

	light = (light_t *) malloc(sizeof(light_t));

	if (light == LightNull)
		FatalError(__FILE__, __LINE__, "Light: Out of memory");

	light->point  = point;
	light->colour = colour;

	return(light);
}


/* LightFree
 *
 * Free a light, and its sub components.
 */

void
LightFree(light)
light_t	*light;
{
	if (light == LightNull)
		return;

	PointFree(light->point);
	ColourFree(light->colour);
	(void) free((char *) light);
}


/* LightPrint
 *
 * Print a light to a file.
 */
 
void
LightPrint(file, light)
FILE	*file;
light_t	*light;
{
	if (light == LightNull)
	{
		fprintf(file, "Null Light\n");
		return;
	}

	PointPrint(file, light->point);
	ColourPrint(file, light->colour);
}


/* LightListCons
 *
 * Add a light to the head of a list of lights.
 */

light_list_t *
LightListCons(light, light_list)
light_t		*light;
light_list_t	*light_list;
{
	return((light_list_t *)
	       ListCons((address_t) light, (list_t *) light_list));
}


/* LightListPrint
 *
 * Print out a list of lights.
 */

void
LightListPrint(file, light_list)
FILE		*file;
light_list_t	*light_list;
{
	ListPrint(file, LightPrint, (list_t *) light_list);
}


/* LightListFree
 *
 * Free a light list, and all its elements.
 */

void
LightListFree(light_list)
light_list_t	*light_list;
{
	ListFree((list_t *) light_list, LightFree);
}
