/*
 * w4735 homework 2
 * by Anders Pearson <anders@columbia.edu>
 * March 2001 
 */

#ifndef HW2_H
#define HW2_H

#define MAXLEN 1000
#define MAXLINES 255

#define WIDTH 274
#define HEIGHT 494

struct point {
  int x;
  int y;
};

struct min_bound_rect {
  struct point upper_left;
  struct point lower_right;
};

struct building {
  char label[MAXLEN];
  int area;
  int dist;
  int occluded;
  struct point com; /* center of mass */
  struct min_bound_rect mbr; 
};

/* function called on mouse click */
void do_stuff(int x, int y);

/* parses the labels file "table.txt" 
 * returns boolean for success 
 */
int parse_labels();

/* utility functions for dealing with the structs */
struct point makepoint (int x, int y);
struct min_bound_rect makembr(struct point ul, struct point lr);
struct building makebuilding(char label[MAXLEN], int area, struct point com,  
			     struct min_bound_rect mbr);

/* initializes the buildings[] array, making the 
 * building structs and figuring out their basic info
 * (centroid, minimum bounding rectangle) */
int make_buildings();

/* relationship functions, return true if pt is [in|south|north|etc] (of) 
 * building N
 */
int in (struct point pt,int N);
int south (struct point pt, int N);
int north (struct point pt, int N); 
int east (struct point pt, int N);
int west (struct point pt, int N);

/* draws a line starting from pt in direction specified by d
 * and returns true if it hits building N */
int go(struct point pt, int N, int d);
/* returns true if pt is within the minimum bounding rectangle 
 * of building N */
int in_mbr(struct point pt, int N);
/* calculates the minimum distance between the point and building N */
int dist(struct point pt, int N);
/* the euclidean distance squared between two points */
int e_dist_sq(struct point a, struct point b);
/* sorts the buildings by their distance from pt. closest first */
void sort_by_distance(struct point pt);
/* comparison function used by qsort */
int cmp_building (int *a, int *b);
/* returns true if building N is occluded as viewed from point pt
 */
int occluded(struct point pt, int N);
#endif

