Скачиваний:
19
Добавлен:
01.05.2014
Размер:
7.76 Кб
Скачать
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H

#include <list>
#include <vector>

#define INFINITY			10000000
#define INFINITY_POINT		TPoint(INFINITY, INFINITY)
#define INFINITY_MYPOINT	MyPoint(INFINITY_POINT, INFINITY)
#define NULL_POINT			TPoint(-111,-111)
#define NULL_MYPOINT    	MyPoint(NULL_POINT, -1)
#define NULL_MYRECT			MyRect(NULL_POINT, NULL_POINT)
#define NULL_LOCUS			TLocus(NULL_POINT, NULL_POINT, 0)

using namespace std;
//---------------------------------------------------------------------------


bool operator == (const TPoint& point1, const TPoint& point2) {
	return (point1.x == point2.x && point1.y == point2.y);
}
bool operator != (const TPoint& point1, const TPoint& point2) {
	return (point1.x != point2.x || point1.y != point2.y);
}
//---------------------------------------------------------------------------


struct MyPoint {
    MyPoint(const TPoint& pntPoint = NULL_POINT, int iNumber = -1) : point(pntPoint), number(iNumber) {}
	int number;
    TPoint point;

    bool operator ==(const MyPoint& point1) const {
    	return (point == point1.point && number == point1.number);
    }

	bool operator !=(const MyPoint& point1) const {
    	return (!(*this == point1));
    }

};

/*
 * Comparing structure for bynary search
 * 		i - template parameter for compare points in stl containers
 *			1 - compare x coordinates	(x-sorted lists, vector, etc)
 *			2 - compare y coordinates	(y-sorted)
 *			3 - compare numbers of points (number-sorted)
 *			4 - compare x,y coordinates (x-and-y-sorted)
 *			5 - compare y,y coordinates (y-and-x-sorted)
 *
 */
template <int i> struct less_my_point {
	int less_type;
    less_my_point() : less_type(i) {}
   	bool operator() (const MyPoint* point1, const MyPoint* point2) const {
    	int rslt = 0;
        switch (less_type) {
			case 1:
            	if (point1->point.x < point2->point.x) rslt = true;
                break;
			case 2:
            	if (point1->point.y < point2->point.y) rslt = true;
                break;
        	case 3:
            	if (point1->number  < point2->number) rslt = true;
                break;
			case 4:
            	if (point1->point.x  < point2->point.x) rslt = true; else
        		if (point1->point.x == point2->point.x && point1->point.y < point2->point.y) rslt = true;
                break;
        	case 5:
            	if (point1->point.y  < point2->point.y) rslt = true; else
        		if (point1->point.y == point2->point.y && point1->point.x < point2->point.x) rslt = true;
                break;
        	default:
            	throw "Parameter is incorrect.";
        }
        return rslt;
	}
};
//---------------------------------------------------------------------------


struct MyRect {
	MyRect(const TPoint& point1 = NULL_POINT, const TPoint& point2 = NULL_POINT) {
    	rect.left   = point1.x;
        rect.top    = point2.y;
        rect.right  = point2.x;
        rect.bottom = point1.y;
    }

	MyRect(int left, int top, int right, int bottom) {
    	rect.left = left;
        rect.top = top;
        rect.right = right;
        rect.bottom = bottom;
    }

    const RECT& getRect() { return rect; }

	RECT rect;

    bool operator ==(const MyRect& rect1) const {
    	return (rect.left == rect1.rect.left
        			&& rect.right == rect1.rect.right
                    && rect.top == rect1.rect.top
                    && rect.bottom == rect1.rect.bottom);
    }

	bool operator !=(const MyRect& rect1) const {
    	return (!(*this == rect1));
    }
};
//---------------------------------------------------------------------------


typedef list<MyPoint*>::const_iterator TPointListConstIterator;

class TPointList {

public:
	TPointList() : _elemCount(0) {}

	MyPoint addPoint(const TPoint&);
    void deletePoint(const MyPoint&);
    void deletePoint(int);
    void deletePoints();
    MyPoint movePoint(const MyPoint&, TPoint);
    MyPoint getPoint(int);
    int getPointCount() const;
    MyPoint getPointInArea(const TPoint&, int);

	TPointListConstIterator begin();
	TPointListConstIterator end();
    void clear();

protected:
typedef list<MyPoint*> TObjectList;
typedef list<MyPoint*>::iterator TObjectListIterator;

	TObjectList _array_points;
	TObjectList _array_x_sorted;
	TObjectList _array_y_sorted;

private:
	MyPoint addPoint(const TPoint&, int);
    int _elemCount;
};
//---------------------------------------------------------------------------

struct TLocus : public MyRect {
	TLocus( const TPoint& point1=NULL_POINT, const TPoint& point2=NULL_POINT, int dom=0) :
    		MyRect(point1,point2), domination(dom) {}

	TLocus( int left, int top, int right, int bottom, int dom=0) :
		MyRect(left, top, right, bottom), domination(dom) {}

    int domination;
};


/*
 * Comparing structure for bynary search
 * locuses was sorted by x,y
 *
 */
struct less_locus {
   	bool operator() (const TLocus& locus, const TPoint& point) const {
    	int rslt = 0;
            	if (locus.rect.right < point.x) rslt = 1; else
            	if (locus.rect.left < point.x && locus.rect.bottom < point.y) rslt = 1;

        return rslt;
	}
};

struct less_locus1 {
   	bool operator() (const TLocus& locus, const TLocus& point) const {
    	int rslt = 0;
            	if (locus.rect.right < point.rect.left) rslt = 1; else
            	if (locus.rect.left < point.rect.left && locus.rect.bottom < point.rect.top) rslt = 1;

        return rslt;
	}
};

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------


typedef void (__closure *TTraceFunc) (const TLocus&);


class TRegionalSearch : public TPointList {

typedef vector<TLocus> TObjectList;
typedef vector<TLocus>::iterator TObjectListIterator;

public:
	TRegionalSearch() : TPointList(), pointInfinity(INFINITY_MYPOINT) {}

    TTraceFunc tracerFunc;

	MyPoint addPoint(const TPoint&);
    void deletePoint(const MyPoint&);
    MyPoint movePoint(const MyPoint&, TPoint);

    void clear();


    int getPointCountInRect(const MyRect&, TLocus&, TLocus&, TLocus&, TLocus&);

public:
    TLocus preprocessing();
	TLocus preprocessingStep(int);
    TLocus getLocus(const TPoint&);
    int IsModified() const { return isModified; }

private:

   	TPointList::TObjectListIterator ix, iy;

	struct preprocessingSearchStruct {
	    TPoint pred_x, pred_y;
	    TLocus locus_x, locus_y;
    	TObjectListIterator ilocusy;
        int ixpoints, iypoints;
        void init() {
			pred_x = TPoint(0, 0);
			pred_y = TPoint(0, 0);
			locus_x= NULL_LOCUS;
            locus_y= NULL_LOCUS;
        }
    } pps;

    MyPoint pointInfinity;
    TObjectList _locus_list;

    int isModified;
};
//---------------------------------------------------------------------------

int getZoomCoord(int coord, float zoom) {
	float rslt = float(coord) * zoom;
	return rslt;
}

int getRealCoord(int coord, float zoom) {
	float rslt = float(coord) / zoom;
	return rslt;
}

int getZoomX(int coord, float zoom) {
	float rslt = float(coord) * zoom;
	return rslt;
}

int getRealX(int coord, float zoom) {
	float rslt = float(coord) / zoom;
	return rslt;
}

int getZoomY(int coord, float zoom, int height) {
	float newcoord = height - coord;
	float rslt = newcoord * zoom;
    if (rslt < 0) rslt = 0; 
	return rslt;
}

int getRealY(int coord, float zoom, int height) {
	float newcoord = height - coord;
	float rslt = newcoord / zoom;
	return rslt;
}


#endif
Соседние файлы в папке Sources