Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

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

Prepares constraints in order to apply VPSC horizontally. Assumes variables have already been created. useNeighbourLists determines whether or not a heuristic is used to deciding whether to resolve all overlap in the x pass, or leave some overlaps for the y pass.

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

Referenced by removeRectangleOverlap().

                                                                                                                       {
      events=new Event*[2*n];
      int i,m,ctr=0;
      for(i=0;i<n;i++) {
            vars[i]->desiredPosition=rs[i]->getCentreX();
            Node *v = new Node(vars[i],rs[i],rs[i]->getCentreX());
            events[ctr++]=new Event(Open,v,rs[i]->getMinY());
            events[ctr++]=new Event(Close,v,rs[i]->getMaxY());
      }
      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);
                  if(useNeighbourLists) {
                        v->setNeighbours(
                              getLeftNeighbours(scanline,v),
                              getRightNeighbours(scanline,v)
                        );
                  } else {
                        NodeSet::iterator it=scanline.find(v);
                        if(it--!=scanline.begin()) {
                              Node *u=*it;
                              v->firstAbove=u;
                              u->firstBelow=v;
                        }
                        it=scanline.find(v);
                        if(++it!=scanline.end()) {
                              Node *u=*it;
                              v->firstBelow=u;
                              u->firstAbove=v;
                        }
                  }
            } else {
                  // Close event
                  int r;
                  if(useNeighbourLists) {
                        for(NodeSet::iterator i=v->leftNeighbours->begin();
                              i!=v->leftNeighbours->end();i++
                        ) {
                              Node *u=*i;
                              double sep = (v->r->width()+u->r->width())/2.0;
                              constraints.push_back(new Constraint(u->v,v->v,sep));
                              r=u->rightNeighbours->erase(v);
                        }
                        
                        for(NodeSet::iterator i=v->rightNeighbours->begin();
                              i!=v->rightNeighbours->end();i++
                        ) {
                              Node *u=*i;
                              double sep = (v->r->width()+u->r->width())/2.0;
                              constraints.push_back(new Constraint(v->v,u->v,sep));
                              r=u->leftNeighbours->erase(v);
                        }
                  } else {
                        Node *l=v->firstAbove, *r=v->firstBelow;
                        if(l!=NULL) {
                              double sep = (v->r->width()+l->r->width())/2.0;
                              constraints.push_back(new Constraint(l->v,v->v,sep));
                              l->firstBelow=v->firstBelow;
                        }
                        if(r!=NULL) {
                              double sep = (v->r->width()+r->r->width())/2.0;
                              constraints.push_back(new Constraint(v->v,r->v,sep));
                              r->firstAbove=v->firstAbove;
                        }
                  }
                  r=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