// Copyright (c) 1999  Max-Planck-Institute Saarbruecken (Germany).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $Source: /CVSROOT/CGAL/Packages/Convex_hull_2/include/CGAL/convex_hull_2.h,v $
// $Revision: 1.11 $ $Date: 2003/10/21 12:15:05 $
// $Name:  $
//
// Author(s)     : Stefan Schirra


#ifndef CGAL_CONVEX_HULL_2_H
#define CGAL_CONVEX_HULL_2_H

#include <CGAL/basic.h>

#ifdef CGAL_REP_CLASS_DEFINED
#include <CGAL/convex_hull_traits_2.h>
#endif // CGAL_REP_CLASS_DEFINED

#include <CGAL/ch_akl_toussaint.h>
#include <CGAL/ch_bykat.h>
#include <iterator> 

CGAL_BEGIN_NAMESPACE

template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
CGAL_convex_hull_points_2(InputIterator first, InputIterator last,
                          OutputIterator  result,
                          const Traits& ch_traits,
                          std::input_iterator_tag )
{ return ch_bykat(first, last, result, ch_traits); }

template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
CGAL_convex_hull_points_2(InputIterator first, InputIterator last,
                          OutputIterator  result,
                          const Traits& ch_traits,
                          std::forward_iterator_tag )
{ return ch_akl_toussaint(first, last, result, ch_traits); }

template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
CGAL_convex_hull_points_2(InputIterator first, InputIterator last,
                          OutputIterator  result,
                          const Traits& ch_traits,
                          std::bidirectional_iterator_tag )
{ return ch_akl_toussaint(first, last, result, ch_traits); }

template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
CGAL_convex_hull_points_2(InputIterator first, InputIterator last,
                          OutputIterator  result,
                          const Traits& ch_traits,
                          std::random_access_iterator_tag )
{ return ch_akl_toussaint(first, last, result, ch_traits); }


template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
convex_hull_points_2(InputIterator first, InputIterator last,
                     OutputIterator  result,
                     const Traits& ch_traits)
{
    typedef std::iterator_traits<InputIterator>   ITraits;
    typedef typename ITraits::iterator_category   Category;
    return CGAL_convex_hull_points_2(first, last, result, ch_traits,
                                     Category());
}


template <class ForwardIterator, class OutputIterator>
inline
OutputIterator 
convex_hull_points_2(ForwardIterator first, ForwardIterator last, 
                     OutputIterator  result )
{ 
    typedef std::iterator_traits<ForwardIterator> ITraits;
    typedef typename ITraits::value_type          value_type;
    typedef typename ITraits::iterator_category   Category;
    typedef CGAL::Kernel_traits<value_type>       KTraits;
    typedef typename KTraits::Kernel              Kernel;
    return CGAL_convex_hull_points_2(first, last, result, Kernel(), 
                                     Category());
}


// generates the counterclockwise sequence of extreme points
// of the points in the range [|first|,|last|). The resulting sequence
// is placed starting at position |result|, and the past-the-end iterator
// for the resulting sequence is returned. It is not specified, at which
// point the cyclic sequence of extreme points is cut into a linear
// sequence.
// {\it Preconditions:}
// [|first|,|last|) does not contain |result|.
// {\sc traits}: operates on |Traits::Point_2| using |Traits::Less_xy_2|, 
// |Traits::Equal_2|, |Traits::Less_yx_2|, and |Traits::Left_turn_2|.
template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
convex_hull_2(InputIterator first, InputIterator last,
              OutputIterator  result, const Traits& ch_traits)
{
    return convex_hull_points_2(first, last, result, ch_traits);
}

template <class ForwardIterator, class OutputIterator>
inline
OutputIterator 
convex_hull_2(ForwardIterator first, ForwardIterator last, 
              OutputIterator  result )
{
    return convex_hull_points_2(first, last, result);
}


// generates the counterclockwise sequence of extreme points
// on the lower hull of the points in the range [|first|,|last|). 
// The resulting sequence is placed starting at position |result|, 
// and the past-the-end iterator for the resulting sequence is returned. 
// The sequence starts with the leftmost point, the rightmost point is
// not included.
// {\it Preconditions:}
// [|first|,|last|) does not contain |result|.
// {\sc traits}: operates on |Traits::Point_2| using |Traits::Less_xy_2|
// |Traits::Equal_2| and |Traits::Left_turn_2|.
template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
lower_hull_points_2(InputIterator first, InputIterator last,
                    OutputIterator  result,
                    const Traits& ch_traits)
{ return ch_lower_hull_scan(first, last, result, ch_traits); }

template <class ForwardIterator, class OutputIterator>
inline
OutputIterator 
lower_hull_points_2(ForwardIterator first, ForwardIterator last, 
                    OutputIterator  result )
{ 
    typedef std::iterator_traits<ForwardIterator> ITraits;
    typedef typename ITraits::value_type          value_type;
    typedef CGAL::Kernel_traits<value_type>       KTraits;
    typedef typename KTraits::Kernel              Kernel;
    return lower_hull_points_2(first, last, result, Kernel());
}


// generates the counterclockwise sequence of extreme points
// on the upper hull of the points in the range [|first|,|last|). 
// The resulting sequence is placed starting at position |result|, 
// and the past-the-end iterator for the resulting sequence is returned. 
// The sequence starts with the rightmost point, the leftmost point is
// not included.
// {\it Preconditions:}
// [|first|,|last|) does not contain |result|.
// {\sc traits}: operates on |Traits::Point_2| using |Traits::Less_xy_2|,
// |Traits::Equal_2| and |Traits::Left_turn_2|.
template <class InputIterator, class OutputIterator, class Traits>
inline
OutputIterator
upper_hull_points_2(InputIterator first, InputIterator last,
                    OutputIterator  result,
                    const Traits& ch_traits)
{ return ch_upper_hull_scan(first, last, result, ch_traits); }


template <class ForwardIterator, class OutputIterator>
inline
OutputIterator 
upper_hull_points_2(ForwardIterator first, ForwardIterator last, 
                    OutputIterator  result )
{ 
    typedef std::iterator_traits<ForwardIterator> ITraits;
    typedef typename ITraits::value_type          value_type;
    typedef CGAL::Kernel_traits<value_type>       KTraits;
    typedef typename KTraits::Kernel              Kernel;
    return upper_hull_points_2(first, last, result, Kernel());
}
CGAL_END_NAMESPACE

#endif // CGAL_CONVEX_HULL_2_H







