//#####################################################################
// Copyright 2009, Avi Robinson-Mosher, Craig Schroeder.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
// Class FACE_INDEX
//#####################################################################
#ifndef __FACE_INDEX__
#define __FACE_INDEX__

#include <Core/Vectors/VECTOR.h>
namespace PhysBAM{

template<int d>
class FACE_INDEX
{
    typedef VECTOR<int,d> IV;
public:
    FACE_INDEX()
        :axis(0)
    {}

    FACE_INDEX(int axis_input,const IV& index_input)
        :axis(axis_input),index(index_input)
    {}

    int axis;
    IV index;

    bool operator==(const FACE_INDEX& fi) const
    {return axis==fi.axis && index==fi.index;}

    bool operator!=(const FACE_INDEX& fi) const
    {return !(*this==fi);}

    IV First_Cell_Index() const
    {IV i(index);i(axis)--;return i;}

    IV Second_Cell_Index() const
    {return index;}

    IV Cell_Index(int j) const
    {IV i(index);i(axis)+=j-1;return i;}

    template<class RW> void Read(UNTYPED_ISTREAM<RW>& input);
    template<class RW> void Write(UNTYPED_OSTREAM<RW>& output) const;
};
template<int d>
inline std::ostream& operator<<(std::ostream& output,const FACE_INDEX<d>& fi)
{output<<"("<<fi.axis<<" "<<fi.index<<")";return output;}
template<int d> struct HASH_REDUCE<FACE_INDEX<d> >
{static int H(const FACE_INDEX<d>& key){return int_hash(key.axis,HASH_REDUCE<VECTOR<int,d> >::H(key.index));}};
}
#endif
