#include <polyblk.h>
Definition at line 47 of file polyblk.h.
POLY_BLOCK::POLY_BLOCK | ( | ) | [inline] |
POLY_BLOCK::POLY_BLOCK | ( | ICOORDELT_LIST * | points, | |
POLY_TYPE | t | |||
) |
FIX:.
Definition at line 38 of file polyblk.cpp.
References compute_bb(), type, and vertices.
00038 { 00039 ICOORDELT_IT v = &vertices; 00040 00041 vertices.clear (); 00042 v.move_to_first (); 00043 v.add_list_before (points); 00044 compute_bb(); 00045 type = t; 00046 }
POLY_BLOCK::~POLY_BLOCK | ( | ) | [inline] |
BOX* POLY_BLOCK::bounding_box | ( | ) | [inline] |
void POLY_BLOCK::compute_bb | ( | ) |
Compute the bounding box from the outline points.
Definition at line 52 of file polyblk.cpp.
References box, vertices, and ICOORD::y().
Referenced by move(), POLY_BLOCK(), and rotate().
00052 { //constructor 00053 ICOORD ibl, itr; //integer bb 00054 ICOORD botleft; //bounding box 00055 ICOORD topright; 00056 ICOORD pos; //current pos; 00057 ICOORDELT_IT pts = &vertices; //iterator 00058 00059 botleft = *pts.data (); 00060 topright = botleft; 00061 do { 00062 pos = *pts.data (); 00063 if (pos.x () < botleft.x ()) 00064 //get bounding box 00065 botleft = ICOORD (pos.x (), botleft.y ()); 00066 if (pos.y () < botleft.y ()) 00067 botleft = ICOORD (botleft.x (), pos.y ()); 00068 if (pos.x () > topright.x ()) 00069 topright = ICOORD (pos.x (), topright.y ()); 00070 if (pos.y () > topright.y ()) 00071 topright = ICOORD (topright.x (), pos.y ()); 00072 pts.forward (); 00073 } 00074 while (!pts.at_first ()); 00075 ibl = ICOORD (botleft.x (), botleft.y ()); 00076 itr = ICOORD (topright.x (), topright.y ()); 00077 box = BOX (ibl, itr); 00078 }
BOOL8 POLY_BLOCK::contains | ( | POLY_BLOCK * | poly | ) |
Return TRUE if poly is within another poly.
Definition at line 128 of file polyblk.cpp.
References bounding_box(), box, count(), FALSE, INTERSECTING, BOX::overlap(), points(), TRUE, vertices, and winding_number().
Referenced by delete_all_in(), delete_all_tr_in(), show_all_in(), and show_all_tr_in().
00129 { 00130 INT16 count; //winding count 00131 ICOORDELT_IT it = &vertices; //iterator 00132 ICOORD vertex; 00133 00134 if (!box.overlap (*(other->bounding_box ()))) 00135 return FALSE; //can't be contained 00136 00137 /* check that no vertex of this is inside other */ 00138 00139 do { 00140 vertex = *it.data (); 00141 //get winding number 00142 count = other->winding_number (vertex); 00143 if (count != INTERSECTING) 00144 if (count != 0) 00145 return (FALSE); 00146 it.forward (); 00147 } 00148 while (!it.at_first ()); 00149 00150 /* check that all vertices of other are inside this */ 00151 it.set_to_list (other->points ()); //switch lists 00152 do { 00153 vertex = *it.data (); 00154 //try other way round 00155 count = winding_number (vertex); 00156 if (count != INTERSECTING) 00157 if (count == 0) 00158 return (FALSE); 00159 it.forward (); 00160 } 00161 while (!it.at_first ()); 00162 return TRUE; 00163 }
void POLY_BLOCK::de_dump | ( | FILE * | f | ) | [inline] |
void POLY_BLOCK::de_serialise_asc | ( | FILE * | f | ) |
Converto from ascii file.
Definition at line 397 of file polyblk.cpp.
References box, BOX::de_serialise_asc(), de_serialise_INT32(), type, and vertices.
00399 { 00400 vertices.de_serialise_asc (f); 00401 box.de_serialise_asc (f); 00402 type = (POLY_TYPE) de_serialise_INT32 (f); 00403 }
void POLY_BLOCK::dump | ( | FILE * | f | ) | [inline] |
Fill window with color?
Definition at line 246 of file polyblk.cpp.
References bounding_box(), draw2d, PB_LINE_IT::get_line(), line_color_index, move2d, and BOX::top().
00246 { 00247 INT16 y; 00248 INT16 width; 00249 PB_LINE_IT *lines; 00250 ICOORDELT_LIST *segments; 00251 ICOORDELT_IT s_it; 00252 00253 lines = new PB_LINE_IT (this); 00254 00255 line_color_index(window, colour); 00256 00257 for (y = this->bounding_box ()->bottom (); 00258 y <= this->bounding_box ()->top (); y++) { 00259 segments = lines->get_line (y); 00260 if (!segments->empty ()) { 00261 s_it.set_to_list (segments); 00262 for (s_it.mark_cycle_pt (); !s_it.cycled_list (); s_it.forward ()) { 00263 // Note different use of ICOORDELT, x coord is x coord of pixel 00264 // at the start of line segment, y coord is length of line segment 00265 // Last pixel is start pixel + length. 00266 width = s_it.data ()->y (); 00267 move2d (window, s_it.data ()->x (), y); 00268 draw2d (window, s_it.data ()->x () + (float) width, y); 00269 } 00270 } 00271 } 00272 }
POLY_TYPE POLY_BLOCK::isA | ( | ) | [inline] |
POLY_BLOCK::make_serialise | ( | POLY_BLOCK | ) |
void POLY_BLOCK::move | ( | ICOORD | shift | ) |
Move the POLY_BLOCK.
Definition at line 195 of file polyblk.cpp.
References compute_bb(), and vertices.
Referenced by TEXT_BLOCK::move().
00197 { 00198 ICOORDELT *pt; //current point 00199 ICOORDELT_IT pts = &vertices; //iterator 00200 00201 do { 00202 pt = pts.data (); 00203 *pt += shift; 00204 pts.forward (); 00205 } 00206 while (!pts.at_first ()); 00207 compute_bb(); 00208 }
BOOL8 POLY_BLOCK::overlap | ( | POLY_BLOCK * | poly | ) |
Return TRUE if polys overlap.
Definition at line 280 of file polyblk.cpp.
References bounding_box(), box, count(), FALSE, INTERSECTING, BOX::overlap(), points(), TRUE, vertices, and winding_number().
Referenced by delete_all_in(), delete_all_tr_in(), show_all_in(), and show_all_tr_in().
00281 { 00282 INT16 count; //winding count 00283 ICOORDELT_IT it = &vertices; //iterator 00284 ICOORD vertex; 00285 00286 if (!box.overlap (*(other->bounding_box ()))) 00287 return FALSE; //can't be any overlap 00288 00289 /* see if a vertex of this is inside other */ 00290 do { 00291 vertex = *it.data (); 00292 //get winding number 00293 count = other->winding_number (vertex); 00294 if (count != INTERSECTING) 00295 if (count != 0) 00296 return (TRUE); 00297 it.forward (); 00298 } 00299 while (!it.at_first ()); 00300 00301 /* see if a vertex of other is inside this */ 00302 00303 //switch lists 00304 it.set_to_list (other->points ()); 00305 do { 00306 vertex = *it.data (); 00307 //try other way round 00308 count = winding_number (vertex); 00309 if (count != INTERSECTING) 00310 if (count != 0) 00311 return (TRUE); 00312 it.forward (); 00313 } 00314 while (!it.at_first ()); 00315 return FALSE; 00316 }
Plot in window with color, something?
Definition at line 216 of file polyblk.cpp.
References character_height, draw2d, FALSE, INT32FORMAT, line_color_index, move2d, text2d, text_color_index, text_font_index, and vertices.
Referenced by WEIRD_BLOCK::plot().
00216 { 00217 ICOORDELT_IT v = &vertices; 00218 00219 line_color_index(window, colour); 00220 v.move_to_first (); 00221 00222 if (num > 0) { 00223 text_color_index(window, colour); 00224 character_height (window, (float) 80); 00225 text_font_index (window, 6); 00226 char temp_buff[34]; 00227 #ifdef __UNIX__ 00228 sprintf(temp_buff, INT32FORMAT, num); 00229 #else 00230 ltoa (num, temp_buff, 10); 00231 #endif 00232 text2d (window, v.data ()->x (), v.data ()->y (), temp_buff, 0, FALSE); 00233 } 00234 move2d (window, v.data ()->x (), v.data ()->y ()); 00235 for (v.mark_cycle_pt (); !v.cycled_list (); v.forward ()) 00236 draw2d (window, v.data ()->x (), v.data ()->y ()); 00237 v.move_to_first (); 00238 draw2d (window, v.data ()->x (), v.data ()->y ()); 00239 }
ICOORDELT_LIST* POLY_BLOCK::points | ( | ) | [inline] |
Definition at line 63 of file polyblk.h.
Referenced by contains(), PB_LINE_IT::get_line(), and overlap().
00063 { // access function 00064 return &vertices; 00065 }
void POLY_BLOCK::prep_serialise | ( | ) | [inline] |
void POLY_BLOCK::rotate | ( | FCOORD | rotation | ) |
Rotate the POLY_BLOCK.
Definition at line 170 of file polyblk.cpp.
References compute_bb(), rotation, ICOORD::set_x(), ICOORD::set_y(), vertices, and ICOORD::y().
Referenced by TEXT_BLOCK::rotate().
00172 { 00173 FCOORD pos; //current pos; 00174 ICOORDELT *pt; //current point 00175 ICOORDELT_IT pts = &vertices; //iterator 00176 00177 do { 00178 pt = pts.data (); 00179 pos.set_x (pt->x ()); 00180 pos.set_y (pt->y ()); 00181 pos.rotate (rotation); 00182 pt->set_x ((INT16) (floor (pos.x () + 0.5))); 00183 pt->set_y ((INT16) (floor (pos.y () + 0.5))); 00184 pts.forward (); 00185 } 00186 while (!pts.at_first ()); 00187 compute_bb(); 00188 }
Return the winding number of the outline around the given point.
Definition at line 85 of file polyblk.cpp.
References count(), INTERSECTING, vertices, and ICOORD::y().
Referenced by contains(), and overlap().
00087 { 00088 INT16 count; //winding count 00089 ICOORD pt; //current point 00090 ICOORD vec; //point to current point 00091 ICOORD vvec; //current point to next point 00092 INT32 cross; //cross product 00093 ICOORDELT_IT it = &vertices; //iterator 00094 00095 count = 0; 00096 do { 00097 pt = *it.data (); 00098 vec = pt - point; 00099 vvec = *it.data_relative (1) - pt; 00100 //crossing the line 00101 if (vec.y () <= 0 && vec.y () + vvec.y () > 0) { 00102 cross = vec * vvec; //cross product 00103 if (cross > 0) 00104 count++; //crossing right half 00105 else if (cross == 0) 00106 return INTERSECTING; //going through point 00107 } 00108 else if (vec.y () > 0 && vec.y () + vvec.y () <= 0) { 00109 cross = vec * vvec; 00110 if (cross < 0) 00111 count--; //crossing back 00112 else if (cross == 0) 00113 return INTERSECTING; //illegal 00114 } 00115 else if (vec.y () == 0 && vec.x () == 0) 00116 return INTERSECTING; 00117 it.forward (); 00118 } 00119 while (!it.at_first ()); 00120 return count; //winding number 00121 }
BOX POLY_BLOCK::box [private] |
Bounding box.
Definition at line 113 of file polyblk.h.
Referenced by compute_bb(), contains(), de_serialise_asc(), and overlap().
POLY_TYPE POLY_BLOCK::type [private] |
Page block or text region.
Definition at line 115 of file polyblk.h.
Referenced by de_serialise_asc(), and POLY_BLOCK().
ICOORDELT_LIST POLY_BLOCK::vertices [private] |
Vertices.
Definition at line 111 of file polyblk.h.
Referenced by compute_bb(), contains(), de_serialise_asc(), move(), overlap(), plot(), POLY_BLOCK(), rotate(), and winding_number().