#include <halfspaceD2.h>

#include <d2simplexSeparateAxis.h>

typedef point2<double> pt2;

//template<>
//double const halfspaceD2<point2<double>,double>::zero = 1E-15;

bool const d2simplexSeparateAxis::intersects(d2simplex const & s2) const
{
  if (sees(s2))
    return false;

  // Upcast - but unusual because only uses base classes data.
  //   The functionality was not put in the base class because
  //   it is specialized.
  d2simplexSeparateAxis * p = (d2simplexSeparateAxis*)(& s2);

  return ! p->sees(*this);
}

bool const d2simplexSeparateAxis::sees(d2simplex const & s2) const
{
  bool flag;
  uint k;

  for (uint i=0; i<3; ++i)
  {
    halfspaceD2<pt2,double> h(v[i],v[(i+2)%3]);
    flag=true;
    k=0;
    for (; flag&&(k<3); ++k)
    {
      if (h.isInside(s2.v[k])==false)
        flag=false;
    
    }
    if (flag==true)
      return true;
  }

  return false;
}




