#include "gosGML.hpp"
//===========================================================================//
// File:	 Region.cpp														 //
// Project:  gosGml				                                         //
// Contents:																 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 4/10/00   DP     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 2000 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//


#include "region.h"



Region::Region(int regionSpacing)
:RegionSpacing(regionSpacing)
{
	H=new Hash<ImageDataC*,int>(59);
}

Region::~Region()
{
	delete H;
}

void Region::AddRegion(rect* Region, ImageData* IDP)
{
	for(int i=Region->Top; i<Region->Bottom; i+=RegionSpacing)
	{
		ImageDataC* HashC=H->FindHit(i);
		if(HashC)
		{
			while(HashC->Next)
				HashC=HashC->Next;
			HashC->Next=new ImageDataC;
			HashC=HashC->Next;
			HashC->Next=0;
			HashC->I=IDP;
			HashC->R=Region;
		}
		else
		{
			HashC=new ImageDataC;
			HashC->Next=0;
			HashC->I=IDP;
			HashC->R=Region;
			NameValuePair<ImageDataC*,int>* NVP=new NameValuePair<ImageDataC*,int>(i,HashC);
			H->AddHash(NVP);
		}
	}
}

ImageData* Region::TestForHit(int x, int y)
{
	x;
	ImageDataC* HashC=H->FindHit(y-y%RegionSpacing);
	if(HashC)
		while(HashC)
		{
			if(x>HashC->R->Left && x<HashC->R->Right && y>HashC->R->Top && y<HashC->R->Bottom)	//if point is within this region
			{
				return HashC->I;
			}
			else
				HashC=HashC->Next;
		};
	return NULL;
}

void Region::Clear()
{
	H->Clear();
}