tools/lgf-gen.cc
changeset 1135 5de6a70446f6
parent 654 a312f84d86c6
equal deleted inserted replaced
7:64701ea2035c 8:a506f2f3ebad
   244     double& _sweep;
   244     double& _sweep;
   245   };
   245   };
   246 
   246 
   247   struct BeachIt;
   247   struct BeachIt;
   248 
   248 
   249   typedef std::multimap<double, BeachIt> SpikeHeap;
   249   typedef std::multimap<double, BeachIt*> SpikeHeap;
   250 
   250 
   251   typedef std::multimap<Part, SpikeHeap::iterator, YLess> Beach;
   251   typedef std::multimap<Part, SpikeHeap::iterator, YLess> Beach;
   252 
   252 
   253   struct BeachIt {
   253   struct BeachIt {
   254     Beach::iterator it;
   254     Beach::iterator it;
   327       sweep = siteheap[siteindex].first;
   327       sweep = siteheap[siteindex].first;
   328 
   328 
   329       Beach::iterator bit = beach.upper_bound(Part(site, site, site));
   329       Beach::iterator bit = beach.upper_bound(Part(site, site, site));
   330 
   330 
   331       if (bit->second != spikeheap.end()) {
   331       if (bit->second != spikeheap.end()) {
       
   332         delete bit->second->second;
   332         spikeheap.erase(bit->second);
   333         spikeheap.erase(bit->second);
   333       }
   334       }
   334 
   335 
   335       int prev = bit->first.prev;
   336       int prev = bit->first.prev;
   336       int curr = bit->first.curr;
   337       int curr = bit->first.curr;
   340 
   341 
   341       SpikeHeap::iterator pit = spikeheap.end();
   342       SpikeHeap::iterator pit = spikeheap.end();
   342       if (prev != -1 &&
   343       if (prev != -1 &&
   343           circle_form(points[prev], points[curr], points[site])) {
   344           circle_form(points[prev], points[curr], points[site])) {
   344         double x = circle_point(points[prev], points[curr], points[site]);
   345         double x = circle_point(points[prev], points[curr], points[site]);
   345         pit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));
   346         pit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end())));
   346         pit->second.it =
   347         pit->second->it =
   347           beach.insert(std::make_pair(Part(prev, curr, site), pit));
   348           beach.insert(std::make_pair(Part(prev, curr, site), pit));
   348       } else {
   349       } else {
   349         beach.insert(std::make_pair(Part(prev, curr, site), pit));
   350         beach.insert(std::make_pair(Part(prev, curr, site), pit));
   350       }
   351       }
   351 
   352 
   353 
   354 
   354       SpikeHeap::iterator nit = spikeheap.end();
   355       SpikeHeap::iterator nit = spikeheap.end();
   355       if (next != -1 &&
   356       if (next != -1 &&
   356           circle_form(points[site], points[curr],points[next])) {
   357           circle_form(points[site], points[curr],points[next])) {
   357         double x = circle_point(points[site], points[curr], points[next]);
   358         double x = circle_point(points[site], points[curr], points[next]);
   358         nit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));
   359         nit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end())));
   359         nit->second.it =
   360         nit->second->it =
   360           beach.insert(std::make_pair(Part(site, curr, next), nit));
   361           beach.insert(std::make_pair(Part(site, curr, next), nit));
   361       } else {
   362       } else {
   362         beach.insert(std::make_pair(Part(site, curr, next), nit));
   363         beach.insert(std::make_pair(Part(site, curr, next), nit));
   363       }
   364       }
   364 
   365 
   365       ++siteindex;
   366       ++siteindex;
   366     } else {
   367     } else {
   367       sweep = spit->first;
   368       sweep = spit->first;
   368 
   369 
   369       Beach::iterator bit = spit->second.it;
   370       Beach::iterator bit = spit->second->it;
   370 
   371 
   371       int prev = bit->first.prev;
   372       int prev = bit->first.prev;
   372       int curr = bit->first.curr;
   373       int curr = bit->first.curr;
   373       int next = bit->first.next;
   374       int next = bit->first.next;
   374 
   375 
   397       Beach::iterator pbit = bit; --pbit;
   398       Beach::iterator pbit = bit; --pbit;
   398       int ppv = pbit->first.prev;
   399       int ppv = pbit->first.prev;
   399       Beach::iterator nbit = bit; ++nbit;
   400       Beach::iterator nbit = bit; ++nbit;
   400       int nnt = nbit->first.next;
   401       int nnt = nbit->first.next;
   401 
   402 
   402       if (bit->second != spikeheap.end()) spikeheap.erase(bit->second);
   403       if (bit->second != spikeheap.end())
   403       if (pbit->second != spikeheap.end()) spikeheap.erase(pbit->second);
   404         {
   404       if (nbit->second != spikeheap.end()) spikeheap.erase(nbit->second);
   405           delete bit->second->second;
   405 
   406           spikeheap.erase(bit->second);
       
   407         }
       
   408       if (pbit->second != spikeheap.end())
       
   409         {
       
   410           delete pbit->second->second;
       
   411           spikeheap.erase(pbit->second);
       
   412         }
       
   413       if (nbit->second != spikeheap.end())
       
   414         {
       
   415           delete nbit->second->second;
       
   416           spikeheap.erase(nbit->second);
       
   417         }
       
   418       
   406       beach.erase(nbit);
   419       beach.erase(nbit);
   407       beach.erase(bit);
   420       beach.erase(bit);
   408       beach.erase(pbit);
   421       beach.erase(pbit);
   409 
   422 
   410       SpikeHeap::iterator pit = spikeheap.end();
   423       SpikeHeap::iterator pit = spikeheap.end();
   411       if (ppv != -1 && ppv != next &&
   424       if (ppv != -1 && ppv != next &&
   412           circle_form(points[ppv], points[prev], points[next])) {
   425           circle_form(points[ppv], points[prev], points[next])) {
   413         double x = circle_point(points[ppv], points[prev], points[next]);
   426         double x = circle_point(points[ppv], points[prev], points[next]);
   414         if (x < sweep) x = sweep;
   427         if (x < sweep) x = sweep;
   415         pit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));
   428         pit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end())));
   416         pit->second.it =
   429         pit->second->it =
   417           beach.insert(std::make_pair(Part(ppv, prev, next), pit));
   430           beach.insert(std::make_pair(Part(ppv, prev, next), pit));
   418       } else {
   431       } else {
   419         beach.insert(std::make_pair(Part(ppv, prev, next), pit));
   432         beach.insert(std::make_pair(Part(ppv, prev, next), pit));
   420       }
   433       }
   421 
   434 
   422       SpikeHeap::iterator nit = spikeheap.end();
   435       SpikeHeap::iterator nit = spikeheap.end();
   423       if (nnt != -1 && prev != nnt &&
   436       if (nnt != -1 && prev != nnt &&
   424           circle_form(points[prev], points[next], points[nnt])) {
   437           circle_form(points[prev], points[next], points[nnt])) {
   425         double x = circle_point(points[prev], points[next], points[nnt]);
   438         double x = circle_point(points[prev], points[next], points[nnt]);
   426         if (x < sweep) x = sweep;
   439         if (x < sweep) x = sweep;
   427         nit = spikeheap.insert(std::make_pair(x, BeachIt(beach.end())));
   440         nit = spikeheap.insert(std::make_pair(x, new BeachIt(beach.end())));
   428         nit->second.it =
   441         nit->second->it =
   429           beach.insert(std::make_pair(Part(prev, next, nnt), nit));
   442           beach.insert(std::make_pair(Part(prev, next, nnt), nit));
   430       } else {
   443       } else {
   431         beach.insert(std::make_pair(Part(prev, next, nnt), nit));
   444         beach.insert(std::make_pair(Part(prev, next, nnt), nit));
   432       }
   445       }
   433 
   446