/usr/include/boost/polygon
Edit: /usr/include/boost/polygon/polygon_traits.hpp (74180B)
/*
Copyright 2008 Intel Corporation
Use, modification and distribution are 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_POLYGON_POLYGON_TRAITS_HPP
#define BOOST_POLYGON_POLYGON_TRAITS_HPP
namespace boost { namespace polygon{
template
struct polygon_90_traits {
typedef typename T::coordinate_type coordinate_type;
typedef typename T::compact_iterator_type compact_iterator_type;
// Get the begin iterator
static inline compact_iterator_type begin_compact(const T& t) {
return t.begin_compact();
}
// Get the end iterator
static inline compact_iterator_type end_compact(const T& t) {
return t.end_compact();
}
// Get the number of sides of the polygon
static inline std::size_t size(const T& t) {
return t.size();
}
// Get the winding direction of the polygon
static inline winding_direction winding(const T&) {
return unknown_winding;
}
};
template
struct polygon_traits_general {
typedef typename T::coordinate_type coordinate_type;
typedef typename T::iterator_type iterator_type;
typedef typename T::point_type point_type;
// Get the begin iterator
static inline iterator_type begin_points(const T& t) {
return t.begin();
}
// Get the end iterator
static inline iterator_type end_points(const T& t) {
return t.end();
}
// Get the number of sides of the polygon
static inline std::size_t size(const T& t) {
return t.size();
}
// Get the winding direction of the polygon
static inline winding_direction winding(const T&) {
return unknown_winding;
}
};
template
struct polygon_traits_90 {
typedef typename polygon_90_traits::coordinate_type coordinate_type;
typedef iterator_compact_to_points::compact_iterator_type, point_data > iterator_type;
typedef point_data point_type;
// Get the begin iterator
static inline iterator_type begin_points(const T& t) {
return iterator_type(polygon_90_traits::begin_compact(t),
polygon_90_traits::end_compact(t));
}
// Get the end iterator
static inline iterator_type end_points(const T& t) {
return iterator_type(polygon_90_traits::end_compact(t),
polygon_90_traits::end_compact(t));
}
// Get the number of sides of the polygon
static inline std::size_t size(const T& t) {
return polygon_90_traits::size(t);
}
// Get the winding direction of the polygon
static inline winding_direction winding(const T& t) {
return polygon_90_traits::winding(t);
}
};
#ifndef BOOST_VERY_LITTLE_SFINAE
template
struct polygon_traits {};
template
struct polygon_traits::type, polygon_concept>::type,
typename gtl_same_type::type, polygon_45_concept>::type,
typename gtl_same_type::type, polygon_with_holes_concept>::type,
typename gtl_same_type::type, polygon_45_with_holes_concept>::type
>::type> : public polygon_traits_general {};
template
struct polygon_traits< T,
typename gtl_or<
typename gtl_same_type::type, polygon_90_concept>::type,
typename gtl_same_type::type, polygon_90_with_holes_concept>::type
>::type > : public polygon_traits_90 {};
#else
template
struct gtl_ifelse {};
template
struct gtl_ifelse {
typedef T_ELSE type;
};
template
struct gtl_ifelse {
typedef T_IF type;
};
template
struct polygon_traits {};
template
struct polygon_traits::type, polygon_concept>::type,
typename gtl_same_type::type, polygon_45_concept>::type,
typename gtl_same_type::type, polygon_with_holes_concept>::type,
typename gtl_same_type::type, polygon_45_with_holes_concept>::type
>::type, typename gtl_or<
typename gtl_same_type::type, polygon_90_concept>::type,
typename gtl_same_type::type, polygon_90_with_holes_concept>::type
>::type>::type > : public gtl_ifelse::type, polygon_90_concept>::type,
typename gtl_same_type::type, polygon_90_with_holes_concept>::type >::type,
polygon_traits_90,
polygon_traits_general >::type {
};
#endif
template
struct polygon_with_holes_traits {
typedef typename T::iterator_holes_type iterator_holes_type;
typedef typename T::hole_type hole_type;
// Get the begin iterator
static inline iterator_holes_type begin_holes(const T& t) {
return t.begin_holes();
}
// Get the end iterator
static inline iterator_holes_type end_holes(const T& t) {
return t.end_holes();
}
// Get the number of holes
static inline std::size_t size_holes(const T& t) {
return t.size_holes();
}
};
template
struct polygon_90_mutable_traits {
// Set the data of a polygon with the unique coordinates in an iterator, starting with an x
template
static inline T& set_compact(T& t, iT input_begin, iT input_end) {
t.set_compact(input_begin, input_end);
return t;
}
};
template
struct polygon_mutable_traits {
// Set the data of a polygon with the unique coordinates in an iterator, starting with an x
template
static inline T& set_points(T& t, iT input_begin, iT input_end) {
t.set(input_begin, input_end);
return t;
}
};
template
struct polygon_with_holes_mutable_traits {
// Set the data of a polygon with the unique coordinates in an iterator, starting with an x
template
static inline T& set_holes(T& t, iT inputBegin, iT inputEnd) {
t.set_holes(inputBegin, inputEnd);
return t;
}
};
}
}
#include "isotropy.hpp"
//point
#include "point_data.hpp"
#include "point_traits.hpp"
#include "point_concept.hpp"
//interval
#include "interval_data.hpp"
#include "interval_traits.hpp"
#include "interval_concept.hpp"
//rectangle
#include "rectangle_data.hpp"
#include "rectangle_traits.hpp"
#include "rectangle_concept.hpp"
//algorithms needed by polygon types
#include "detail/iterator_points_to_compact.hpp"
#include "detail/iterator_compact_to_points.hpp"
//polygons
#include "polygon_45_data.hpp"
#include "polygon_data.hpp"
#include "polygon_90_data.hpp"
#include "polygon_90_with_holes_data.hpp"
#include "polygon_45_with_holes_data.hpp"
#include "polygon_with_holes_data.hpp"
namespace boost { namespace polygon{
struct polygon_concept {};
struct polygon_with_holes_concept {};
struct polygon_45_concept {};
struct polygon_45_with_holes_concept {};
struct polygon_90_concept {};
struct polygon_90_with_holes_concept {};
template
struct is_polygon_90_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_polygon_45_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_or::type,
typename gtl_same_type::type>::type type;
};
template
struct is_polygon_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_or::type,
typename gtl_same_type::type>::type type;
};
template
struct is_polygon_90_with_holes_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_or::type,
typename gtl_same_type::type>::type type;
};
template
struct is_polygon_45_with_holes_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_or_3::type,
typename is_polygon_45_type::type,
typename gtl_same_type::type>::type type;
};
template
struct is_polygon_with_holes_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_or_3::type,
typename is_polygon_type::type,
typename gtl_same_type::type>::type type;
};
template
struct is_mutable_polygon_90_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_mutable_polygon_45_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_mutable_polygon_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_mutable_polygon_90_with_holes_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_mutable_polygon_45_with_holes_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_mutable_polygon_with_holes_type {
typedef typename geometry_concept::type GC;
typedef typename gtl_same_type::type type;
};
template
struct is_any_mutable_polygon_with_holes_type {
typedef typename gtl_or_3::type,
typename is_mutable_polygon_45_with_holes_type::type,
typename is_mutable_polygon_with_holes_type::type>::type type;
};
template
struct is_any_mutable_polygon_without_holes_type {
typedef typename gtl_or_3<
typename is_mutable_polygon_90_type::type,
typename is_mutable_polygon_45_type::type,
typename is_mutable_polygon_type::type>::type type; };
template
struct is_any_mutable_polygon_type {
typedef typename gtl_or::type,
typename is_any_mutable_polygon_without_holes_type::type>::type type;
};
template
struct polygon_from_polygon_with_holes_type {};
template <>
struct polygon_from_polygon_with_holes_type { typedef polygon_concept type; };
template <>
struct polygon_from_polygon_with_holes_type { typedef polygon_45_concept type; };
template <>
struct polygon_from_polygon_with_holes_type { typedef polygon_90_concept type; };
template <>
struct geometry_domain { typedef forty_five_domain type; };
template <>
struct geometry_domain { typedef forty_five_domain type; };
template <>
struct geometry_domain { typedef manhattan_domain type; };
template <>
struct geometry_domain { typedef manhattan_domain type; };
template
struct distance_type_by_domain { typedef typename coordinate_traits::coordinate_distance type; };
template
struct distance_type_by_domain {
typedef typename coordinate_traits::coordinate_difference type; };
// \brief Sets the boundary of the polygon to the points in the iterator range
// \tparam T A type that models polygon_concept
// \tparam iT Iterator type over objects that model point_concept
// \param t The polygon to set
// \param begin_points The start of the range of points
// \param end_points The end of the range of points
/// \relatesalso polygon_concept
template
typename enable_if ::type, T>::type &
set_points(T& t, iT begin_points, iT end_points) {
polygon_mutable_traits::set_points(t, begin_points, end_points);
return t;
}
// \brief Sets the boundary of the polygon to the non-redundant coordinates in the iterator range
// \tparam T A type that models polygon_90_concept
// \tparam iT Iterator type over objects that model coordinate_concept
// \param t The polygon to set
// \param begin_compact_coordinates The start of the range of coordinates
// \param end_compact_coordinates The end of the range of coordinates
/// \relatesalso polygon_90_concept
template
typename enable_if ::type,
typename is_mutable_polygon_90_with_holes_type::type>::type, T>::type &
set_compact(T& t, iT begin_compact_coordinates, iT end_compact_coordinates) {
polygon_90_mutable_traits::set_compact(t, begin_compact_coordinates, end_compact_coordinates);
return t;
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if< typename gtl_and <
typename is_any_mutable_polygon_with_holes_type::type,
typename gtl_different_type::type>::type,
manhattan_domain>::type>::type,
T>::type &
set_compact(T& t, iT begin_compact_coordinates, iT end_compact_coordinates) {
iterator_compact_to_points::coordinate_type> >
itrb(begin_compact_coordinates, end_compact_coordinates),
itre(end_compact_coordinates, end_compact_coordinates);
return set_points(t, itrb, itre);
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if ::type, T>::type &
set_holes(T& t, iT begin_holes, iT end_holes) {
polygon_with_holes_mutable_traits::set_holes(t, begin_holes, end_holes);
return t;
}
/// \relatesalso polygon_90_concept
template
typename polygon_90_traits::compact_iterator_type
begin_compact(const T& polygon,
typename enable_if<
typename gtl_and ::type,
typename gtl_same_type::type>::type,
manhattan_domain>::type>::type>::type * = 0
) {
return polygon_90_traits::begin_compact(polygon);
}
/// \relatesalso polygon_90_concept
template
typename polygon_90_traits::compact_iterator_type
end_compact(const T& polygon,
typename enable_if<
typename gtl_and ::type,
typename gtl_same_type::type>::type,
manhattan_domain>::type>::type>::type * = 0
) {
return polygon_90_traits::end_compact(polygon);
}
/// \relatesalso polygon_concept
template
typename enable_if < typename gtl_if<
typename is_polygon_with_holes_type::type>::type,
typename polygon_traits::iterator_type>::type
begin_points(const T& polygon) {
return polygon_traits::begin_points(polygon);
}
/// \relatesalso polygon_concept
template
typename enable_if < typename gtl_if<
typename is_polygon_with_holes_type::type>::type,
typename polygon_traits::iterator_type>::type
end_points(const T& polygon) {
return polygon_traits::end_points(polygon);
}
/// \relatesalso polygon_concept
template
typename enable_if ::type,
std::size_t>::type
size(const T& polygon) {
return polygon_traits::size(polygon);
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if < typename gtl_if<
typename is_polygon_with_holes_type::type>::type,
typename polygon_with_holes_traits::iterator_holes_type>::type
begin_holes(const T& polygon) {
return polygon_with_holes_traits::begin_holes(polygon);
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if < typename gtl_if<
typename is_polygon_with_holes_type::type>::type,
typename polygon_with_holes_traits::iterator_holes_type>::type
end_holes(const T& polygon) {
return polygon_with_holes_traits::end_holes(polygon);
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if ::type,
std::size_t>::type
size_holes(const T& polygon) {
return polygon_with_holes_traits::size_holes(polygon);
}
// \relatesalso polygon_concept
template
typename enable_if<
typename gtl_and< typename is_mutable_polygon_type::type,
typename is_polygon_type::type>::type, T1>::type &
assign(T1& lvalue, const T2& rvalue) {
polygon_mutable_traits::set_points(lvalue, polygon_traits::begin_points(rvalue),
polygon_traits::end_points(rvalue));
return lvalue;
}
// \relatesalso polygon_with_holes_concept
template
typename enable_if<
typename gtl_and< typename is_mutable_polygon_with_holes_type::type,
typename is_polygon_with_holes_type::type>::type, T1>::type &
assign(T1& lvalue, const T2& rvalue) {
polygon_mutable_traits::set_points(lvalue, polygon_traits::begin_points(rvalue),
polygon_traits::end_points(rvalue));
polygon_with_holes_mutable_traits::set_holes(lvalue, polygon_with_holes_traits::begin_holes(rvalue),
polygon_with_holes_traits::end_holes(rvalue));
return lvalue;
}
// \relatesalso polygon_45_concept
template
typename enable_if< typename gtl_and< typename is_mutable_polygon_45_type::type, typename is_polygon_45_type::type>::type, T1>::type &
assign(T1& lvalue, const T2& rvalue) {
polygon_mutable_traits::set_points(lvalue, polygon_traits::begin_points(rvalue),
polygon_traits::end_points(rvalue));
return lvalue;
}
// \relatesalso polygon_45_with_holes_concept
template
typename enable_if<
typename gtl_and< typename is_mutable_polygon_45_with_holes_type::type,
typename is_polygon_45_with_holes_type::type>::type, T1>::type &
assign(T1& lvalue, const T2& rvalue) {
polygon_mutable_traits::set_points(lvalue, polygon_traits::begin_points(rvalue),
polygon_traits::end_points(rvalue));
polygon_with_holes_mutable_traits::set_holes(lvalue, polygon_with_holes_traits::begin_holes(rvalue),
polygon_with_holes_traits::end_holes(rvalue));
return lvalue;
}
// \relatesalso polygon_90_concept
template
typename enable_if<
typename gtl_and< typename is_mutable_polygon_90_type::type,
typename is_polygon_90_type::type>::type, T1>::type &
assign(T1& lvalue, const T2& rvalue) {
polygon_90_mutable_traits::set_compact(lvalue, polygon_90_traits::begin_compact(rvalue),
polygon_90_traits::end_compact(rvalue));
return lvalue;
}
// \relatesalso polygon_90_with_holes_concept
template
typename enable_if<
typename gtl_and< typename is_mutable_polygon_90_with_holes_type::type,
typename is_polygon_90_with_holes_type::type>::type, T1>::type &
assign(T1& lvalue, const T2& rvalue) {
polygon_90_mutable_traits::set_compact(lvalue, polygon_90_traits::begin_compact(rvalue),
polygon_90_traits::end_compact(rvalue));
polygon_with_holes_mutable_traits::set_holes(lvalue, polygon_with_holes_traits::begin_holes(rvalue),
polygon_with_holes_traits::end_holes(rvalue));
return lvalue;
}
// \relatesalso polygon_90_concept
template
typename enable_if<
typename gtl_and< typename is_any_mutable_polygon_type::type,
typename is_rectangle_concept::type>::type>::type, T1>::type &
assign(T1& polygon, const T2& rect) {
typedef point_data::coordinate_type> PT;
PT points[4] = {PT(xl(rect), yl(rect)), PT(xh(rect), yl(rect)), PT(xh(rect), yh(rect)), PT(xl(rect), yh(rect))};
set_points(polygon, points, points+4);
return polygon;
}
/// \relatesalso polygon_90_concept
template
typename enable_if< typename gtl_and< typename is_mutable_polygon_90_type::type,
typename is_point_concept::type>::type>::type,
polygon_type>::type &
convolve(polygon_type& polygon, const point_type& point) {
std::vector::coordinate_type> coords;
coords.reserve(::boost::polygon::size(polygon));
bool pingpong = true;
for(typename polygon_90_traits::compact_iterator_type iter = begin_compact(polygon);
iter != end_compact(polygon); ++iter) {
coords.push_back((*iter) + (pingpong ? x(point) : y(point)));
pingpong = !pingpong;
}
polygon_90_mutable_traits::set_compact(polygon, coords.begin(), coords.end());
return polygon;
}
/// \relatesalso polygon_concept
template
typename enable_if< typename gtl_and< typename gtl_or<
typename is_mutable_polygon_45_type::type,
typename is_mutable_polygon_type::type>::type,
typename is_point_concept::type>::type>::type,
polygon_type>::type &
convolve(polygon_type& polygon, const point_type& point) {
std::vector::iterator_type>::value_type> points;
points.reserve(::boost::polygon::size(polygon));
for(typename polygon_traits::iterator_type iter = begin_points(polygon);
iter != end_points(polygon); ++iter) {
points.push_back(*iter);
convolve(points.back(), point);
}
polygon_mutable_traits::set_points(polygon, points.begin(), points.end());
return polygon;
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if<
typename gtl_and< typename is_any_mutable_polygon_with_holes_type::type,
typename is_point_concept::type>::type>::type,
polygon_type>::type &
convolve(polygon_type& polygon, const point_type& point) {
typedef typename polygon_with_holes_traits::hole_type hole_type;
hole_type h;
set_points(h, begin_points(polygon), end_points(polygon));
convolve(h, point);
std::vector holes;
holes.reserve(size_holes(polygon));
for(typename polygon_with_holes_traits::iterator_holes_type itr = begin_holes(polygon);
itr != end_holes(polygon); ++itr) {
holes.push_back(*itr);
convolve(holes.back(), point);
}
assign(polygon, h);
set_holes(polygon, holes.begin(), holes.end());
return polygon;
}
/// \relatesalso polygon_concept
template
typename enable_if< typename is_any_mutable_polygon_type::type, T>::type &
move(T& polygon, orientation_2d orient, typename polygon_traits::coordinate_type displacement) {
typedef typename polygon_traits::coordinate_type Unit;
if(orient == HORIZONTAL) return convolve(polygon, point_data(displacement, Unit(0)));
return convolve(polygon, point_data(Unit(0), displacement));
}
/// \relatesalso polygon_concept
/// \brief Applies a transformation to the polygon.
/// \tparam polygon_type A type that models polygon_concept
/// \tparam transform_type A type that may be either axis_transformation or transformation or that overloads point_concept::transform
/// \param polygon The polygon to transform
/// \param tr The transformation to apply
template
typename enable_if< typename is_any_mutable_polygon_without_holes_type::type, polygon_type>::type &
transform(polygon_type& polygon, const transform_type& tr) {
std::vector::iterator_type>::value_type> points;
points.reserve(::boost::polygon::size(polygon));
for(typename polygon_traits::iterator_type iter = begin_points(polygon);
iter != end_points(polygon); ++iter) {
points.push_back(*iter);
transform(points.back(), tr);
}
polygon_mutable_traits::set_points(polygon, points.begin(), points.end());
return polygon;
}
/// \relatesalso polygon_with_holes_concept
template
typename enable_if< typename is_any_mutable_polygon_with_holes_type::type, T>::type &
transform(T& polygon, const transform_type& tr) {
typedef typename polygon_with_holes_traits::hole_type hole_type;
hole_type h;
set_points(h, begin_points(polygon), end_points(polygon));
transform(h, tr);
std::vector holes;
holes.reserve(size_holes(polygon));
for(typename polygon_with_holes_traits::iterator_holes_type itr = begin_holes(polygon);
itr != end_holes(polygon); ++itr) {
holes.push_back(*itr);
transform(holes.back(), tr);
}
assign(polygon, h);
set_holes(polygon, holes.begin(), holes.end());
return polygon;
}
template
typename enable_if< typename is_any_mutable_polygon_without_holes_type::type, polygon_type>::type &
scale_up(polygon_type& polygon, typename coordinate_traits::coordinate_type>::unsigned_area_type factor) {
std::vector::iterator_type>::value_type> points;
points.reserve(::boost::polygon::size(polygon));
for(typename polygon_traits::iterator_type iter = begin_points(polygon);
iter != end_points(polygon); ++iter) {
points.push_back(*iter);
scale_up(points.back(), factor);
}
polygon_mutable_traits::set_points(polygon, points.begin(), points.end());
return polygon;
}
template
typename enable_if< typename is_any_mutable_polygon_with_holes_type::type, T>::type &
scale_up(T& polygon, typename coordinate_traits