#include <stdio.h>
#include <sys/types.h>
#ifndef NOMEMCPY
#include <memory.h>
#endif

#include <math.h>
#include <values.h>
#include <xalloca.h>
#undef _ANSI_ARGS_
#undef CONST
#if ((defined(__STDC__) || defined(SABER)) && !defined(NO_PROTOTYPE)) || defined(__cplusplus)
#   define _USING_PROTOTYPES_ 1
#   define _ANSI_ARGS_(x)	x
#   define CONST const
#   ifdef __cplusplus
#       define VARARGS (...)
#   else
#       define VARARGS ()
#   endif
#else
#   define _ANSI_ARGS_(x)	()
#   define CONST
#endif
typedef int bool;
#include <smalloc.h>

typedef struct {
    double x, y, z;
} Vector;

typedef struct {
    double   red;
    double   grn;
    double   blu;
} Color;

#include "/com/ftp/pub/courses/6.837/ps1/include/extraneous.h" /* Include other definitions you don't need to worry about */

/* In this problem set, you're going to be primarily concerned with the
   x,y,z coordinates.  The color of the edge is stored in the normal (dumb)
   as red = normal.x, green = normal.y, blue = normal.z */
typedef struct edges_3d {
  int              ystart;
  int              ystop;
  double           xstart;
  double           xstep;
  double           zstart;
  double           zstep;
  double           hden;        /* Homogeneous denominator */
  double           hdenstep;
  Vector           world;       /* World coordinates */
  Vector           worldstep;   /* World coordinates interpolation steps */
  Vector           normal;      /* Surface normal */
  Vector           normalstep;  /* Surface normal interpolation steps */
  Vector           texture;     /* Texture coordinates */
  Vector           texturestep; /* Texture coordinates interpolation steps */
  int              polygon;     /* Id of the polygon the edge belongs to */
  Surface         *surface;     /* Surface that the edge belongs to */
  struct edges_3d *next;        /* Next edge on this scanline */
} Edge;

extern Edge    **y_bucket;

void render_scanlines (int xres,
		       int yres);

void updateAEL(Edge **pAEL, int y);

/*
   Sets the screen pixel at (x,y) to Color
*/
extern void SetPixel(int x, 
		     int y,
		     Color col);

/*
  Merges two edge lists, sorting by x.  
*/

extern Edge * merge_edge_lists (Edge *list1,
				Edge *list2);


#define FAR_AWAY 269298240 /* Use this for your z-buffering.  This == DBL_MAX */



