annotate DEPENDENCIES/generic/include/boost/polygon/isotropy.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 Copyright 2008 Intel Corporation
Chris@16 3
Chris@16 4 Use, modification and distribution are subject to the Boost Software License,
Chris@16 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 http://www.boost.org/LICENSE_1_0.txt).
Chris@16 7 */
Chris@16 8
Chris@16 9 #ifndef BOOST_POLYGON_ISOTROPY_HPP
Chris@16 10 #define BOOST_POLYGON_ISOTROPY_HPP
Chris@16 11
Chris@16 12 //external
Chris@16 13 #include <cmath>
Chris@16 14 #include <cstddef>
Chris@16 15 #include <cstdlib>
Chris@16 16 #include <vector>
Chris@16 17 #include <deque>
Chris@16 18 #include <map>
Chris@16 19 #include <set>
Chris@16 20 #include <list>
Chris@16 21 //#include <iostream>
Chris@16 22 #include <algorithm>
Chris@16 23 #include <limits>
Chris@16 24 #include <iterator>
Chris@16 25 #include <string>
Chris@16 26
Chris@16 27 #ifndef BOOST_POLYGON_NO_DEPS
Chris@16 28
Chris@16 29 #include <boost/config.hpp>
Chris@16 30 #ifdef BOOST_MSVC
Chris@16 31 #define BOOST_POLYGON_MSVC
Chris@16 32 #endif
Chris@16 33 #ifdef BOOST_INTEL
Chris@16 34 #define BOOST_POLYGON_ICC
Chris@16 35 #endif
Chris@16 36 #ifdef BOOST_HAS_LONG_LONG
Chris@16 37 #define BOOST_POLYGON_USE_LONG_LONG
Chris@16 38 typedef boost::long_long_type polygon_long_long_type;
Chris@16 39 typedef boost::ulong_long_type polygon_ulong_long_type;
Chris@16 40 //typedef long long polygon_long_long_type;
Chris@16 41 //typedef unsigned long long polygon_ulong_long_type;
Chris@16 42 #endif
Chris@16 43 #include <boost/mpl/size_t.hpp>
Chris@16 44 #include <boost/mpl/protect.hpp>
Chris@16 45 #include <boost/utility/enable_if.hpp>
Chris@16 46 #include <boost/mpl/bool.hpp>
Chris@16 47 #include <boost/mpl/and.hpp>
Chris@16 48 #include <boost/mpl/or.hpp>
Chris@16 49 #else
Chris@16 50
Chris@16 51 #ifdef _WIN32
Chris@16 52 #define BOOST_POLYGON_MSVC
Chris@16 53 #endif
Chris@16 54 #ifdef __ICC
Chris@16 55 #define BOOST_POLYGON_ICC
Chris@16 56 #endif
Chris@16 57 #define BOOST_POLYGON_USE_LONG_LONG
Chris@16 58 typedef long long polygon_long_long_type;
Chris@16 59 typedef unsigned long long polygon_ulong_long_type;
Chris@16 60
Chris@16 61 namespace boost {
Chris@16 62 template <bool B, class T = void>
Chris@16 63 struct enable_if_c {
Chris@16 64 typedef T type;
Chris@16 65 };
Chris@16 66
Chris@16 67 template <class T>
Chris@16 68 struct enable_if_c<false, T> {};
Chris@16 69
Chris@16 70 template <class Cond, class T = void>
Chris@16 71 struct enable_if : public enable_if_c<Cond::value, T> {};
Chris@16 72
Chris@16 73 template <bool B, class T>
Chris@16 74 struct lazy_enable_if_c {
Chris@16 75 typedef typename T::type type;
Chris@16 76 };
Chris@16 77
Chris@16 78 template <class T>
Chris@16 79 struct lazy_enable_if_c<false, T> {};
Chris@16 80
Chris@16 81 template <class Cond, class T>
Chris@16 82 struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T> {};
Chris@16 83
Chris@16 84
Chris@16 85 template <bool B, class T = void>
Chris@16 86 struct disable_if_c {
Chris@16 87 typedef T type;
Chris@16 88 };
Chris@16 89
Chris@16 90 template <class T>
Chris@16 91 struct disable_if_c<true, T> {};
Chris@16 92
Chris@16 93 template <class Cond, class T = void>
Chris@16 94 struct disable_if : public disable_if_c<Cond::value, T> {};
Chris@16 95
Chris@16 96 template <bool B, class T>
Chris@16 97 struct lazy_disable_if_c {
Chris@16 98 typedef typename T::type type;
Chris@16 99 };
Chris@16 100
Chris@16 101 template <class T>
Chris@16 102 struct lazy_disable_if_c<true, T> {};
Chris@16 103
Chris@16 104 template <class Cond, class T>
Chris@16 105 struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {};
Chris@16 106 }
Chris@16 107
Chris@16 108 #endif
Chris@16 109
Chris@16 110 namespace boost { namespace polygon{
Chris@16 111
Chris@16 112 enum GEOMETRY_CONCEPT_ID {
Chris@16 113 COORDINATE_CONCEPT,
Chris@16 114 INTERVAL_CONCEPT,
Chris@16 115 POINT_CONCEPT,
Chris@16 116 POINT_3D_CONCEPT,
Chris@16 117 RECTANGLE_CONCEPT,
Chris@16 118 POLYGON_90_CONCEPT,
Chris@16 119 POLYGON_90_WITH_HOLES_CONCEPT,
Chris@16 120 POLYGON_45_CONCEPT,
Chris@16 121 POLYGON_45_WITH_HOLES_CONCEPT,
Chris@16 122 POLYGON_CONCEPT,
Chris@16 123 POLYGON_WITH_HOLES_CONCEPT,
Chris@16 124 POLYGON_90_SET_CONCEPT,
Chris@16 125 POLYGON_45_SET_CONCEPT,
Chris@16 126 POLYGON_SET_CONCEPT
Chris@16 127 };
Chris@16 128
Chris@16 129 struct undefined_concept {};
Chris@16 130
Chris@16 131 template <typename T>
Chris@16 132 struct geometry_concept { typedef undefined_concept type; };
Chris@16 133
Chris@16 134 template <typename GCT, typename T>
Chris@16 135 struct view_of {};
Chris@16 136
Chris@16 137 template <typename T1, typename T2>
Chris@16 138 view_of<T1, T2> view_as(const T2& obj) { return view_of<T1, T2>(obj); }
Chris@16 139
Chris@16 140 template <typename T>
Chris@16 141 struct coordinate_traits {};
Chris@16 142
Chris@16 143 //used to override long double with an infinite precision datatype
Chris@16 144 template <typename T>
Chris@16 145 struct high_precision_type {
Chris@16 146 typedef long double type;
Chris@16 147 };
Chris@16 148
Chris@16 149 template <typename T>
Chris@16 150 T convert_high_precision_type(const typename high_precision_type<T>::type& v) {
Chris@16 151 return T(v);
Chris@16 152 }
Chris@16 153
Chris@16 154 //used to override std::sort with an alternative (parallel) algorithm
Chris@16 155 template <typename iter_type>
Chris@16 156 void polygon_sort(iter_type _b_, iter_type _e_);
Chris@16 157
Chris@16 158 template <typename iter_type, typename pred_type>
Chris@16 159 void polygon_sort(iter_type _b_, iter_type _e_, const pred_type& _pred_);
Chris@16 160
Chris@16 161
Chris@16 162 template <>
Chris@16 163 struct coordinate_traits<int> {
Chris@16 164 typedef int coordinate_type;
Chris@16 165 typedef long double area_type;
Chris@16 166 #ifdef BOOST_POLYGON_USE_LONG_LONG
Chris@16 167 typedef polygon_long_long_type manhattan_area_type;
Chris@16 168 typedef polygon_ulong_long_type unsigned_area_type;
Chris@16 169 typedef polygon_long_long_type coordinate_difference;
Chris@16 170 #else
Chris@16 171 typedef long manhattan_area_type;
Chris@16 172 typedef unsigned long unsigned_area_type;
Chris@16 173 typedef long coordinate_difference;
Chris@16 174 #endif
Chris@16 175 typedef long double coordinate_distance;
Chris@16 176 };
Chris@16 177
Chris@16 178 #ifdef BOOST_POLYGON_USE_LONG_LONG
Chris@16 179 template <>
Chris@16 180 struct coordinate_traits<polygon_long_long_type> {
Chris@16 181 typedef polygon_long_long_type coordinate_type;
Chris@16 182 typedef long double area_type;
Chris@16 183 typedef polygon_long_long_type manhattan_area_type;
Chris@16 184 typedef polygon_ulong_long_type unsigned_area_type;
Chris@16 185 typedef polygon_long_long_type coordinate_difference;
Chris@16 186 typedef long double coordinate_distance;
Chris@16 187 };
Chris@16 188 #endif
Chris@16 189
Chris@16 190 template <>
Chris@16 191 struct coordinate_traits<float> {
Chris@16 192 typedef float coordinate_type;
Chris@16 193 typedef float area_type;
Chris@16 194 typedef float manhattan_area_type;
Chris@16 195 typedef float unsigned_area_type;
Chris@16 196 typedef float coordinate_difference;
Chris@16 197 typedef float coordinate_distance;
Chris@16 198 };
Chris@16 199
Chris@16 200 template <>
Chris@16 201 struct coordinate_traits<double> {
Chris@16 202 typedef double coordinate_type;
Chris@16 203 typedef double area_type;
Chris@16 204 typedef double manhattan_area_type;
Chris@16 205 typedef double unsigned_area_type;
Chris@16 206 typedef double coordinate_difference;
Chris@16 207 typedef double coordinate_distance;
Chris@16 208 };
Chris@16 209
Chris@16 210 template <>
Chris@16 211 struct coordinate_traits<long double> {
Chris@16 212 typedef long double coordinate_type;
Chris@16 213 typedef long double area_type;
Chris@16 214 typedef long double manhattan_area_type;
Chris@16 215 typedef long double unsigned_area_type;
Chris@16 216 typedef long double coordinate_difference;
Chris@16 217 typedef long double coordinate_distance;
Chris@16 218 };
Chris@16 219
Chris@16 220 template <typename T>
Chris@16 221 struct scaling_policy {
Chris@16 222 template <typename T2>
Chris@16 223 static inline T round(T2 t2) {
Chris@16 224 return (T)std::floor(t2+0.5);
Chris@16 225 }
Chris@16 226
Chris@16 227 static inline T round(T t2) {
Chris@16 228 return t2;
Chris@16 229 }
Chris@16 230 };
Chris@16 231
Chris@16 232 struct coordinate_concept {};
Chris@16 233
Chris@16 234 template <>
Chris@16 235 struct geometry_concept<int> { typedef coordinate_concept type; };
Chris@16 236 #ifdef BOOST_POLYGON_USE_LONG_LONG
Chris@16 237 template <>
Chris@16 238 struct geometry_concept<polygon_long_long_type> { typedef coordinate_concept type; };
Chris@16 239 #endif
Chris@16 240 template <>
Chris@16 241 struct geometry_concept<float> { typedef coordinate_concept type; };
Chris@16 242 template <>
Chris@16 243 struct geometry_concept<double> { typedef coordinate_concept type; };
Chris@16 244 template <>
Chris@16 245 struct geometry_concept<long double> { typedef coordinate_concept type; };
Chris@16 246
Chris@16 247 #ifndef BOOST_POLYGON_NO_DEPS
Chris@16 248 struct gtl_no : mpl::bool_<false> {};
Chris@16 249 struct gtl_yes : mpl::bool_<true> {};
Chris@16 250 template <typename T, typename T2>
Chris@16 251 struct gtl_and : mpl::and_<T, T2> {};
Chris@16 252 template <typename T, typename T2, typename T3>
Chris@16 253 struct gtl_and_3 : mpl::and_<T, T2, T3> {};
Chris@16 254 template <typename T, typename T2, typename T3, typename T4>
Chris@16 255 struct gtl_and_4 : mpl::and_<T, T2, T3, T4> {};
Chris@16 256 // template <typename T, typename T2>
Chris@16 257 // struct gtl_or : mpl::or_<T, T2> {};
Chris@16 258 // template <typename T, typename T2, typename T3>
Chris@16 259 // struct gtl_or_3 : mpl::or_<T, T2, T3> {};
Chris@16 260 // template <typename T, typename T2, typename T3, typename T4>
Chris@16 261 // struct gtl_or_4 : mpl::or_<T, T2, T3, T4> {};
Chris@16 262 #else
Chris@16 263 struct gtl_no { static const bool value = false; };
Chris@16 264 struct gtl_yes { typedef gtl_yes type;
Chris@16 265 static const bool value = true; };
Chris@16 266
Chris@16 267 template <bool T, bool T2>
Chris@16 268 struct gtl_and_c { typedef gtl_no type; };
Chris@16 269 template <>
Chris@16 270 struct gtl_and_c<true, true> { typedef gtl_yes type; };
Chris@16 271
Chris@16 272 template <typename T, typename T2>
Chris@16 273 struct gtl_and : gtl_and_c<T::value, T2::value> {};
Chris@16 274 template <typename T, typename T2, typename T3>
Chris@16 275 struct gtl_and_3 { typedef typename gtl_and<
Chris@16 276 T, typename gtl_and<T2, T3>::type>::type type; };
Chris@16 277
Chris@16 278 template <typename T, typename T2, typename T3, typename T4>
Chris@16 279 struct gtl_and_4 { typedef typename gtl_and_3<
Chris@16 280 T, T2, typename gtl_and<T3, T4>::type>::type type; };
Chris@16 281 #endif
Chris@16 282 template <typename T, typename T2>
Chris@16 283 struct gtl_or { typedef gtl_yes type; };
Chris@16 284 template <typename T>
Chris@16 285 struct gtl_or<T, T> { typedef T type; };
Chris@16 286
Chris@16 287 template <typename T, typename T2, typename T3>
Chris@16 288 struct gtl_or_3 { typedef typename gtl_or<
Chris@16 289 T, typename gtl_or<T2, T3>::type>::type type; };
Chris@16 290
Chris@16 291 template <typename T, typename T2, typename T3, typename T4>
Chris@16 292 struct gtl_or_4 { typedef typename gtl_or<
Chris@16 293 T, typename gtl_or_3<T2, T3, T4>::type>::type type; };
Chris@16 294
Chris@16 295 template <typename T>
Chris@16 296 struct gtl_not { typedef gtl_no type; };
Chris@16 297 template <>
Chris@16 298 struct gtl_not<gtl_no> { typedef gtl_yes type; };
Chris@16 299
Chris@16 300 template <typename T>
Chris@16 301 struct gtl_if {
Chris@16 302 #ifdef BOOST_POLYGON_MSVC
Chris@16 303 typedef gtl_no type;
Chris@16 304 #endif
Chris@16 305 };
Chris@16 306 template <>
Chris@16 307 struct gtl_if<gtl_yes> { typedef gtl_yes type; };
Chris@16 308
Chris@16 309 template <typename T, typename T2>
Chris@16 310 struct gtl_same_type { typedef gtl_no type; };
Chris@16 311 template <typename T>
Chris@16 312 struct gtl_same_type<T, T> { typedef gtl_yes type; };
Chris@16 313 template <typename T, typename T2>
Chris@16 314 struct gtl_different_type { typedef typename gtl_not<typename gtl_same_type<T, T2>::type>::type type; };
Chris@16 315
Chris@16 316 struct manhattan_domain {};
Chris@16 317 struct forty_five_domain {};
Chris@16 318 struct general_domain {};
Chris@16 319
Chris@16 320 template <typename T>
Chris@16 321 struct geometry_domain { typedef general_domain type; };
Chris@16 322
Chris@16 323 template <typename domain_type, typename coordinate_type>
Chris@16 324 struct area_type_by_domain { typedef typename coordinate_traits<coordinate_type>::area_type type; };
Chris@16 325 template <typename coordinate_type>
Chris@16 326 struct area_type_by_domain<manhattan_domain, coordinate_type> {
Chris@16 327 typedef typename coordinate_traits<coordinate_type>::manhattan_area_type type; };
Chris@16 328
Chris@16 329 struct y_c_edist : gtl_yes {};
Chris@16 330
Chris@16 331 template <typename coordinate_type_1, typename coordinate_type_2>
Chris@16 332 typename enable_if<
Chris@16 333 typename gtl_and_3<y_c_edist, typename gtl_same_type<typename geometry_concept<coordinate_type_1>::type, coordinate_concept>::type,
Chris@16 334 typename gtl_same_type<typename geometry_concept<coordinate_type_1>::type, coordinate_concept>::type>::type,
Chris@16 335 typename coordinate_traits<coordinate_type_1>::coordinate_difference>::type
Chris@16 336 euclidean_distance(const coordinate_type_1& lvalue, const coordinate_type_2& rvalue) {
Chris@16 337 typedef typename coordinate_traits<coordinate_type_1>::coordinate_difference Unit;
Chris@16 338 return (lvalue < rvalue) ? (Unit)rvalue - (Unit)lvalue : (Unit)lvalue - (Unit)rvalue;
Chris@16 339 }
Chris@16 340
Chris@16 341
Chris@16 342
Chris@16 343 // predicated_swap swaps a and b if pred is true
Chris@16 344
Chris@16 345 // predicated_swap is guarenteed to behave the same as
Chris@16 346 // if(pred){
Chris@16 347 // T tmp = a;
Chris@16 348 // a = b;
Chris@16 349 // b = tmp;
Chris@16 350 // }
Chris@16 351 // but will not generate a branch instruction.
Chris@16 352 // predicated_swap always creates a temp copy of a, but does not
Chris@16 353 // create more than one temp copy of an input.
Chris@16 354 // predicated_swap can be used to optimize away branch instructions in C++
Chris@16 355 template <class T>
Chris@16 356 inline bool predicated_swap(const bool& pred,
Chris@16 357 T& a,
Chris@16 358 T& b) {
Chris@16 359 const T tmp = a;
Chris@16 360 const T* input[2] = {&b, &tmp};
Chris@16 361 a = *input[!pred];
Chris@16 362 b = *input[pred];
Chris@16 363 return pred;
Chris@16 364 }
Chris@16 365
Chris@16 366 enum direction_1d_enum { LOW = 0, HIGH = 1,
Chris@16 367 LEFT = 0, RIGHT = 1,
Chris@16 368 CLOCKWISE = 0, COUNTERCLOCKWISE = 1,
Chris@16 369 REVERSE = 0, FORWARD = 1,
Chris@16 370 NEGATIVE = 0, POSITIVE = 1 };
Chris@16 371 enum orientation_2d_enum { HORIZONTAL = 0, VERTICAL = 1 };
Chris@16 372 enum direction_2d_enum { WEST = 0, EAST = 1, SOUTH = 2, NORTH = 3 };
Chris@16 373 enum orientation_3d_enum { PROXIMAL = 2 };
Chris@16 374 enum direction_3d_enum { DOWN = 4, UP = 5 };
Chris@16 375 enum winding_direction {
Chris@16 376 clockwise_winding = 0,
Chris@16 377 counterclockwise_winding = 1,
Chris@16 378 unknown_winding = 2
Chris@16 379 };
Chris@16 380
Chris@16 381 class direction_2d;
Chris@16 382 class direction_3d;
Chris@16 383 class orientation_2d;
Chris@16 384
Chris@16 385 class direction_1d {
Chris@16 386 private:
Chris@16 387 unsigned int val_;
Chris@16 388 explicit direction_1d(int d);
Chris@16 389 public:
Chris@16 390 inline direction_1d() : val_(LOW) {}
Chris@16 391 inline direction_1d(const direction_1d& that) : val_(that.val_) {}
Chris@16 392 inline direction_1d(const direction_1d_enum val) : val_(val) {}
Chris@16 393 explicit inline direction_1d(const direction_2d& that);
Chris@16 394 explicit inline direction_1d(const direction_3d& that);
Chris@16 395 inline direction_1d& operator = (const direction_1d& d) {
Chris@16 396 val_ = d.val_; return * this; }
Chris@16 397 inline bool operator==(direction_1d d) const { return (val_ == d.val_); }
Chris@16 398 inline bool operator!=(direction_1d d) const { return !((*this) == d); }
Chris@16 399 inline unsigned int to_int(void) const { return val_; }
Chris@16 400 inline direction_1d& backward() { val_ ^= 1; return *this; }
Chris@16 401 inline int get_sign() const { return val_ * 2 - 1; }
Chris@16 402 };
Chris@16 403
Chris@16 404 class direction_2d;
Chris@16 405
Chris@16 406 class orientation_2d {
Chris@16 407 private:
Chris@16 408 unsigned int val_;
Chris@16 409 explicit inline orientation_2d(int o);
Chris@16 410 public:
Chris@16 411 inline orientation_2d() : val_(HORIZONTAL) {}
Chris@16 412 inline orientation_2d(const orientation_2d& ori) : val_(ori.val_) {}
Chris@16 413 inline orientation_2d(const orientation_2d_enum val) : val_(val) {}
Chris@16 414 explicit inline orientation_2d(const direction_2d& that);
Chris@16 415 inline orientation_2d& operator=(const orientation_2d& ori) {
Chris@16 416 val_ = ori.val_; return * this; }
Chris@16 417 inline bool operator==(orientation_2d that) const { return (val_ == that.val_); }
Chris@16 418 inline bool operator!=(orientation_2d that) const { return (val_ != that.val_); }
Chris@16 419 inline unsigned int to_int() const { return (val_); }
Chris@16 420 inline void turn_90() { val_ = val_^ 1; }
Chris@16 421 inline orientation_2d get_perpendicular() const {
Chris@16 422 orientation_2d retval = *this;
Chris@16 423 retval.turn_90();
Chris@16 424 return retval;
Chris@16 425 }
Chris@16 426 inline direction_2d get_direction(direction_1d dir) const;
Chris@16 427 };
Chris@16 428
Chris@16 429 class direction_2d {
Chris@16 430 private:
Chris@16 431 int val_;
Chris@16 432
Chris@16 433 public:
Chris@16 434
Chris@16 435 inline direction_2d() : val_(WEST) {}
Chris@16 436
Chris@16 437 inline direction_2d(const direction_2d& that) : val_(that.val_) {}
Chris@16 438
Chris@16 439 inline direction_2d(const direction_2d_enum val) : val_(val) {}
Chris@16 440
Chris@16 441 inline direction_2d& operator=(const direction_2d& d) {
Chris@16 442 val_ = d.val_;
Chris@16 443 return * this;
Chris@16 444 }
Chris@16 445
Chris@16 446 inline ~direction_2d() { }
Chris@16 447
Chris@16 448 inline bool operator==(direction_2d d) const { return (val_ == d.val_); }
Chris@16 449 inline bool operator!=(direction_2d d) const { return !((*this) == d); }
Chris@16 450 inline bool operator< (direction_2d d) const { return (val_ < d.val_); }
Chris@16 451 inline bool operator<=(direction_2d d) const { return (val_ <= d.val_); }
Chris@16 452 inline bool operator> (direction_2d d) const { return (val_ > d.val_); }
Chris@16 453 inline bool operator>=(direction_2d d) const { return (val_ >= d.val_); }
Chris@16 454
Chris@16 455 // Casting to int
Chris@16 456 inline unsigned int to_int(void) const { return val_; }
Chris@16 457
Chris@16 458 inline direction_2d backward() const {
Chris@16 459 // flip the LSB, toggles 0 - 1 and 2 - 3
Chris@16 460 return direction_2d(direction_2d_enum(val_ ^ 1));
Chris@16 461 }
Chris@16 462
Chris@16 463 // Returns a direction 90 degree left (LOW) or right(HIGH) to this one
Chris@16 464 inline direction_2d turn(direction_1d t) const {
Chris@16 465 return direction_2d(direction_2d_enum(val_ ^ 3 ^ (val_ >> 1) ^ t.to_int()));
Chris@16 466 }
Chris@16 467
Chris@16 468 // Returns a direction 90 degree left to this one
Chris@16 469 inline direction_2d left() const {return turn(HIGH);}
Chris@16 470
Chris@16 471 // Returns a direction 90 degree right to this one
Chris@16 472 inline direction_2d right() const {return turn(LOW);}
Chris@16 473
Chris@16 474 // N, E are positive, S, W are negative
Chris@16 475 inline bool is_positive() const {return (val_ & 1);}
Chris@16 476 inline bool is_negative() const {return !is_positive();}
Chris@16 477 inline int get_sign() const {return ((is_positive()) << 1) -1;}
Chris@16 478
Chris@16 479 };
Chris@16 480
Chris@16 481 direction_1d::direction_1d(const direction_2d& that) : val_(that.to_int() & 1) {}
Chris@16 482
Chris@16 483 orientation_2d::orientation_2d(const direction_2d& that) : val_(that.to_int() >> 1) {}
Chris@16 484
Chris@16 485 direction_2d orientation_2d::get_direction(direction_1d dir) const {
Chris@16 486 return direction_2d(direction_2d_enum((val_ << 1) + dir.to_int()));
Chris@16 487 }
Chris@16 488
Chris@16 489 class orientation_3d {
Chris@16 490 private:
Chris@16 491 unsigned int val_;
Chris@16 492 explicit inline orientation_3d(int o);
Chris@16 493 public:
Chris@16 494 inline orientation_3d() : val_((int)HORIZONTAL) {}
Chris@16 495 inline orientation_3d(const orientation_3d& ori) : val_(ori.val_) {}
Chris@16 496 inline orientation_3d(orientation_2d ori) : val_(ori.to_int()) {}
Chris@16 497 inline orientation_3d(const orientation_3d_enum val) : val_(val) {}
Chris@16 498 explicit inline orientation_3d(const direction_2d& that);
Chris@16 499 explicit inline orientation_3d(const direction_3d& that);
Chris@16 500 inline ~orientation_3d() { }
Chris@16 501 inline orientation_3d& operator=(const orientation_3d& ori) {
Chris@16 502 val_ = ori.val_; return * this; }
Chris@16 503 inline bool operator==(orientation_3d that) const { return (val_ == that.val_); }
Chris@16 504 inline bool operator!=(orientation_3d that) const { return (val_ != that.val_); }
Chris@16 505 inline unsigned int to_int() const { return (val_); }
Chris@16 506 inline direction_3d get_direction(direction_1d dir) const;
Chris@16 507 };
Chris@16 508
Chris@16 509 class direction_3d {
Chris@16 510 private:
Chris@16 511 int val_;
Chris@16 512
Chris@16 513 public:
Chris@16 514
Chris@16 515 inline direction_3d() : val_(WEST) {}
Chris@16 516
Chris@16 517 inline direction_3d(direction_2d that) : val_(that.to_int()) {}
Chris@16 518 inline direction_3d(const direction_3d& that) : val_(that.val_) {}
Chris@16 519
Chris@16 520 inline direction_3d(const direction_2d_enum val) : val_(val) {}
Chris@16 521 inline direction_3d(const direction_3d_enum val) : val_(val) {}
Chris@16 522
Chris@16 523 inline direction_3d& operator=(direction_3d d) {
Chris@16 524 val_ = d.val_;
Chris@16 525 return * this;
Chris@16 526 }
Chris@16 527
Chris@16 528 inline ~direction_3d() { }
Chris@16 529
Chris@16 530 inline bool operator==(direction_3d d) const { return (val_ == d.val_); }
Chris@16 531 inline bool operator!=(direction_3d d) const { return !((*this) == d); }
Chris@16 532 inline bool operator< (direction_3d d) const { return (val_ < d.val_); }
Chris@16 533 inline bool operator<=(direction_3d d) const { return (val_ <= d.val_); }
Chris@16 534 inline bool operator> (direction_3d d) const { return (val_ > d.val_); }
Chris@16 535 inline bool operator>=(direction_3d d) const { return (val_ >= d.val_); }
Chris@16 536
Chris@16 537 // Casting to int
Chris@16 538 inline unsigned int to_int(void) const { return val_; }
Chris@16 539
Chris@16 540 inline direction_3d backward() const {
Chris@16 541 // flip the LSB, toggles 0 - 1 and 2 - 3 and 4 - 5
Chris@16 542 return direction_2d(direction_2d_enum(val_ ^ 1));
Chris@16 543 }
Chris@16 544
Chris@16 545 // N, E, U are positive, S, W, D are negative
Chris@16 546 inline bool is_positive() const {return (val_ & 1);}
Chris@16 547 inline bool is_negative() const {return !is_positive();}
Chris@16 548 inline int get_sign() const {return ((is_positive()) << 1) -1;}
Chris@16 549
Chris@16 550 };
Chris@16 551
Chris@16 552 direction_1d::direction_1d(const direction_3d& that) : val_(that.to_int() & 1) {}
Chris@16 553 orientation_3d::orientation_3d(const direction_3d& that) : val_(that.to_int() >> 1) {}
Chris@16 554 orientation_3d::orientation_3d(const direction_2d& that) : val_(that.to_int() >> 1) {}
Chris@16 555
Chris@16 556 direction_3d orientation_3d::get_direction(direction_1d dir) const {
Chris@16 557 return direction_3d(direction_3d_enum((val_ << 1) + dir.to_int()));
Chris@16 558 }
Chris@16 559
Chris@16 560 }
Chris@16 561 }
Chris@16 562 #endif