All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
POLY_BLOCK Class Reference

#include <polyblk.h>

Public Member Functions

 POLY_BLOCK ()
 
 POLY_BLOCK (const TBOX &box, PolyBlockType type)
 
 POLY_BLOCK (ICOORDELT_LIST *points, PolyBlockType type)
 
 ~POLY_BLOCK ()
 
TBOXbounding_box ()
 
ICOORDELT_LIST * points ()
 
PolyBlockType isA () const
 
bool IsText () const
 
POLY_BLOCK::compute_bb

Compute the bounding box from the outline points.

void compute_bb ()
 
POLY_BLOCK::rotate

Rotate the POLY_BLOCK.

Parameters
rotationcos, sin of angle
void rotate (FCOORD rotation)
 
POLY_BLOCK::winding_number

Return the winding number of the outline around the given point.

Parameters
pointpoint to wind around
bool contains (POLY_BLOCK *other)
 
inT16 winding_number (const ICOORD &test_pt)
 

POLY_BLOCK::reflect_in_y_axis

Reflect the coords of the polygon in the y-axis. (Flip the sign of x.)

void reflect_in_y_axis ()
 
void move (ICOORD shift)
 
void plot (ScrollView *window, inT32 num)
 
void fill (ScrollView *window, ScrollView::Color colour)
 
bool overlap (POLY_BLOCK *other)
 
static ScrollView::Color ColorForPolyBlockType (PolyBlockType type)
 Returns a color to draw the given type. More...
 

Detailed Description

Definition at line 28 of file polyblk.h.

Constructor & Destructor Documentation

POLY_BLOCK::POLY_BLOCK ( )
inline

Definition at line 30 of file polyblk.h.

30  {
31  }
POLY_BLOCK::POLY_BLOCK ( const TBOX box,
PolyBlockType  type 
)

Definition at line 47 of file polyblk.cpp.

47  {
48  vertices.clear();
49  ICOORDELT_IT v = &vertices;
50  v.move_to_first();
51  v.add_to_end(new ICOORDELT(box.left(), box.top()));
52  v.add_to_end(new ICOORDELT(box.left(), box.bottom()));
53  v.add_to_end(new ICOORDELT(box.right(), box.bottom()));
54  v.add_to_end(new ICOORDELT(box.right(), box.top()));
55  compute_bb();
56  type = t;
57 }
void compute_bb()
Definition: polyblk.cpp:65
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
inT16 top() const
Definition: rect.h:54
POLY_BLOCK::POLY_BLOCK ( ICOORDELT_LIST *  points,
PolyBlockType  type 
)

Definition at line 36 of file polyblk.cpp.

36  {
37  ICOORDELT_IT v = &vertices;
38 
39  vertices.clear();
40  v.move_to_first();
41  v.add_list_before(points);
42  compute_bb();
43  type = t;
44 }
void compute_bb()
Definition: polyblk.cpp:65
ICOORDELT_LIST * points()
Definition: polyblk.h:42
POLY_BLOCK::~POLY_BLOCK ( )
inline

Definition at line 35 of file polyblk.h.

35  {
36  }

Member Function Documentation

TBOX* POLY_BLOCK::bounding_box ( )
inline

Definition at line 38 of file polyblk.h.

38  { // access function
39  return &box;
40  }
ScrollView::Color POLY_BLOCK::ColorForPolyBlockType ( PolyBlockType  type)
static

Returns a color to draw the given type.

Definition at line 395 of file polyblk.cpp.

395  {
396  // Keep kPBColors in sync with PolyBlockType.
397  const ScrollView::Color kPBColors[PT_COUNT] = {
398  ScrollView::WHITE, // Type is not yet known. Keep as the 1st element.
399  ScrollView::BLUE, // Text that lives inside a column.
400  ScrollView::CYAN, // Text that spans more than one column.
401  ScrollView::MEDIUM_BLUE, // Text that is in a cross-column pull-out region.
402  ScrollView::AQUAMARINE, // Partition belonging to an equation region.
403  ScrollView::SKY_BLUE, // Partition belonging to an inline equation region.
404  ScrollView::MAGENTA, // Partition belonging to a table region.
405  ScrollView::GREEN, // Text-line runs vertically.
406  ScrollView::LIGHT_BLUE, // Text that belongs to an image.
407  ScrollView::RED, // Image that lives inside a column.
408  ScrollView::YELLOW, // Image that spans more than one column.
409  ScrollView::ORANGE, // Image in a cross-column pull-out region.
410  ScrollView::BROWN, // Horizontal Line.
411  ScrollView::DARK_GREEN, // Vertical Line.
412  ScrollView::GREY // Lies outside of any column.
413  };
414  if (type >= 0 && type < PT_COUNT) {
415  return kPBColors[type];
416  }
417  return ScrollView::WHITE;
418 }
Definition: capi.h:79
void POLY_BLOCK::compute_bb ( )

Definition at line 65 of file polyblk.cpp.

65  { //constructor
66  ICOORD ibl, itr; //integer bb
67  ICOORD botleft; //bounding box
68  ICOORD topright;
69  ICOORD pos; //current pos;
70  ICOORDELT_IT pts = &vertices; //iterator
71 
72  botleft = *pts.data ();
73  topright = botleft;
74  do {
75  pos = *pts.data ();
76  if (pos.x () < botleft.x ())
77  //get bounding box
78  botleft = ICOORD (pos.x (), botleft.y ());
79  if (pos.y () < botleft.y ())
80  botleft = ICOORD (botleft.x (), pos.y ());
81  if (pos.x () > topright.x ())
82  topright = ICOORD (pos.x (), topright.y ());
83  if (pos.y () > topright.y ())
84  topright = ICOORD (topright.x (), pos.y ());
85  pts.forward ();
86  }
87  while (!pts.at_first ());
88  ibl = ICOORD (botleft.x (), botleft.y ());
89  itr = ICOORD (topright.x (), topright.y ());
90  box = TBOX (ibl, itr);
91 }
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
inT16 x() const
access function
Definition: points.h:52
Definition: rect.h:30
bool POLY_BLOCK::contains ( POLY_BLOCK other)
Returns
true if other is inside this.

Definition at line 139 of file polyblk.cpp.

139  {
140  inT16 count; // winding count
141  ICOORDELT_IT it = &vertices; // iterator
142  ICOORD vertex;
143 
144  if (!box.overlap (*(other->bounding_box ())))
145  return false; // can't be contained
146 
147  /* check that no vertex of this is inside other */
148 
149  do {
150  vertex = *it.data ();
151  // get winding number
152  count = other->winding_number (vertex);
153  if (count != INTERSECTING)
154  if (count != 0)
155  return false;
156  it.forward ();
157  }
158  while (!it.at_first ());
159 
160  /* check that all vertices of other are inside this */
161 
162  //switch lists
163  it.set_to_list (other->points ());
164  do {
165  vertex = *it.data ();
166  //try other way round
167  count = winding_number (vertex);
168  if (count != INTERSECTING)
169  if (count == 0)
170  return false;
171  it.forward ();
172  }
173  while (!it.at_first ());
174  return true;
175 }
TBOX * bounding_box()
Definition: polyblk.h:38
ICOORDELT_LIST * points()
Definition: polyblk.h:42
integer coordinate
Definition: points.h:30
#define INTERSECTING
Definition: polyblk.cpp:32
int count(LIST var_list)
Definition: oldlist.cpp:108
inT16 winding_number(const ICOORD &test_pt)
Definition: polyblk.cpp:101
bool overlap(const TBOX &box) const
Definition: rect.h:345
short inT16
Definition: host.h:100
void POLY_BLOCK::fill ( ScrollView window,
ScrollView::Color  colour 
)

Definition at line 272 of file polyblk.cpp.

272  {
273  inT16 y;
274  inT16 width;
275  PB_LINE_IT *lines;
276  ICOORDELT_LIST *segments;
277  ICOORDELT_IT s_it;
278 
279  lines = new PB_LINE_IT (this);
280  window->Pen(colour);
281 
282  for (y = this->bounding_box ()->bottom ();
283  y <= this->bounding_box ()->top (); y++) {
284  segments = lines->get_line (y);
285  if (!segments->empty ()) {
286  s_it.set_to_list (segments);
287  for (s_it.mark_cycle_pt (); !s_it.cycled_list (); s_it.forward ()) {
288  // Note different use of ICOORDELT, x coord is x coord of pixel
289  // at the start of line segment, y coord is length of line segment
290  // Last pixel is start pixel + length.
291  width = s_it.data ()->y ();
292  window->SetCursor(s_it.data ()->x (), y);
293  window->DrawTo(s_it.data ()->x () + (float) width, y);
294  }
295  }
296  }
297 }
void Pen(Color color)
Definition: scrollview.cpp:726
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
ICOORDELT_LIST * get_line(inT16 y)
Definition: polyblk.cpp:341
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
TBOX * bounding_box()
Definition: polyblk.h:38
inT16 top() const
Definition: rect.h:54
short inT16
Definition: host.h:100
PolyBlockType POLY_BLOCK::isA ( ) const
inline

Definition at line 48 of file polyblk.h.

48  {
49  return type;
50  }
bool POLY_BLOCK::IsText ( ) const
inline

Definition at line 52 of file polyblk.h.

52  {
53  return PTIsTextType(type);
54  }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70
void POLY_BLOCK::move ( ICOORD  shift)

POLY_BLOCK::move

Move the POLY_BLOCK.

Parameters
shiftx,y translation vector

Definition at line 230 of file polyblk.cpp.

230  {
231  ICOORDELT *pt; //current point
232  ICOORDELT_IT pts = &vertices; //iterator
233 
234  do {
235  pt = pts.data ();
236  *pt += shift;
237  pts.forward ();
238  }
239  while (!pts.at_first ());
240  compute_bb();
241 }
void compute_bb()
Definition: polyblk.cpp:65
bool POLY_BLOCK::overlap ( POLY_BLOCK other)
Returns
true if the polygons of other and this overlap.

Definition at line 302 of file polyblk.cpp.

302  {
303  inT16 count; // winding count
304  ICOORDELT_IT it = &vertices; // iterator
305  ICOORD vertex;
306 
307  if (!box.overlap(*(other->bounding_box())))
308  return false; // can't be any overlap.
309 
310  /* see if a vertex of this is inside other */
311 
312  do {
313  vertex = *it.data ();
314  // get winding number
315  count = other->winding_number (vertex);
316  if (count != INTERSECTING)
317  if (count != 0)
318  return true;
319  it.forward ();
320  }
321  while (!it.at_first ());
322 
323  /* see if a vertex of other is inside this */
324 
325  // switch lists
326  it.set_to_list (other->points ());
327  do {
328  vertex = *it.data();
329  // try other way round
330  count = winding_number (vertex);
331  if (count != INTERSECTING)
332  if (count != 0)
333  return true;
334  it.forward ();
335  }
336  while (!it.at_first ());
337  return false;
338 }
TBOX * bounding_box()
Definition: polyblk.h:38
ICOORDELT_LIST * points()
Definition: polyblk.h:42
integer coordinate
Definition: points.h:30
#define INTERSECTING
Definition: polyblk.cpp:32
int count(LIST var_list)
Definition: oldlist.cpp:108
inT16 winding_number(const ICOORD &test_pt)
Definition: polyblk.cpp:101
bool overlap(const TBOX &box) const
Definition: rect.h:345
short inT16
Definition: host.h:100
void POLY_BLOCK::plot ( ScrollView window,
inT32  num 
)

Definition at line 245 of file polyblk.cpp.

245  {
246  ICOORDELT_IT v = &vertices;
247 
248  window->Pen(ColorForPolyBlockType(type));
249 
250  v.move_to_first ();
251 
252  if (num > 0) {
253  window->TextAttributes("Times", 80, false, false, false);
254  char temp_buff[34];
255  #if defined(__UNIX__) || defined(MINGW)
256  sprintf(temp_buff, INT32FORMAT, num);
257  #else
258  ltoa (num, temp_buff, 10);
259  #endif
260  window->Text(v.data ()->x (), v.data ()->y (), temp_buff);
261  }
262 
263  window->SetCursor(v.data ()->x (), v.data ()->y ());
264  for (v.mark_cycle_pt (); !v.cycled_list (); v.forward ()) {
265  window->DrawTo(v.data ()->x (), v.data ()->y ());
266  }
267  v.move_to_first ();
268  window->DrawTo(v.data ()->x (), v.data ()->y ());
269 }
void Pen(Color color)
Definition: scrollview.cpp:726
static ScrollView::Color ColorForPolyBlockType(PolyBlockType type)
Returns a color to draw the given type.
Definition: polyblk.cpp:395
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:658
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
#define INT32FORMAT
Definition: host.h:115
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:641
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
ICOORDELT_LIST* POLY_BLOCK::points ( )
inline

Definition at line 42 of file polyblk.h.

42  { // access function
43  return &vertices;
44  }
void POLY_BLOCK::reflect_in_y_axis ( )

Definition at line 209 of file polyblk.cpp.

209  {
210  ICOORDELT *pt; // current point
211  ICOORDELT_IT pts = &vertices; // Iterator.
212 
213  do {
214  pt = pts.data();
215  pt->set_x(-pt->x());
216  pts.forward();
217  }
218  while (!pts.at_first());
219  compute_bb();
220 }
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void compute_bb()
Definition: polyblk.cpp:65
inT16 x() const
access function
Definition: points.h:52
void POLY_BLOCK::rotate ( FCOORD  rotation)

Definition at line 185 of file polyblk.cpp.

185  {
186  FCOORD pos; //current pos;
187  ICOORDELT *pt; //current point
188  ICOORDELT_IT pts = &vertices; //iterator
189 
190  do {
191  pt = pts.data ();
192  pos.set_x (pt->x ());
193  pos.set_y (pt->y ());
194  pos.rotate (rotation);
195  pt->set_x ((inT16) (floor (pos.x () + 0.5)));
196  pt->set_y ((inT16) (floor (pos.y () + 0.5)));
197  pts.forward ();
198  }
199  while (!pts.at_first ());
200  compute_bb();
201 }
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
float x() const
Definition: points.h:209
void rotate(const FCOORD vec)
Definition: ipoints.h:471
void compute_bb()
Definition: polyblk.cpp:65
inT16 y() const
access_function
Definition: points.h:56
void set_x(float xin)
rewrite function
Definition: points.h:216
void set_y(float yin)
rewrite function
Definition: points.h:220
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
inT16 x() const
access function
Definition: points.h:52
float y() const
Definition: points.h:212
Definition: points.h:189
short inT16
Definition: host.h:100
inT16 POLY_BLOCK::winding_number ( const ICOORD test_pt)

Definition at line 101 of file polyblk.cpp.

101  {
102  inT16 count; //winding count
103  ICOORD pt; //current point
104  ICOORD vec; //point to current point
105  ICOORD vvec; //current point to next point
106  inT32 cross; //cross product
107  ICOORDELT_IT it = &vertices; //iterator
108 
109  count = 0;
110  do {
111  pt = *it.data ();
112  vec = pt - point;
113  vvec = *it.data_relative (1) - pt;
114  //crossing the line
115  if (vec.y () <= 0 && vec.y () + vvec.y () > 0) {
116  cross = vec * vvec; //cross product
117  if (cross > 0)
118  count++; //crossing right half
119  else if (cross == 0)
120  return INTERSECTING; //going through point
121  }
122  else if (vec.y () > 0 && vec.y () + vvec.y () <= 0) {
123  cross = vec * vvec;
124  if (cross < 0)
125  count--; //crossing back
126  else if (cross == 0)
127  return INTERSECTING; //illegal
128  }
129  else if (vec.y () == 0 && vec.x () == 0)
130  return INTERSECTING;
131  it.forward ();
132  }
133  while (!it.at_first ());
134  return count; //winding number
135 }
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
#define INTERSECTING
Definition: polyblk.cpp:32
int count(LIST var_list)
Definition: oldlist.cpp:108
inT16 x() const
access function
Definition: points.h:52
short inT16
Definition: host.h:100
int inT32
Definition: host.h:102

The documentation for this class was generated from the following files: