/*
    C++ Mesh Generation Library
    Copyright (c) 2000echet <eric at bechet dot ca>

    This file is part of the C++ Mesh Generation Library.

    See the NOTICE & LICENSE files for conditions.
*/
#include "AOMDElement.h"
#include "AOMDNode.h"

namespace FM
{
  void AOMDElement::GetNodes ( vector<AOMDNode> &tab ) const
  {
    int sz=paomd->size ( 0 );

    for ( int i=0; i<sz; i++ )
    {
      tab.push_back ( AOMDNode ( ( AOMD::mVertex * ) paomd->get ( 0,i ) ) );
    }
  }

  void AOMDElement::GetNeighbors ( vector<AOMDElement> &tab ) const
  {
    int dim=paomd->getLevel();
    int szed=paomd->size ( dim-1 );

    for ( int ed=0; ed<szed; ed++ )
    {
      AOMD::mEntity *ped=paomd->get ( dim-1,ed );
      int szel=ped->size ( dim );

      for ( int el=0; el<szel; el++ )
      {
        AOMD::mEntity *ele2=ped->get ( dim,el );

        if ( ele2!=paomd )
        {
          tab.push_back ( AOMDElement ( ele2 ) );
        }
      }
    }
  }


  void AOMDElement::CommonNodes ( const AOMDElement &other,vector<AOMDNode> &tabcommon,vector<AOMDNode> &tabother ) const
  {
    vector<AOMDNode> curr,oth;
    GetNodes ( curr );
    other.GetNodes ( oth );

    for ( int i=0; i<curr.size(); ++i )
    {
      vector<AOMDNode>::iterator it;
      it=find ( oth.begin(),oth.end(),curr[i] );

      if ( it==oth.end() )
      {
        tabother.push_back ( curr[i] );
      }
      else
      {
        tabcommon.push_back ( curr[i] );
      }
    }
  }

  void AOMDElement::CommonNodes ( const AOMDElement &other,vector<AOMDNode> &tabcommon,vector<AOMDNode> &tabother,vector<AOMDNode> &tabother2 ) const
  {
    vector<AOMDNode> curr,oth;
    GetNodes ( curr );
    other.GetNodes ( oth );

    for ( int i=0; i<curr.size(); ++i )
    {
      vector<AOMDNode>::iterator it;
      it=find ( oth.begin(),oth.end(),curr[i] );

      if ( it==oth.end() )
      {
        tabother.push_back ( curr[i] );
      }
      else
      {
        tabcommon.push_back ( curr[i] );
        oth.erase ( it );
      }
    }

    tabother2=oth;
  }



}
 
