Esempio n. 1
0
void find_blob_limits(                  //get y limits
                      PBLOB *blob,      //blob to search
                      float leftx,      //x limits
                      float rightx,
                      FCOORD rotation,  //for landscape
                      float &ymin,      //output y limits
                      float &ymax) {
  float testy;                   //y intercept
  FCOORD pos;                    //rotated
  FCOORD vec;
  POLYPT *polypt;                //current point
                                 //outlines
  OUTLINE_IT out_it = blob->out_list ();
  POLYPT_IT poly_it;             //outline pts

  ymin = (float) MAX_INT32;
  ymax = (float) -MAX_INT32;
  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
                                 //get points
    poly_it.set_to_list (out_it.data ()->polypts ());
    for (poly_it.mark_cycle_pt (); !poly_it.cycled_list ();
    poly_it.forward ()) {
      polypt = poly_it.data ();
      pos = polypt->pos;
      pos.rotate (rotation);
      vec = polypt->vec;
      vec.rotate (rotation);
      if (pos.x () < leftx && pos.x () + vec.x () > leftx
      || pos.x () > leftx && pos.x () + vec.x () < leftx) {
        testy = pos.y () + vec.y () * (leftx - pos.x ()) / vec.x ();
        //intercept of boundary
        if (testy < ymin)
          ymin = testy;
        if (testy > ymax)
          ymax = testy;
      }
      if (pos.x () >= leftx && pos.x () <= rightx) {
        if (pos.y () > ymax)
          ymax = pos.y ();
        if (pos.y () < ymin)
          ymin = pos.y ();
      }
      if (pos.x () > rightx && pos.x () + vec.x () < rightx
      || pos.x () < rightx && pos.x () + vec.x () > rightx) {
        testy = pos.y () + vec.y () * (rightx - pos.x ()) / vec.x ();
        //intercept of boundary
        if (testy < ymin)
          ymin = testy;
        if (testy > ymax)
          ymax = testy;
      }
    }
  }
}
Esempio n. 2
0
void POLY_BLOCK::rotate(FCOORD rotation) {
  FCOORD pos;                    //current pos;
  ICOORDELT *pt;                 //current point
  ICOORDELT_IT pts = &vertices;  //iterator

  do {
    pt = pts.data ();
    pos.set_x (pt->x ());
    pos.set_y (pt->y ());
    pos.rotate (rotation);
    pt->set_x ((inT16) (floor (pos.x () + 0.5)));
    pt->set_y ((inT16) (floor (pos.y () + 0.5)));
    pts.forward ();
  }
  while (!pts.at_first ());
  compute_bb();
}