/usr/include/boost/geometry/algorithms
Edit: /usr/include/boost/geometry/algorithms/convex_hull.hpp (11589B)
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
// This file was modified by Oracle on 2014, 2015.
// Modifications copyright (c) 2014-2015 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_ALGORITHMS_CONVEX_HULL_HPP
#define BOOST_GEOMETRY_ALGORITHMS_CONVEX_HULL_HPP
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace convex_hull
{
template
struct hull_insert
{
// Member template function (to avoid inconvenient declaration
// of output-iterator-type, from hull_to_geometry)
template
static inline OutputIterator apply(Geometry const& geometry,
OutputIterator out, Strategy const& strategy)
{
typename Strategy::state_type state;
strategy.apply(geometry, state);
strategy.result(state, out, Order == clockwise, Closure != open);
return out;
}
};
struct hull_to_geometry
{
template
static inline void apply(Geometry const& geometry, OutputGeometry& out,
Strategy const& strategy)
{
hull_insert
<
geometry::point_order::value,
geometry::closure::value
>::apply(geometry,
range::back_inserter(
// Handle linestring, ring and polygon the same:
detail::as_range
<
typename range_type::type
>(out)), strategy);
}
};
}} // namespace detail::convex_hull
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template
<
typename Geometry,
typename Tag = typename tag::type
>
struct convex_hull
: detail::convex_hull::hull_to_geometry
{};
template
struct convex_hull
{
template
static inline void apply(Box const& box, OutputGeometry& out,
Strategy const& )
{
static bool const Close
= geometry::closure::value == closed;
static bool const Reverse
= geometry::point_order::value == counterclockwise;
// A hull for boxes is trivial. Any strategy is (currently) skipped.
boost::array::type, 4> range;
geometry::detail::assign_box_corners_oriented(box, range);
geometry::append(out, range);
if (BOOST_GEOMETRY_CONDITION(Close))
{
geometry::append(out, *boost::begin(range));
}
}
};
template
struct convex_hull_insert
: detail::convex_hull::hull_insert
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
namespace resolve_strategy {
struct convex_hull
{
template
static inline void apply(Geometry const& geometry,
OutputGeometry& out,
Strategy const& strategy)
{
BOOST_CONCEPT_ASSERT( (geometry::concepts::ConvexHullStrategy) );
dispatch::convex_hull::apply(geometry, out, strategy);
}
template
static inline void apply(Geometry const& geometry,
OutputGeometry& out,
default_strategy)
{
typedef typename strategy_convex_hull<
Geometry,
typename point_type::type
>::type strategy_type;
apply(geometry, out, strategy_type());
}
};
struct convex_hull_insert
{
template
static inline OutputIterator apply(Geometry const& geometry,
OutputIterator& out,
Strategy const& strategy)
{
BOOST_CONCEPT_ASSERT( (geometry::concepts::ConvexHullStrategy) );
return dispatch::convex_hull_insert<
geometry::point_order::value,
geometry::closure::value
>::apply(geometry, out, strategy);
}
template
static inline OutputIterator apply(Geometry const& geometry,
OutputIterator& out,
default_strategy)
{
typedef typename strategy_convex_hull<
Geometry,
typename point_type::type
>::type strategy_type;
return apply(geometry, out, strategy_type());
}
};
} // namespace resolve_strategy
namespace resolve_variant {
template
struct convex_hull
{
template
static inline void apply(Geometry const& geometry, OutputGeometry& out, Strategy const& strategy)
{
concepts::check_concepts_and_equal_dimensions<
const Geometry,
OutputGeometry
>();
resolve_strategy::convex_hull::apply(geometry, out, strategy);
}
};
template
struct convex_hull >
{
template
struct visitor: boost::static_visitor
{
OutputGeometry& m_out;
Strategy const& m_strategy;
visitor(OutputGeometry& out, Strategy const& strategy)
: m_out(out), m_strategy(strategy)
{}
template
void operator()(Geometry const& geometry) const
{
convex_hull::apply(geometry, m_out, m_strategy);
}
};
template
static inline void
apply(boost::variant const& geometry,
OutputGeometry& out,
Strategy const& strategy)
{
boost::apply_visitor(visitor(out, strategy), geometry);
}
};
template
struct convex_hull_insert
{
template
static inline OutputIterator apply(Geometry const& geometry, OutputIterator& out, Strategy const& strategy)
{
// Concept: output point type = point type of input geometry
concepts::check();
concepts::check::type>();
return resolve_strategy::convex_hull_insert::apply(geometry, out, strategy);
}
};
template
struct convex_hull_insert >
{
template
struct visitor: boost::static_visitor
{
OutputIterator& m_out;
Strategy const& m_strategy;
visitor(OutputIterator& out, Strategy const& strategy)
: m_out(out), m_strategy(strategy)
{}
template
OutputIterator operator()(Geometry const& geometry) const
{
return convex_hull_insert::apply(geometry, m_out, m_strategy);
}
};
template
static inline OutputIterator
apply(boost::variant const& geometry,
OutputIterator& out,
Strategy const& strategy)
{
return boost::apply_visitor(visitor(out, strategy), geometry);
}
};
} // namespace resolve_variant
template
inline void convex_hull(Geometry const& geometry,
OutputGeometry& out, Strategy const& strategy)
{
if (geometry::is_empty(geometry))
{
// Leave output empty
return;
}
resolve_variant::convex_hull::apply(geometry, out, strategy);
}
/*!
\brief \brief_calc{convex hull}
\ingroup convex_hull
\details \details_calc{convex_hull,convex hull}.
\tparam Geometry the input geometry type
\tparam OutputGeometry the output geometry type
\param geometry \param_geometry, input geometry
\param hull \param_geometry \param_set{convex hull}
\qbk{[include reference/algorithms/convex_hull.qbk]}
*/
template
inline void convex_hull(Geometry const& geometry,
OutputGeometry& hull)
{
geometry::convex_hull(geometry, hull, default_strategy());
}
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace convex_hull
{
template
inline OutputIterator convex_hull_insert(Geometry const& geometry,
OutputIterator out, Strategy const& strategy)
{
return resolve_variant::convex_hull_insert
::apply(geometry, out, strategy);
}
/*!
\brief Calculate the convex hull of a geometry, output-iterator version
\ingroup convex_hull
\tparam Geometry the input geometry type
\tparam OutputIterator: an output-iterator
\param geometry the geometry to calculate convex hull from
\param out an output iterator outputing points of the convex hull
\note This overloaded version outputs to an output iterator.
In this case, nothing is known about its point-type or
about its clockwise order. Therefore, the input point-type
and order are copied
*/
template
inline OutputIterator convex_hull_insert(Geometry const& geometry,
OutputIterator out)
{
return convex_hull_insert(geometry, out, default_strategy());
}
}} // namespace detail::convex_hull
#endif // DOXYGEN_NO_DETAIL
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_CONVEX_HULL_HPP