/*-------------------------------------------------------------------------------------*/
/*  NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.0.0      */
/*                                                                                     */
/*  Copyright (C) 2001-2008  Mark Abramson        - the Boeing Company, Seattle        */
/*                           Charles Audet        - Ecole Polytechnique, Montreal      */
/*                           Gilles Couture       - Ecole Polytechnique, Montreal      */
/*                           John Dennis          - Rice University, Houston           */
/*                           Sebastien Le Digabel - Ecole Polytechnique, Montreal      */
/*                                                                                     */
/*  funded in part by AFOSR and Exxon Mobil                                            */
/*                                                                                     */
/*  Author: Sebastien Le Digabel                                                       */
/*                                                                                     */
/*  Contact information:                                                               */
/*    Ecole Polytechnique de Montreal - GERAD                                          */
/*    C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada                  */
/*    e-mail: Sebastien.Le.Digabel@gerad.ca                                            */
/*    phone : 1-514-340-6053 #6673                                                     */
/*    fax   : 1-514-340-5665                                                           */
/*                                                                                     */
/*  This program is free software: you can redistribute it and/or modify it under the  */
/*  terms of the GNU General Public License as published by the Free Software          */
/*  Foundation, either version 3 of the License, or (at your option) any later         */
/*  version.                                                                           */
/*                                                                                     */
/*  This program is distributed in the hope that it will be useful, but WITHOUT ANY    */
/*  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A    */
/*  PARTICULAR PURPOSE.  See the GNU General Public License for more details.          */
/*                                                                                     */
/*  You should have received a copy of the GNU General Public License along with this  */
/*  program. If not, see <http://www.gnu.org/licenses/>.                               */
/*                                                                                     */
/*  You can find information on the NOMAD software at www.gerad.ca/nomad               */
/*-------------------------------------------------------------------------------------*/
#include "Direction.hpp"
using namespace std;

/*-----------------------------------*/
/*   static members initialization   */
/*-----------------------------------*/
#ifdef DEBUG
int Direction::_cardinality     = 0;
int Direction::_max_cardinality = 0;
#endif

/*---------------------------------------------------------*/
/*                       constructor 1                     */
/*---------------------------------------------------------*/
Direction::Direction ( void ) : Point (                     ) ,
				_type (_UNDEFINED_DIRECTION_) ,
				_index(-1                   )   {
#ifdef DEBUG
  ++Direction::_cardinality;
  if ( Direction::_cardinality > Direction::_max_cardinality )
    ++Direction::_max_cardinality;
#endif
}

/*---------------------------------------------------------*/
/*                       constructor 2                     */
/*---------------------------------------------------------*/
Direction::Direction ( int n , const NOMAD::Double & v , direction_type type ) :
  Point (n,v ) ,
  _type (type) ,
  _index(-1  ) {
#ifdef DEBUG
  ++Direction::_cardinality;
  if ( Direction::_cardinality > Direction::_max_cardinality )
    ++Direction::_max_cardinality;
#endif
}

/*---------------------------------------------------------*/
/*                       constructor 3                     */
/*---------------------------------------------------------*/
Direction::Direction ( const Point & x , direction_type type ) :
  Point (x   ) ,
  _type (type) ,
  _index(-1  ) {
#ifdef DEBUG
  ++Direction::_cardinality;
  if ( Direction::_cardinality > Direction::_max_cardinality )
    ++Direction::_max_cardinality;
#endif
}

/*---------------------------------------------------------*/
/*                      copy constructor                   */
/*---------------------------------------------------------*/
Direction::Direction ( const Direction & d ) : Point (d       ) ,
					       _type (d._type ) ,
					       _index(d._index)   {
#ifdef DEBUG
  ++Direction::_cardinality;
  if ( Direction::_cardinality > Direction::_max_cardinality )
    ++Direction::_max_cardinality;
#endif
}

/*---------------------------------------------------------*/
/*                         destructor                      */
/*---------------------------------------------------------*/
Direction::~Direction ( void ) {
#ifdef DEBUG
  --Direction::_cardinality;
#endif
}

/*---------------------------------------------------------*/
/*                  affectation operator                   */
/*---------------------------------------------------------*/
Direction & Direction::operator = ( const Direction & d ) {
  if ( this == &d )
    return *this;

  Point::operator = (d);
  
  _type  = d._type;
  _index = d._index;

  return *this;
}

/*---------------------------------------------------------*/
/*                            clear                        */
/*---------------------------------------------------------*/
void Direction::clear ( void ) {
  Point::clear();
  _type  = _UNDEFINED_DIRECTION_;
  _index = -1;
}

/*---------------------------------------------------------*/
/*                          display                        */
/*---------------------------------------------------------*/
void Direction::display ( ostream      & out ,
			  const string & sep ,
			  int            w   ,
			  int            lim   ) const {
  out << "( ";
  Point::display ( out , sep , w , lim );
  out << " ) type=" << _type;
}

/*-----------------------------------------------------------*/
/*                           negation                        */
/*-----------------------------------------------------------*/
const Direction Direction::operator - ( void ) const {
  return Direction ( this->Point::operator-() , _type );
}
