00001 /********************************************************************** 00002 *< 00003 FILE: box2.h 00004 00005 DESCRIPTION: 00006 00007 CREATED BY: Dan Silva 00008 00009 HISTORY: 00010 00011 *> Copyright (c) 1994, All Rights Reserved. 00012 **********************************************************************/ 00013 #pragma once 00014 00015 #include "GeomExport.h" 00016 #include "maxheap.h" 00017 #include "ipoint2.h" 00018 #include "point2.h" 00019 #include <wtypes.h> 00020 00029 class Box2: public RECT, public MaxHeapOperators { 00030 public: 00033 GEOMEXPORT Box2(); 00040 GEOMEXPORT Box2(const IPoint2 a, const IPoint2 b); 00044 GEOMEXPORT int IsEmpty(); 00047 GEOMEXPORT void SetEmpty(); 00050 GEOMEXPORT void Rectify(); // makes top<bottom, left<right 00056 GEOMEXPORT void Scale(float f); 00061 GEOMEXPORT void Translate(IPoint2 t); 00062 00065 IPoint2 GetCenter() { return IPoint2((left+right)/2, (top+bottom)/2); } 00067 int x() { return min(left,right); } 00069 int y() { return min(top,bottom); } 00071 int w() { return abs(right-left)+1; } 00073 int h() { return abs(bottom-top)+1; } 00074 00081 void SetW(int w) { right = left + w -1; } 00088 void SetH(int h) { bottom = top + h -1; } 00093 void SetX(int x) { left = x; } 00098 void SetY(int y) { top = y; } 00105 void SetWH(int w, int h) { SetW(w); SetH(h); } 00112 void SetXY(int x, int y) { SetX(x); SetY(y); } 00113 00116 GEOMEXPORT Box2& operator=(const RECT& r); 00119 GEOMEXPORT Box2& operator=(RECT& r); 00122 GEOMEXPORT Box2& operator+=(const Box2& b); 00124 GEOMEXPORT Box2& operator+=(const IPoint2& p); 00127 int operator==( const Box2& b ) const { return (left==b.left && right==b.right && top==b.top && bottom==b.bottom); } 00132 GEOMEXPORT int Contains(const IPoint2& p) const; // is point in this box? 00133 }; 00134 00135 typedef Box2 Rect; 00136 00137 00138 struct FBox2: public MaxHeapOperators { 00139 Point2 pmin; 00140 Point2 pmax; 00141 int IsEmpty() { return pmin.x>pmax.x?1:0; } 00142 void SetEmpty() { pmin = Point2(1E30,1E30); pmax = -pmin; } 00143 FBox2& operator=(const FBox2& r) { pmin = r.pmin; pmax = r.pmax; return *this; } 00144 GEOMEXPORT FBox2& operator+=(const Point2& p); 00145 GEOMEXPORT FBox2& operator+=(const FBox2& b); 00146 GEOMEXPORT int Contains(const Point2& p) const; // is point in this box? 00147 }; 00148