// Vorosweep - Copyright (C) 2010-2014 T. Mouton
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to <thibaud.mouton@gmail.com>.

#include "vorosweep.h"

using namespace vorosweep;

void Graph::handle_newfacetswitch ( Event *ev )
{
	SweepFacet *sf = ev->get_sweepfacet();
  if ( sf->is_stopped() )
    return;
  double *pos = ev->get_coord();
  double time = ev->get_time();
  int gid = ev->get_gid();
  if ( gid == -1 ) // no need to set the facet stopped
    return;
  // add mc to the newly entered cell
  dbgprintf ( 5, "--> inserting facet in cell %d\n", gid );
  bucketgrid->insert_sweepfacet ( sf, gid );
  // compute next facet switch events
  Event *eventlist[MAX_EVENT_LIST];
  int nbe = 0;
  next_facetswitch ( sf, pos, gid, eventlist, nbe );
  dbgprintf ( 5, "--> listing %d next facet switch events :\n", nbe );
  for ( int i = 0; i < nbe; i++ )
  {
    Event *next = eventlist[i];
    dbgprintf ( 5, "--> next switch event add :\n" );
    add_event ( next );
  }
  
  // check for potential crash events in cell gid
  process_facet_events ( sf, time, gid );
}