Logo Search packages:      
Sourcecode: inkscape version File versions

int vpsc::generateYConstraints ( const int  n,
Rectangle **  rs,
Variable **  vars,
Constraint **&  cs 
)

Prepares constraints in order to apply VPSC vertically to remove ALL overlap.

Definition at line 255 of file generate-constraints.cpp.

                                                                                         {
      events=new Event*[2*n];
      int ctr=0,i,m;
      for(i=0;i<n;i++) {
            vars[i]->desiredPosition=rs[i]->getCentreY();
            Node *v = new Node(vars[i],rs[i],rs[i]->getCentreY());
            events[ctr++]=new Event(Open,v,rs[i]->getMinX());
            events[ctr++]=new Event(Close,v,rs[i]->getMaxX());
      }
      qsort((Event*)events, (size_t)2*n, sizeof(Event*), compare_events );
      NodeSet scanline;
      vector<Constraint*> constraints;
      for(i=0;i<2*n;i++) {
            Event *e=events[i];
            Node *v=e->v;
            if(e->type==Open) {
                  scanline.insert(v);
                  NodeSet::iterator i=scanline.find(v);
                  if(i--!=scanline.begin()) {
                        Node *u=*i;
                        v->firstAbove=u;
                        u->firstBelow=v;
                  }
                  i=scanline.find(v);
                  if(++i!=scanline.end())  {
                        Node *u=*i;
                        v->firstBelow=u;
                        u->firstAbove=v;
                  }
            } else {
                  // Close event
                  Node *l=v->firstAbove, *r=v->firstBelow;
                  if(l!=NULL) {
                        double sep = (v->r->height()+l->r->height())/2.0;
                        constraints.push_back(new Constraint(l->v,v->v,sep));
                        l->firstBelow=v->firstBelow;
                  }
                  if(r!=NULL) {
                        double sep = (v->r->height()+r->r->height())/2.0;
                        constraints.push_back(new Constraint(v->v,r->v,sep));
                        r->firstAbove=v->firstAbove;
                  }
                  scanline.erase(v);
                  delete v;
            }
            delete e;
      }
      delete [] events;
      cs=new Constraint*[m=constraints.size()];
      for(i=0;i<m;i++) cs[i]=constraints[i];
      return m;
}


Generated by  Doxygen 1.6.0   Back to index