ccstruct/rect.cpp

Go to the documentation of this file.
00001 
00020 #include          "mfcpch.h"     //precompiled headers
00021 #include          "rect.h"
00022 
00026 BOX::BOX(                   //construtor
00027          const ICOORD pt1,  //one corner
00028          const ICOORD pt2   //the other corner
00029         ) {
00030   if (pt1.x () <= pt2.x ()) {
00031     if (pt1.y () <= pt2.y ()) {
00032       bot_left = pt1;
00033       top_right = pt2;
00034     }
00035     else {
00036       bot_left = ICOORD (pt1.x (), pt2.y ());
00037       top_right = ICOORD (pt2.x (), pt1.y ());
00038     }
00039   }
00040   else {
00041     if (pt1.y () <= pt2.y ()) {
00042       bot_left = ICOORD (pt2.x (), pt1.y ());
00043       top_right = ICOORD (pt1.x (), pt2.y ());
00044     }
00045     else {
00046       bot_left = pt2;
00047       top_right = pt1;
00048     }
00049   }
00050 }
00051 
00052 
00056 BOX BOX::intersection(  //shared area box
00057                       const BOX &box) const {
00058   ICOORD bl;                     //bottom left
00059   ICOORD tr;                     //top right
00060 
00061   if (overlap (box)) {
00062     if (box.bot_left.x () > bot_left.x ())
00063       bl.set_x (box.bot_left.x ());
00064     else
00065       bl.set_x (bot_left.x ());
00066 
00067     if (box.top_right.x () < top_right.x ())
00068       tr.set_x (box.top_right.x ());
00069     else
00070       tr.set_x (top_right.x ());
00071 
00072     if (box.bot_left.y () > bot_left.y ())
00073       bl.set_y (box.bot_left.y ());
00074     else
00075       bl.set_y (bot_left.y ());
00076 
00077     if (box.top_right.y () < top_right.y ())
00078       tr.set_y (box.top_right.y ());
00079     else
00080       tr.set_y (top_right.y ());
00081   }
00082   else {
00083     bl.set_x (MAX_INT16);
00084     bl.set_y (MAX_INT16);
00085     tr.set_x (-MAX_INT16);
00086     tr.set_y (-MAX_INT16);
00087   }
00088   return BOX (bl, tr);
00089 }
00090 
00091 
00095 BOX BOX::bounding_union(  //box enclosing both
00096                         const BOX &box) const {
00097   ICOORD bl;                     //bottom left
00098   ICOORD tr;                     //top right
00099 
00100   if (box.bot_left.x () < bot_left.x ())
00101     bl.set_x (box.bot_left.x ());
00102   else
00103     bl.set_x (bot_left.x ());
00104 
00105   if (box.top_right.x () > top_right.x ())
00106     tr.set_x (box.top_right.x ());
00107   else
00108     tr.set_x (top_right.x ());
00109 
00110   if (box.bot_left.y () < bot_left.y ())
00111     bl.set_y (box.bot_left.y ());
00112   else
00113     bl.set_y (bot_left.y ());
00114 
00115   if (box.top_right.y () > top_right.y ())
00116     tr.set_y (box.top_right.y ());
00117   else
00118     tr.set_y (top_right.y ());
00119   return BOX (bl, tr);
00120 }
00121 
00122 
00126 #ifndef GRAPHICS_DISABLED
00127 void BOX::plot(                      //paint box
00128                WINDOW fd,            //where to paint
00129                INT16 style,          //display style
00130                INT16 edged,          //show border?
00131                COLOUR fill_colour,   //colour for inside
00132                COLOUR border_colour  //colour for border
00133               ) const {
00134   interior_style(fd, style, edged); 
00135   fill_color_index(fd, fill_colour); 
00136   perimeter_color_index(fd, border_colour); 
00137   plot(fd); 
00138 }
00139 #endif
00140 
00141 
00145 DLLSYM BOX &
00146 operator+= (                     //bounding bounding bx
00147 BOX & op1,                       //operands
00148 const BOX & op2) {
00149   if (op2.bot_left.x () < op1.bot_left.x ())
00150     op1.bot_left.set_x (op2.bot_left.x ());
00151 
00152   if (op2.top_right.x () > op1.top_right.x ())
00153     op1.top_right.set_x (op2.top_right.x ());
00154 
00155   if (op2.bot_left.y () < op1.bot_left.y ())
00156     op1.bot_left.set_y (op2.bot_left.y ());
00157 
00158   if (op2.top_right.y () > op1.top_right.y ())
00159     op1.top_right.set_y (op2.top_right.y ());
00160 
00161   return op1;
00162 }
00163 
00164 
00168 DLLSYM BOX &
00169 operator-= (                     //inplace intersection
00170 BOX & op1,                       //operands
00171 const BOX & op2) {
00172   if (op1.overlap (op2)) {
00173     if (op2.bot_left.x () > op1.bot_left.x ())
00174       op1.bot_left.set_x (op2.bot_left.x ());
00175 
00176     if (op2.top_right.x () < op1.top_right.x ())
00177       op1.top_right.set_x (op2.top_right.x ());
00178 
00179     if (op2.bot_left.y () > op1.bot_left.y ())
00180       op1.bot_left.set_y (op2.bot_left.y ());
00181 
00182     if (op2.top_right.y () < op1.top_right.y ())
00183       op1.top_right.set_y (op2.top_right.y ());
00184   }
00185   else {
00186     op1.bot_left.set_x (MAX_INT16);
00187     op1.bot_left.set_y (MAX_INT16);
00188     op1.top_right.set_x (-MAX_INT16);
00189     op1.top_right.set_y (-MAX_INT16);
00190   }
00191   return op1;
00192 }
00193 
00194 
00198 void BOX::serialise_asc(         //convert to ascii
00199                         FILE *f  //file to use
00200                        ) {
00201   bot_left.serialise_asc (f);
00202   top_right.serialise_asc (f);
00203 }
00204 
00205 
00209 void BOX::de_serialise_asc(         //convert from ascii
00210                            FILE *f  //file to use
00211                           ) {
00212   bot_left.de_serialise_asc (f);
00213   top_right.de_serialise_asc (f);
00214 }

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1