// 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 "common.h"
#include "elementary.h"
#include <geom.h>

#ifndef _EVENT_INCLUDE
#define _EVENT_INCLUDE

namespace vorosweep
{
class Border;
class SweepObject;
class SweepEdge;
class SweepFacet;
class Convex_generator;

class Event
{
    friend class EventPtrComp;

  public:
    static const char *eventtypename[];
  public:
    enum eventtype
    {
      NEWBORDEREDGESWITCH,
      NEWEDGESWITCH,
      NEWFACETSWITCH,
      NEWGENERATOR,
      EDGE_EDGECRASH,
      EDGE_FACETCRASH,
      EDGE_BORDERCRASH,
      FACET_BORDERCRASH,
      EDGESWITCH,
      FACETSWITCH,
      BORDEREDGESWITCH
    };
    enum eventstatus
    {
      ENABLE,
      DISABLE
    };
  private:
    double p[2];
    double time; // time of event
    eventtype type;
    eventstatus status;
    int gid;
    // the following things should be unioned :
    SweepObject *so[2];
    Border *brd;
    Convex_generator *cg;

  public:
    Event ();
    void init ( SweepObject *s, double *pos, double t, eventtype what, int index_in_grid );
    void init ( SweepObject *s0, SweepObject *s1, double *pos, double t, eventtype what, int index_in_grid );
    void init ( SweepObject *s, Border *b, double *pos, double t, eventtype what, int index_in_grid );
    void init ( Convex_generator *g, double *pos, double t, eventtype what, int index_in_grid );

    inline SweepObject *get_sweepobject()
    {
      return so[0];
    }
    inline SweepObject *get_sweepobject ( int i )
    {
      return so[i];
    }
    SweepEdge *get_sweepedge();
    SweepFacet *get_sweepfacet();
    SweepEdge *get_sweepedge ( int i );
    SweepFacet *get_sweepfacet ( int i );
    inline Border *get_border ()
    {
      return brd;
    }
    inline Convex_generator *get_generator ()
    {
      return cg;
    }
    inline double *get_coord()
    {
      return p;
    }
    inline double get_time()
    {
      return time;
    }
    inline eventtype get_type()
    {
      return type;
    }
    inline int get_gid()
    {
      return gid;
    }
    inline void disable()
    {
      dbgprintf(2, "disabling event %p\n", this);
      status = Event::DISABLE;
    }
    inline int enabled()
    {
      return (status == Event::ENABLE);
    }
    inline int disabled()
    {
      return (status == Event::DISABLE);
    }
    void print();
};

class EventPtrComp
{
  public:
    bool operator() ( const Event* a, const Event* b );
};

// class BorderEvent : public Event
// {
//     private:
//       Border *brd;
//     public:
//     void init ( SweepObject *s, Border *b, double *pos, double t, eventtype what, int index_in_grid );
//     inline Border *get_border ()
//     {
//       return brd;
//     }
// };

};

#endif


