void composite_box_rep::finalize () { int i, n= subnr (); lip= descend (ip, 0); rip= descend (ip, 1); for (i=0; i<n; i++) { path l= bs[i]->find_lip (); path r= bs[i]->find_rip (); /* cout << " i = " << i << "\n"; cout << " l = " << l << "\n"; cout << " r = " << r << "\n"; */ if (is_accessible (l) && is_accessible (r)) { if (is_decoration (lip) || path_less (reverse (l), reverse (lip))) lip= l; if (is_decoration (rip) || path_less (reverse (rip), reverse (r))) rip= r; } } /* cout << ((tree) (*((box_rep*) this))) << " " << ip << "\n"; cout << " lip= " << lip << "\n"; cout << " rip= " << rip << "\n"; */ }
void composite_box_rep::left_justify () { int i, n= subnr(); SI d= x1; x1-=d; x2-=d; x3-=d; x4-=d; for (i=0; i<n; i++) sx(i) -= d; }
void box_rep::relocate (path new_ip, bool force) { if (!force) if (is_nil (ip) || (ip->item >= 0) || (ip == new_ip)) return; ip= new_ip; int i, n= subnr (); for (i=0; i<n; i++) subbox (i)->relocate (ip, force); }
gr_selections composite_box_rep::graphical_select (SI x, SI y, SI dist) { gr_selections res; if (graphical_distance (x, y) <= dist) { int i, n= subnr(); for (i=0; i<n; i++) res << bs[i]->graphical_select (x- sx(i), y- sy(i), dist); } return res; }
int scatter_box_rep::find_child (SI x, SI y, SI delta, bool force) { int i, n= subnr(), d= MAX_SI, m= -1; for (i=0; i<n; i++) if (distance (i, x, y, delta)< d) if (bs[i]->accessible () || force) { d= distance (i, x, y, delta); m= i; } return m; }
gr_selections composite_box_rep::graphical_select (SI x1, SI y1, SI x2, SI y2) { gr_selections res; if (contains_rectangle (x1, y1, x2, y2)) { int i, n= subnr(); for (i=0; i<n; i++) res << bs[i]->graphical_select (x1- sx(i), y1- sy(i), x2- sx(i), y2- sy(i)); } return res; }
composite_box_rep::composite_box_rep ( path ip, array<box> B, array<SI> x, array<SI> y): box_rep (ip) { bs= B; int i, n= subnr(); for (i=0; i<n; i++) { sx(i)= x[i]; sy(i)= y[i]; } position (); }
int composite_box_rep::find_child (SI x, SI y, SI delta, bool force) { if (outside (x, delta, x1, x2) && (is_accessible (ip) || force)) return -1; int i, n= subnr(), d= MAX_SI, m= -1; for (i=0; i<n; i++) if (distance (i, x, y, delta)< d) if (bs[i]->accessible () || force) { d= distance (i, x, y, delta); m= i; } return m; }
box composite_box_rep::transform (frame fr) { int i; array<box> bs; for (i= 0; i<subnr(); i++) { if (!is_nil (subbox (i))) { box sb= subbox (i)->transform (fr); if (!is_nil (sb)) bs << sb; } } return N (bs)==0?box ():composite_box (ip, bs); }
path composite_box_rep::find_box_path (SI x, SI y, SI delta, bool force, bool& found) { int i, n= subnr(), m= find_child (x, y, delta, force); if (m != -1) for (i=0; i<=n; i++) { int c= (m+i) % n; SI xx= x- sx(c), yy= y- sy(c); SI dd= delta + get_delta (xx, bs[c]->x1, bs[c]->x2); path r= path (c, bs[c]->find_box_path (xx, yy, dd, force, found)); if (found || i == n) return r; } return box_rep::find_box_path (x, y, delta, force, found); }
void composite_box_rep::position () { int i, n= subnr(); if (n == 0) { x1= y1= x3= y3= 0; x2= y2= x4= y4= 0; FAILED ("empty composite box"); } else { x1= y1= x3= y3= MAX_SI; x2= y2= x4= y4= -MAX_SI; for (i=0; i<n; i++) { x1= min (x1, sx1(i)); y1= min (y1, sy1(i)); x2= max (x2, sx2(i)); y2= max (y2, sy2(i)); x3= min (x3, sx3(i)); y3= min (y3, sy3(i)); x4= max (x4, sx4(i)); y4= max (y4, sy4(i)); } } }
path composite_box_rep::find_box_path (path p, bool& found) { // cout << "Find box path " << box (this) << ", " << p // << "; " << reverse (ip) // << ", " << reverse (find_lip ()) // << " -- " << reverse (find_rip ()) << "\n"; int n= subnr(); // cout << "Search cursor " << p << " among " << n // << " at " << box (this) << " " << reverse (ip) << "\n"; if (n == 0) return box_rep::find_box_path (p, found); int start= n>>1, acc= start, step= (start+1)>>1; while (step > 0) { path sr= bs[acc]->find_rip (); while (!is_accessible (sr)) { acc--; if (acc<0) break; sr= bs[acc]->find_rip (); } if (acc<0) { start= 0; break; } if (path_less (reverse (sr), p)) { int old_start= start, old_acc= acc; start= min (n-1, start+ step); acc = start; while ((acc > old_start) && (!is_accessible (bs[acc]->find_rip ()))) acc--; if (acc == old_start) acc= old_acc; } else { start= max (0, start- step); acc = min (acc, start); } if (step <= 1) break; step= (step+1)>>1; } path bp; bool flag= false; int i= start; found= false; while (true) { path sl= bs[i]->find_lip (); path sr= bs[i]->find_rip (); // cout << " " << i << ":\t" << reverse(sl) <<", "<< reverse(sr) << "\n"; if (is_accessible (sl) && is_accessible (sr) && path_less_eq (reverse (sl), p) && path_less_eq (p, reverse (sr))) { flag= true; bp= path (i, bs[i]->find_box_path (p, found)); if (found) return bp; } i++; if (i==n) i=0; if (i==start) break; } if (is_accessible (ip) && (path_up (p) == reverse (ip)) && access_allowed ()) return box_rep::find_box_path (p, found); if (flag) return bp; if (start > 0) { path sl= bs[start-1]->find_rip (); path sr= bs[start ]->find_lip (); if (is_accessible (sl) && is_accessible (sr) && path_less_eq (reverse (sl), p) && path_less_eq (p, reverse (sr))) { int c1= N (common (reverse (sl), p)); int c2= N (common (reverse (sr), p)); int i = (c1 >= c2? start-1: start); return path (i, bs[i]->find_box_path (p, found)); } } return box_rep::find_box_path (p, flag); }