// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#include "StdFail_NotDone.hxx"
#include "IntPatch_Line.hxx"

#define _DECAL 7
#define _DECAL2 14
#define _BASE 128
#define _BASEM1 127

//======================================================================
inline int IntPatch_PrmPrmIntersection::NbLines() const
{
  if (!done)
    throw StdFail_NotDone(" IntPatch_PrmPrmIntersection ");
  return (SLin.Length());
}

//======================================================================
inline const occ::handle<IntPatch_Line>& IntPatch_PrmPrmIntersection::Line(const int n) const
{
  if (!done)
    throw StdFail_NotDone(" IntPatch_PrmPrmIntersection ");
  return (SLin.Value(n));
}

//======================================================================
inline bool IntPatch_PrmPrmIntersection::IsEmpty() const
{
  if (!done)
    throw StdFail_NotDone(" IntPatch_PrmPrmIntersection ");
  return (empt);
}

//======================================================================
inline bool IntPatch_PrmPrmIntersection::IsDone() const
{
  return (done);
}

inline int IntPatch_PrmPrmIntersection::GrilleInteger(const int ix,
                                                      const int iy,
                                                      const int iz) const
{
  int tz = iz << _DECAL2;
  int ty = iy << _DECAL;
  int t  = ix;
  t |= ty;
  t |= tz;
  return (t);
}

inline void IntPatch_PrmPrmIntersection::IntegerGrille(const int tt,
                                                       int&      ix,
                                                       int&      iy,
                                                       int&      iz) const
{
  int t = tt;
  ix    = t & _BASEM1;
  t >>= _DECAL;
  iy = t & _BASEM1;
  t >>= _DECAL;
  iz = t;
}

inline int IntPatch_PrmPrmIntersection::DansGrille(const int t) const
{
  if (t >= 0)
  {
    if (t < _BASE)
    {
      return (1);
    }
  }
  return (0);
}

inline int IntPatch_PrmPrmIntersection::NbPointsGrille() const
{
  return (_BASE);
}

inline int IntPatch_PrmPrmIntersection::CodeReject(const double x0,
                                                   const double y0,
                                                   const double z0,
                                                   const double x1,
                                                   const double y1,
                                                   const double z1,
                                                   const double x,
                                                   const double y,
                                                   const double z) const
{
  int code = 0;
  if (x < x0)
    code = 1;
  if (y < y0)
    code |= 2;
  if (z < z0)
    code |= 4;
  if (x > x1)
    code |= 8;
  if (y > y1)
    code |= 16;
  if (z > z1)
    code |= 32;
  return (code);
}
