annotate DEPENDENCIES/generic/include/boost/polygon/point_concept.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Boost.Polygon library point_concept.hpp header file
Chris@16 2
Chris@16 3 // Copyright (c) Intel Corporation 2008.
Chris@16 4 // Copyright (c) 2008-2012 Simonson Lucanus.
Chris@16 5 // Copyright (c) 2012-2012 Andrii Sydorchuk.
Chris@16 6
Chris@16 7 // See http://www.boost.org for updates, documentation, and revision history.
Chris@16 8 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 10 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 11
Chris@16 12 #ifndef BOOST_POLYGON_POINT_CONCEPT_HPP
Chris@16 13 #define BOOST_POLYGON_POINT_CONCEPT_HPP
Chris@16 14
Chris@16 15 #include "isotropy.hpp"
Chris@16 16 #include "point_traits.hpp"
Chris@16 17
Chris@16 18 namespace boost {
Chris@16 19 namespace polygon {
Chris@16 20
Chris@16 21 struct point_concept {};
Chris@16 22
Chris@16 23 template <typename ConceptType>
Chris@16 24 struct is_point_concept {
Chris@16 25 typedef gtl_no type;
Chris@16 26 };
Chris@16 27
Chris@16 28 template <>
Chris@16 29 struct is_point_concept<point_concept> {
Chris@16 30 typedef gtl_yes type;
Chris@16 31 };
Chris@16 32
Chris@16 33 template <typename ConceptType>
Chris@16 34 struct is_mutable_point_concept {
Chris@16 35 typedef gtl_no type;
Chris@16 36 };
Chris@16 37
Chris@16 38 template <>
Chris@16 39 struct is_mutable_point_concept<point_concept> {
Chris@16 40 typedef gtl_yes type;
Chris@16 41 };
Chris@16 42
Chris@16 43 template <typename GeometryType, typename BoolType>
Chris@16 44 struct point_coordinate_type_by_concept {
Chris@16 45 typedef void type;
Chris@16 46 };
Chris@16 47
Chris@16 48 template <typename GeometryType>
Chris@16 49 struct point_coordinate_type_by_concept<GeometryType, gtl_yes> {
Chris@16 50 typedef typename point_traits<GeometryType>::coordinate_type type;
Chris@16 51 };
Chris@16 52
Chris@16 53 template <typename GeometryType>
Chris@16 54 struct point_coordinate_type {
Chris@16 55 typedef typename point_coordinate_type_by_concept<
Chris@16 56 GeometryType,
Chris@16 57 typename is_point_concept<
Chris@16 58 typename geometry_concept<GeometryType>::type
Chris@16 59 >::type
Chris@16 60 >::type type;
Chris@16 61 };
Chris@16 62
Chris@16 63 template <typename GeometryType, typename BoolType>
Chris@16 64 struct point_difference_type_by_concept {
Chris@16 65 typedef void type;
Chris@16 66 };
Chris@16 67
Chris@16 68 template <typename GeometryType>
Chris@16 69 struct point_difference_type_by_concept<GeometryType, gtl_yes> {
Chris@16 70 typedef typename coordinate_traits<
Chris@16 71 typename point_traits<GeometryType>::coordinate_type
Chris@16 72 >::coordinate_difference type;
Chris@16 73 };
Chris@16 74
Chris@16 75 template <typename GeometryType>
Chris@16 76 struct point_difference_type {
Chris@16 77 typedef typename point_difference_type_by_concept<
Chris@16 78 GeometryType,
Chris@16 79 typename is_point_concept<
Chris@16 80 typename geometry_concept<GeometryType>::type
Chris@16 81 >::type
Chris@16 82 >::type type;
Chris@16 83 };
Chris@16 84
Chris@16 85 template <typename GeometryType, typename BoolType>
Chris@16 86 struct point_distance_type_by_concept {
Chris@16 87 typedef void type;
Chris@16 88 };
Chris@16 89
Chris@16 90 template <typename GeometryType>
Chris@16 91 struct point_distance_type_by_concept<GeometryType, gtl_yes> {
Chris@16 92 typedef typename coordinate_traits<
Chris@16 93 typename point_coordinate_type<GeometryType>::type
Chris@16 94 >::coordinate_distance type;
Chris@16 95 };
Chris@16 96
Chris@16 97 template <typename GeometryType>
Chris@16 98 struct point_distance_type {
Chris@16 99 typedef typename point_distance_type_by_concept<
Chris@16 100 GeometryType,
Chris@16 101 typename is_point_concept<
Chris@16 102 typename geometry_concept<GeometryType>::type
Chris@16 103 >::type
Chris@16 104 >::type type;
Chris@16 105 };
Chris@16 106
Chris@16 107 struct y_pt_get : gtl_yes {};
Chris@16 108
Chris@16 109 template <typename PointType>
Chris@16 110 typename enable_if<
Chris@16 111 typename gtl_and<
Chris@16 112 y_pt_get,
Chris@16 113 typename is_point_concept<
Chris@16 114 typename geometry_concept<PointType>::type
Chris@16 115 >::type
Chris@16 116 >::type,
Chris@16 117 typename point_coordinate_type<PointType>::type
Chris@16 118 >::type get(const PointType& point, orientation_2d orient) {
Chris@16 119 return point_traits<PointType>::get(point, orient);
Chris@16 120 }
Chris@16 121
Chris@16 122 struct y_pt_set : gtl_yes {};
Chris@16 123
Chris@16 124 template <typename PointType>
Chris@16 125 typename enable_if<
Chris@16 126 typename gtl_and<
Chris@16 127 y_pt_set,
Chris@16 128 typename is_mutable_point_concept<
Chris@16 129 typename geometry_concept<PointType>::type
Chris@16 130 >::type
Chris@16 131 >::type,
Chris@16 132 void
Chris@16 133 >::type set(PointType& point, orientation_2d orient,
Chris@16 134 typename point_mutable_traits<PointType>::coordinate_type value) {
Chris@16 135 point_mutable_traits<PointType>::set(point, orient, value);
Chris@16 136 }
Chris@16 137
Chris@16 138 struct y_pt_construct : gtl_yes {};
Chris@16 139
Chris@16 140 template <typename PointType>
Chris@16 141 typename enable_if<
Chris@16 142 typename gtl_and<
Chris@16 143 y_pt_construct,
Chris@16 144 typename is_mutable_point_concept<
Chris@16 145 typename geometry_concept<PointType>::type
Chris@16 146 >::type
Chris@16 147 >::type,
Chris@16 148 PointType>::type construct(
Chris@16 149 typename point_mutable_traits<PointType>::coordinate_type x,
Chris@16 150 typename point_mutable_traits<PointType>::coordinate_type y) {
Chris@16 151 return point_mutable_traits<PointType>::construct(x, y);
Chris@16 152 }
Chris@16 153
Chris@16 154 struct y_pt_assign : gtl_yes {};
Chris@16 155
Chris@16 156 template <typename PointType1, typename PointType2>
Chris@16 157 typename enable_if<
Chris@16 158 typename gtl_and_3<
Chris@16 159 y_pt_assign,
Chris@16 160 typename is_mutable_point_concept<
Chris@16 161 typename geometry_concept<PointType1>::type
Chris@16 162 >::type,
Chris@16 163 typename is_point_concept<
Chris@16 164 typename geometry_concept<PointType2>::type
Chris@16 165 >::type
Chris@16 166 >::type,
Chris@16 167 PointType1>::type& assign(PointType1& lvalue, const PointType2& rvalue) {
Chris@16 168 set(lvalue, HORIZONTAL, get(rvalue, HORIZONTAL));
Chris@16 169 set(lvalue, VERTICAL, get(rvalue, VERTICAL));
Chris@16 170 return lvalue;
Chris@16 171 }
Chris@16 172
Chris@16 173 struct y_p_x : gtl_yes {};
Chris@16 174
Chris@16 175 template <typename PointType>
Chris@16 176 typename enable_if<
Chris@16 177 typename gtl_and<
Chris@16 178 y_p_x,
Chris@16 179 typename is_point_concept<
Chris@16 180 typename geometry_concept<PointType>::type
Chris@16 181 >::type
Chris@16 182 >::type,
Chris@16 183 typename point_coordinate_type<PointType>::type
Chris@16 184 >::type x(const PointType& point) {
Chris@16 185 return get(point, HORIZONTAL);
Chris@16 186 }
Chris@16 187
Chris@16 188 struct y_p_y : gtl_yes {};
Chris@16 189
Chris@16 190 template <typename PointType>
Chris@16 191 typename enable_if<
Chris@16 192 typename gtl_and<
Chris@16 193 y_p_y,
Chris@16 194 typename is_point_concept<
Chris@16 195 typename geometry_concept<PointType>::type
Chris@16 196 >::type
Chris@16 197 >::type,
Chris@16 198 typename point_coordinate_type<PointType>::type
Chris@16 199 >::type y(const PointType& point) {
Chris@16 200 return get(point, VERTICAL);
Chris@16 201 }
Chris@16 202
Chris@16 203 struct y_p_sx : gtl_yes {};
Chris@16 204
Chris@16 205 template <typename PointType>
Chris@16 206 typename enable_if<
Chris@16 207 typename gtl_and<
Chris@16 208 y_p_sx,
Chris@16 209 typename is_mutable_point_concept<
Chris@16 210 typename geometry_concept<PointType>::type
Chris@16 211 >::type
Chris@16 212 >::type,
Chris@16 213 void>::type x(PointType& point,
Chris@16 214 typename point_mutable_traits<PointType>::coordinate_type value) {
Chris@16 215 set(point, HORIZONTAL, value);
Chris@16 216 }
Chris@16 217
Chris@16 218 struct y_p_sy : gtl_yes {};
Chris@16 219
Chris@16 220 template <typename PointType>
Chris@16 221 typename enable_if<
Chris@16 222 typename gtl_and<
Chris@16 223 y_p_sy,
Chris@16 224 typename is_mutable_point_concept<
Chris@16 225 typename geometry_concept<PointType>::type
Chris@16 226 >::type
Chris@16 227 >::type,
Chris@16 228 void>::type y(PointType& point,
Chris@16 229 typename point_mutable_traits<PointType>::coordinate_type value) {
Chris@16 230 set(point, VERTICAL, value);
Chris@16 231 }
Chris@16 232
Chris@16 233 struct y_pt_equiv : gtl_yes {};
Chris@16 234
Chris@16 235 template <typename PointType1, typename PointType2>
Chris@16 236 typename enable_if<
Chris@16 237 typename gtl_and_3<
Chris@16 238 y_pt_equiv,
Chris@16 239 typename is_point_concept<
Chris@16 240 typename geometry_concept<PointType1>::type
Chris@16 241 >::type,
Chris@16 242 typename is_point_concept<
Chris@16 243 typename geometry_concept<PointType2>::type
Chris@16 244 >::type
Chris@16 245 >::type,
Chris@16 246 bool>::type equivalence(
Chris@16 247 const PointType1& point1, const PointType2& point2) {
Chris@16 248 return (x(point1) == x(point2)) && (y(point1) == y(point2));
Chris@16 249 }
Chris@16 250
Chris@16 251 struct y_pt_man_dist : gtl_yes {};
Chris@16 252
Chris@16 253 template <typename PointType1, typename PointType2>
Chris@16 254 typename enable_if<
Chris@16 255 typename gtl_and_3<
Chris@16 256 y_pt_man_dist,
Chris@16 257 typename is_point_concept<
Chris@16 258 typename geometry_concept<PointType1>::type
Chris@16 259 >::type,
Chris@16 260 typename is_point_concept<
Chris@16 261 typename geometry_concept<PointType2>::type
Chris@16 262 >::type
Chris@16 263 >::type,
Chris@16 264 typename point_difference_type<PointType1>::type>::type
Chris@16 265 manhattan_distance(const PointType1& point1, const PointType2& point2) {
Chris@16 266 return euclidean_distance(point1, point2, HORIZONTAL) +
Chris@16 267 euclidean_distance(point1, point2, VERTICAL);
Chris@16 268 }
Chris@16 269
Chris@16 270 struct y_pt_ed1 : gtl_yes {};
Chris@16 271
Chris@16 272 template <typename PointType1, typename PointType2>
Chris@16 273 typename enable_if<
Chris@16 274 typename gtl_and_3<
Chris@16 275 y_pt_ed1,
Chris@16 276 typename is_point_concept<
Chris@16 277 typename geometry_concept<PointType1>::type
Chris@16 278 >::type,
Chris@16 279 typename is_point_concept<
Chris@16 280 typename geometry_concept<PointType2>::type
Chris@16 281 >::type
Chris@16 282 >::type,
Chris@16 283 typename point_difference_type<PointType1>::type>::type
Chris@16 284 euclidean_distance(
Chris@16 285 const PointType1& point1,
Chris@16 286 const PointType2& point2,
Chris@16 287 orientation_2d orient) {
Chris@16 288 typename point_difference_type<PointType1>::type dif =
Chris@16 289 get(point1, orient) - get(point2, orient);
Chris@16 290 return (dif < 0) ? -dif : dif;
Chris@16 291 }
Chris@16 292
Chris@16 293 struct y_pt_eds : gtl_yes {};
Chris@16 294
Chris@16 295 template <typename PointType1, typename PointType2>
Chris@16 296 typename enable_if<
Chris@16 297 typename gtl_and_3<
Chris@16 298 y_pt_eds,
Chris@16 299 typename is_point_concept<
Chris@16 300 typename geometry_concept<PointType1>::type
Chris@16 301 >::type,
Chris@16 302 typename is_point_concept<
Chris@16 303 typename geometry_concept<PointType2>::type
Chris@16 304 >::type
Chris@16 305 >::type,
Chris@16 306 typename point_difference_type<PointType1>::type>::type
Chris@16 307 distance_squared(const PointType1& point1, const PointType2& point2) {
Chris@16 308 typename point_difference_type<PointType1>::type dx =
Chris@16 309 euclidean_distance(point1, point2, HORIZONTAL);
Chris@16 310 typename point_difference_type<PointType1>::type dy =
Chris@16 311 euclidean_distance(point1, point2, VERTICAL);
Chris@16 312 dx *= dx;
Chris@16 313 dy *= dy;
Chris@16 314 return dx + dy;
Chris@16 315 }
Chris@16 316
Chris@16 317 struct y_pt_ed2 : gtl_yes {};
Chris@16 318
Chris@16 319 template <typename PointType1, typename PointType2>
Chris@16 320 typename enable_if<
Chris@16 321 typename gtl_and_3<
Chris@16 322 y_pt_ed2,
Chris@16 323 typename is_point_concept<
Chris@16 324 typename geometry_concept<PointType1>::type
Chris@16 325 >::type,
Chris@16 326 typename is_point_concept<
Chris@16 327 typename geometry_concept<PointType2>::type
Chris@16 328 >::type
Chris@16 329 >::type,
Chris@16 330 typename point_distance_type<PointType1>::type>::type
Chris@16 331 euclidean_distance(const PointType1& point1, const PointType2& point2) {
Chris@16 332 return (std::sqrt)(
Chris@16 333 static_cast<double>(distance_squared(point1, point2)));
Chris@16 334 }
Chris@16 335
Chris@16 336 struct y_pt_convolve : gtl_yes {};
Chris@16 337
Chris@16 338 template <typename PointType1, typename PointType2>
Chris@16 339 typename enable_if<
Chris@16 340 typename gtl_and_3<
Chris@16 341 y_pt_convolve,
Chris@16 342 typename is_mutable_point_concept<
Chris@16 343 typename geometry_concept<PointType1>::type
Chris@16 344 >::type,
Chris@16 345 typename is_point_concept<
Chris@16 346 typename geometry_concept<PointType2>::type
Chris@16 347 >::type
Chris@16 348 >::type,
Chris@16 349 PointType1>::type& convolve(PointType1& lvalue, const PointType2& rvalue) {
Chris@16 350 x(lvalue, x(lvalue) + x(rvalue));
Chris@16 351 y(lvalue, y(lvalue) + y(rvalue));
Chris@16 352 return lvalue;
Chris@16 353 }
Chris@16 354
Chris@16 355 struct y_pt_deconvolve : gtl_yes {};
Chris@16 356
Chris@16 357 template <typename PointType1, typename PointType2>
Chris@16 358 typename enable_if<
Chris@16 359 typename gtl_and_3<
Chris@16 360 y_pt_deconvolve,
Chris@16 361 typename is_mutable_point_concept<
Chris@16 362 typename geometry_concept<PointType1>::type
Chris@16 363 >::type,
Chris@16 364 typename is_point_concept<
Chris@16 365 typename geometry_concept<PointType2>::type
Chris@16 366 >::type
Chris@16 367 >::type,
Chris@16 368 PointType1>::type& deconvolve(PointType1& lvalue, const PointType2& rvalue) {
Chris@16 369 x(lvalue, x(lvalue) - x(rvalue));
Chris@16 370 y(lvalue, y(lvalue) - y(rvalue));
Chris@16 371 return lvalue;
Chris@16 372 }
Chris@16 373
Chris@16 374 struct y_pt_scale_up : gtl_yes {};
Chris@16 375
Chris@16 376 template <typename PointType, typename CType>
Chris@16 377 typename enable_if<
Chris@16 378 typename gtl_and<
Chris@16 379 y_pt_scale_up,
Chris@16 380 typename is_mutable_point_concept<
Chris@16 381 typename geometry_concept<PointType>::type
Chris@16 382 >::type
Chris@16 383 >::type,
Chris@16 384 PointType>::type& scale_up(PointType& point, CType factor) {
Chris@16 385 typedef typename point_coordinate_type<PointType>::type Unit;
Chris@16 386 x(point, x(point) * (Unit)factor);
Chris@16 387 y(point, y(point) * (Unit)factor);
Chris@16 388 return point;
Chris@16 389 }
Chris@16 390
Chris@16 391 struct y_pt_scale_down : gtl_yes {};
Chris@16 392
Chris@16 393 template <typename PointType, typename CType>
Chris@16 394 typename enable_if<
Chris@16 395 typename gtl_and<
Chris@16 396 y_pt_scale_down,
Chris@16 397 typename is_mutable_point_concept<
Chris@16 398 typename geometry_concept<PointType>::type
Chris@16 399 >::type
Chris@16 400 >::type,
Chris@16 401 PointType>::type& scale_down(PointType& point, CType factor) {
Chris@16 402 typedef typename point_coordinate_type<PointType>::type Unit;
Chris@16 403 typedef typename coordinate_traits<Unit>::coordinate_distance dt;
Chris@16 404 x(point, scaling_policy<Unit>::round((dt)(x(point)) / (dt)factor));
Chris@16 405 y(point, scaling_policy<Unit>::round((dt)(y(point)) / (dt)factor));
Chris@16 406 return point;
Chris@16 407 }
Chris@16 408
Chris@16 409 struct y_pt_scale : gtl_yes {};
Chris@16 410
Chris@16 411 template <typename PointType, typename ScaleType>
Chris@16 412 typename enable_if<
Chris@16 413 typename gtl_and<
Chris@16 414 y_pt_scale,
Chris@16 415 typename is_mutable_point_concept<
Chris@16 416 typename geometry_concept<PointType>::type
Chris@16 417 >::type
Chris@16 418 >::type,
Chris@16 419 PointType>::type& scale(PointType& point, const ScaleType& scaling) {
Chris@16 420 typedef typename point_coordinate_type<PointType>::type Unit;
Chris@16 421 Unit x_coord(x(point));
Chris@16 422 Unit y_coord(y(point));
Chris@16 423 scaling.scale(x_coord, y_coord);
Chris@16 424 x(point, x_coord);
Chris@16 425 y(point, y_coord);
Chris@16 426 return point;
Chris@16 427 }
Chris@16 428
Chris@16 429 struct y_pt_transform : gtl_yes {};
Chris@16 430
Chris@16 431 template <typename PointType, typename TransformType>
Chris@16 432 typename enable_if<
Chris@16 433 typename gtl_and<
Chris@16 434 y_pt_transform,
Chris@16 435 typename is_mutable_point_concept<
Chris@16 436 typename geometry_concept<PointType>::type
Chris@16 437 >::type
Chris@16 438 >::type,
Chris@16 439 PointType>::type& transform(PointType& point, const TransformType& transform) {
Chris@16 440 typedef typename point_coordinate_type<PointType>::type Unit;
Chris@16 441 Unit x_coord(x(point));
Chris@16 442 Unit y_coord(y(point));
Chris@16 443 transform.transform(x_coord, y_coord);
Chris@16 444 x(point, x_coord);
Chris@16 445 y(point, y_coord);
Chris@16 446 return point;
Chris@16 447 }
Chris@16 448
Chris@16 449 struct y_pt_move : gtl_yes {};
Chris@16 450
Chris@16 451 template <typename PointType>
Chris@16 452 typename enable_if<
Chris@16 453 typename gtl_and<
Chris@16 454 y_pt_move,
Chris@16 455 typename is_mutable_point_concept<
Chris@16 456 typename geometry_concept<PointType>::type
Chris@16 457 >::type
Chris@16 458 >::type,
Chris@16 459 PointType>::type& move(PointType& point, orientation_2d orient,
Chris@16 460 typename point_coordinate_type<PointType>::type displacement) {
Chris@16 461 typedef typename point_coordinate_type<PointType>::type Unit;
Chris@16 462 Unit coord = get(point, orient);
Chris@16 463 set(point, orient, coord + displacement);
Chris@16 464 return point;
Chris@16 465 }
Chris@16 466 } // polygon
Chris@16 467 } // boost
Chris@16 468
Chris@16 469 #endif // BOOST_POLYGON_POINT_CONCEPT_HPP