1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
// Copyright (c) 1997 Utrecht University (The Netherlands),
// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
// and Tel-Aviv University (Israel). All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; version 2.1 of the License.
// See the file LICENSE.LGPL 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.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.2-branch/Polygon/include/CGAL/Polygon_2_algorithms.h $
// $Id: Polygon_2_algorithms.h 28567 2006-02-16 14:30:13Z lsaboret $
//
//
// Author(s) : Wieger Wesselink <wieger@cs.ruu.nl>
#ifndef CGAL_POLYGON_2_ALGORITHMS_H
#define CGAL_POLYGON_2_ALGORITHMS_H
#include <CGAL/basic.h>
#include <CGAL/enum.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/polygon_assertions.h>
CGAL_BEGIN_NAMESPACE
//-----------------------------------------------------------------------//
// algorithms for sequences of 2D points
//-----------------------------------------------------------------------//
template <class ForwardIterator, class Traits>
ForwardIterator left_vertex_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
template <class ForwardIterator, class Traits>
ForwardIterator right_vertex_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
template <class ForwardIterator, class Traits>
ForwardIterator top_vertex_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
template <class ForwardIterator, class Traits>
ForwardIterator bottom_vertex_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
template <class InputIterator, class Traits>
Bbox_2 bbox_2(InputIterator first,
InputIterator last,
const Traits& traits);
template <class ForwardIterator, class Traits>
void
area_2( ForwardIterator first, ForwardIterator last,
typename Traits::FT &result,
const Traits& traits)
{
typedef typename Traits::FT FT;
result = FT(0);
// check if the polygon is empty
if (first == last) return;
ForwardIterator second = first; ++second;
// check if the polygon has only one point
if (second == last) return;
typename Traits::Compute_area_2 compute_area_2 =
traits.compute_area_2_object();
ForwardIterator third = second;
while (++third != last) {
result = result + compute_area_2(*first, *second, *third);
second = third;
}
}
template <class ForwardIterator, class Traits>
typename Traits::FT
polygon_area_2( ForwardIterator first, ForwardIterator last,
const Traits& traits)
{
typedef typename Traits::FT FT;
FT result = FT(0);
// check if the polygon is empty
if (first == last) return result;
ForwardIterator second = first; ++second;
// check if the polygon has only one point
if (second == last) return result;
typename Traits::Compute_area_2 compute_area_2 =
traits.compute_area_2_object();
ForwardIterator third = second;
while (++third != last) {
result = result + compute_area_2(*first, *second, *third);
second = third;
}
return result;
}
template <class ForwardIterator, class Traits>
bool is_convex_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
template <class ForwardIterator, class Traits>
bool is_simple_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
// In the following two functions we would like to use Traits::Point_2 instead
// of Point, but this is not allowed by g++ 2.7.2.
template <class ForwardIterator, class Point, class Traits>
Oriented_side oriented_side_2(ForwardIterator first,
ForwardIterator last,
const Point& point,
const Traits& traits);
template <class ForwardIterator, class Point, class Traits>
Bounded_side bounded_side_2(ForwardIterator first,
ForwardIterator last,
const Point& point,
const Traits& traits);
template <class ForwardIterator, class Traits>
Orientation orientation_2(ForwardIterator first,
ForwardIterator last,
const Traits& traits);
//-----------------------------------------------------------------------//
// implementation
//-----------------------------------------------------------------------//
#ifdef CGAL_REP_CLASS_DEFINED
template <class ForwardIterator>
inline
ForwardIterator left_vertex_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return left_vertex_2(first, last, K());
}
template <class ForwardIterator>
inline
ForwardIterator right_vertex_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return right_vertex_2(first, last, K());
}
template <class ForwardIterator>
inline
ForwardIterator top_vertex_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return top_vertex_2(first, last, K());
}
template <class ForwardIterator>
inline
ForwardIterator bottom_vertex_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return bottom_vertex_2(first, last, K());
}
template <class InputIterator>
inline
Bbox_2 bbox_2(InputIterator first,
InputIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<InputIterator>::value_type>::Kernel K;
return bbox_2(first, last, K());
}
template <class ForwardIterator, class Numbertype>
inline
void area_2(ForwardIterator first,
ForwardIterator last,
Numbertype& result)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
area_2(first, last, result, K());
}
template <class ForwardIterator>
inline
bool is_convex_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return is_convex_2(first, last, K());
}
template <class ForwardIterator>
inline
bool is_simple_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return is_simple_2(first, last, K());
}
template <class ForwardIterator>
inline
Oriented_side oriented_side_2(
ForwardIterator first,
ForwardIterator last,
const typename std::iterator_traits<ForwardIterator>::value_type& point)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return oriented_side_2(first, last, point, K());
}
template <class ForwardIterator>
inline
Bounded_side bounded_side_2(
ForwardIterator first,
ForwardIterator last,
const typename std::iterator_traits<ForwardIterator>::value_type& point)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return bounded_side_2(first, last, point, K());
}
template <class ForwardIterator>
inline
Orientation orientation_2(ForwardIterator first,
ForwardIterator last)
{
typedef typename Kernel_traits<
typename std::iterator_traits<ForwardIterator>::value_type>::Kernel K;
return orientation_2(first, last, K());
}
#endif // CGAL_REP_CLASS_DEFINED
CGAL_END_NAMESPACE
#ifdef CGAL_CFG_NO_AUTOMATIC_TEMPLATE_INCLUSION
#include <CGAL/Polygon_2_algorithms.C>
#endif // CGAL_CFG_NO_AUTOMATIC_TEMPLATE_INCLUSION
#endif // CGAL_POLYGON_2_ALGORITHMS_H
|