Boost logo

Boost-Commit :

From: lucanus.j.simonson_at_[hidden]
Date: 2008-05-08 03:00:49


Author: ljsimons
Date: 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
New Revision: 45208
URL: http://svn.boost.org/trac/boost/changeset/45208

Log:
initial checkin
Added:
   sandbox/gtl/
   sandbox/gtl/boost/
   sandbox/gtl/gtl/
   sandbox/gtl/gtl/geometry_traits.h (contents, props changed)
   sandbox/gtl/gtl/gtl.h (contents, props changed)
   sandbox/gtl/gtl/interval_concept.h (contents, props changed)
   sandbox/gtl/gtl/interval_data.h (contents, props changed)
   sandbox/gtl/gtl/interval_traits.h (contents, props changed)
   sandbox/gtl/gtl/isotropy.h (contents, props changed)
   sandbox/gtl/gtl/point_3d_concept.h (contents, props changed)
   sandbox/gtl/gtl/point_3d_data.h (contents, props changed)
   sandbox/gtl/gtl/point_3d_traits.h (contents, props changed)
   sandbox/gtl/gtl/point_concept.h (contents, props changed)
   sandbox/gtl/gtl/point_data.h (contents, props changed)
   sandbox/gtl/gtl/point_traits.h (contents, props changed)
   sandbox/gtl/gtl/polygon_concept.h (contents, props changed)
   sandbox/gtl/gtl/polygon_data.h (contents, props changed)
   sandbox/gtl/gtl/polygon_traits.h (contents, props changed)
   sandbox/gtl/gtl/post_concept_definitions.h (contents, props changed)
   sandbox/gtl/gtl/post_geometry_traits_definitions.h (contents, props changed)
   sandbox/gtl/gtl/rectangle_concept.h (contents, props changed)
   sandbox/gtl/gtl/rectangle_data.h (contents, props changed)
   sandbox/gtl/gtl/rectangle_traits.h (contents, props changed)

Added: sandbox/gtl/gtl/geometry_traits.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/geometry_traits.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,52 @@
+struct no_type {};
+
+template <typename T>
+struct geometry_traits {
+ typedef no_type geometry_concept;
+};
+template <>
+struct geometry_traits<point_data<int> > {
+ typedef point_concept geometry_concept;
+ typedef int point_get_retval;
+};
+template <>
+struct geometry_traits<point_data<long long> > {
+ typedef point_concept geometry_concept;
+ typedef long long point_get_retval;
+};
+template <>
+struct geometry_traits<rectangle_data<int> > {
+ typedef rectangle_concept geometry_concept;
+ typedef interval_data<int> rectangle_get_retval;
+};
+template <>
+struct geometry_traits<rectangle_data<long long> > {
+ typedef rectangle_concept geometry_concept;
+ typedef interval_data<long long> rectangle_get_retval;
+};
+template <>
+struct geometry_traits<interval_data<int> > {
+ typedef interval_concept geometry_concept;
+};
+template <>
+struct geometry_traits<interval_data<long long> > {
+ typedef interval_concept geometry_concept;
+};
+template <>
+struct geometry_traits<polygon_data<int> > {
+ typedef polygon_concept geometry_concept;
+};
+template <>
+struct geometry_traits<polygon_data<long long> > {
+ typedef polygon_concept geometry_concept;
+};
+template <>
+struct geometry_traits<point_3d_data<int> > {
+ typedef point_3d_concept geometry_concept;
+};
+template <>
+struct geometry_traits<point_3d_data<long long> > {
+ typedef point_3d_concept geometry_concept;
+};
+
+

Added: sandbox/gtl/gtl/gtl.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/gtl.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,70 @@
+//external
+#include <vector>
+#include <iostream>
+
+//isotropy types
+#include "isotropy.h"
+
+//data types
+#include "point_data.h"
+#include "interval_data.h"
+#include "rectangle_data.h"
+#include "point_3d_data.h"
+#include "polygon_data.h"
+
+//traits types
+#include "point_traits.h"
+#include "interval_traits.h"
+#include "rectangle_traits.h"
+#include "point_3d_traits.h"
+#include "polygon_traits.h"
+
+//concept types
+#include "point_concept.h"
+#include "interval_concept.h"
+#include "rectangle_concept.h"
+#include "point_3d_concept.h"
+#include "polygon_concept.h"
+
+//definitions
+#include "post_concept_definitions.h"
+
+//geometry traits
+#include "geometry_traits.h"
+
+//defintions
+#include "post_geometry_traits_definitions.h"
+
+template <typename geometry_type_1, typename geometry_type_2>
+bool contains(const geometry_type_1& geometry_object, const geometry_type_2& contained_geometry_object) {
+ typename geometry_traits<geometry_type_1>::geometry_concept().contains(geometry_object, contained_geometry_object);
+}
+
+template <typename geometry_type_1, typename geometry_type_2>
+bool equivilence(const geometry_type_1& lvalue, const geometry_type_2& rvalue) {
+ typename geometry_traits<geometry_type_1>::geometry_concept concept_instantiation;
+ return concept_instantiation.equivilence(lvalue, rvalue);
+}
+
+template <typename geometry_type>
+typename component_type<geometry_type>::type
+get(const geometry_type& geometry_object, orientation_2d orient) {
+ return geometry_traits<geometry_type>::geometry_concept::get(geometry_object, orient);
+}
+
+template <typename geometry_type>
+typename component_type<geometry_type>::type
+get(const geometry_type& geometry_object, orientation_3d orient) {
+ return geometry_traits<geometry_type>::geometry_concept::get(geometry_object, orient);
+}
+
+template <typename geometry_type_1, typename geometry_type_2>
+geometry_type_1& assign(geometry_type_1& lvalue, geometry_type_2& rvalue) {
+ return geometry_traits<geometry_type_1>::geometry_concept::assign(lvalue, rvalue);
+}
+
+template <typename geometry_type_1, typename geometry_type_2>
+geometry_type_1& operator|(geometry_type_1& lvalue, const geometry_type_2& rvalue) {
+ return assign(lvalue, rvalue);
+}
+

Added: sandbox/gtl/gtl/interval_concept.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/interval_concept.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,68 @@
+struct interval_concept {
+ interval_concept() {}
+
+ template <direction_1d_enum dir, typename T>
+ static inline typename interval_traits<T>::coordinate_type
+ get(const T& interval) {
+ return interval_traits<T>::get(interval, dir);
+ }
+
+ template <typename T>
+ static inline typename interval_traits<T>::coordinate_type
+ get(const T& interval, direction_1d dir) {
+ return interval_traits<T>::get(interval, dir);
+ }
+
+ template <direction_1d_enum dir, typename T, typename coordinate_type>
+ static inline void set(T& interval, coordinate_type value) {
+ set(interval, dir, value);
+ }
+
+ template <typename T, typename coordinate_type>
+ static inline void set(T& interval, direction_1d dir, coordinate_type value) {
+ interval_traits<T>::set(interval, dir, value);
+ if(get<HIGH>(interval) < get<LOW>(interval))
+ interval_traits<T>::set(interval, dir.backward(), value);
+ }
+
+ template <typename T, typename coordinate_type1, typename coordinate_type2>
+ static inline T construct(coordinate_type1 low_value, coordinate_type2 high_value) {
+ if(low_value > high_value) std::swap(low_value, high_value);
+ return interval_traits<T>::construct(low_value, high_value);
+ }
+
+ template <typename T, typename T2>
+ static T copy_construct(const T2& interval) {
+ return construct<T>
+ (get(interval, LOW ),
+ get(interval, HIGH));
+ }
+
+ template <typename interval_type_1, typename interval_type_2>
+ static interval_type_1& assign(interval_type_1& lvalue, const interval_type_2& rvalue) {
+ set(lvalue, LOW, get(rvalue, LOW));
+ set(lvalue, HIGH, get(rvalue, HIGH));
+ return lvalue;
+ }
+
+ template <typename T, typename T2>
+ static bool equivilence(const T& interval1, const T2& interval2) {
+ return get(interval1, LOW) ==
+ get(interval2, LOW) &&
+ get(interval1, HIGH) ==
+ get(interval2, HIGH);
+ }
+
+ template <typename interval_type, typename coordinate_type>
+ static bool contains_coordinate(const interval_type& interval,
+ coordinate_type value, bool consider_touch) {
+ if(consider_touch) {
+ return value <= get<HIGH>(interval) && value >= get<LOW>(interval);
+ } else {
+ return value < get<HIGH>(interval) && value > get<LOW>(interval);
+ }
+ }
+
+};
+
+

Added: sandbox/gtl/gtl/interval_data.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/interval_data.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,26 @@
+template <typename T>
+class interval_data {
+public:
+ typedef T coordinate_type;
+ inline interval_data(){}
+ inline interval_data(coordinate_type low, coordinate_type high) {
+ coords_[LOW] = low; coords_[HIGH] = high;
+ }
+ inline interval_data(const interval_data& that) {
+ (*this) = that;
+ }
+ inline interval_data& operator=(const interval_data& that) {
+ coords_[0] = that.coords_[0]; coords_[1] = that.coords_[1]; return *this;
+ }
+ template <typename T2>
+ inline interval_data& operator=(const T2& rvalue);
+ inline coordinate_type get(direction_1d dir) const {
+ return coords_[dir.to_int()];
+ }
+ inline void set(direction_1d dir, coordinate_type value) {
+ coords_[dir.to_int()] = value;
+ }
+private:
+ coordinate_type coords_[2];
+};
+

Added: sandbox/gtl/gtl/interval_traits.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/interval_traits.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,17 @@
+template <typename T>
+struct interval_traits {
+ typedef typename T::coordinate_type coordinate_type;
+
+ static inline coordinate_type get(const T& interval, direction_1d dir) {
+ return interval.get(dir);
+ }
+
+ static inline void set(T& interval, direction_1d dir, coordinate_type value) {
+ interval.set(dir, value);
+ }
+
+ static inline T construct(coordinate_type low_value, coordinate_type high_value) {
+ return T(low_value, high_value);
+ }
+};
+

Added: sandbox/gtl/gtl/isotropy.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/isotropy.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,59 @@
+enum orientation_2d_enum { HORIZONTAL = 0, VERTICAL = 1 };
+enum direction_1d_enum { LOW = 0, HIGH = 1 };
+enum orientation_3d_enum { PROXIMAL = 2 };
+enum winding_direction {
+ counterclockwise_winding = 0,
+ clockwise_winding = 1,
+ unknown_winding = 2
+};
+
+
+class orientation_2d {
+private:
+ unsigned int val_;
+ explicit orientation_2d(int o);
+public:
+ orientation_2d() : val_(HORIZONTAL) {}
+ orientation_2d(const orientation_2d& ori) : val_(ori.val_) {}
+ orientation_2d(const orientation_2d_enum val) : val_(val) {}
+ const orientation_2d& operator=(const orientation_2d& ori) {
+ val_ = ori.val_; return * this; }
+ bool operator==(orientation_2d that) const { return (val_ == that.val_); }
+ bool operator!=(orientation_2d that) const { return (val_ != that.val_); }
+ unsigned int to_int() const { return (val_); }
+ void turn_90() { val_ = val_^ 1; }
+};
+
+class direction_1d {
+private:
+ unsigned int val_;
+ explicit direction_1d(int d);
+public:
+ direction_1d() { val_ = LOW; }
+ direction_1d(const direction_1d& that) : val_(that.val_) {}
+ direction_1d(const direction_1d_enum val) : val_(val) {}
+ const direction_1d& operator = (const direction_1d& d) {
+ val_ = d.val_; return * this; }
+ bool operator==(direction_1d d) const { return (val_ == d.val_); }
+ bool operator!=(direction_1d d) const { return !((*this) == d); }
+ unsigned int to_int(void) const { return val_; }
+ direction_1d& backward() { val_ ^ 1; }
+};
+
+class orientation_3d {
+private:
+ unsigned int val_;
+ explicit orientation_3d(int o);
+public:
+ orientation_3d() : val_((int)HORIZONTAL) {}
+ orientation_3d(const orientation_3d& ori) : val_(ori.val_) {}
+ orientation_3d(const orientation_2d& ori) { val_ = ori.to_int(); }
+ orientation_3d(const orientation_3d_enum val) : val_(val) {}
+ ~orientation_3d() { }
+ const orientation_3d& operator=(const orientation_3d& ori) {
+ val_ = ori.val_; return * this; }
+ bool operator==(orientation_3d that) const { return (val_ == that.val_); }
+ bool operator!=(orientation_3d that) const { return (val_ != that.val_); }
+ unsigned int to_int() const { return (val_); }
+};
+

Added: sandbox/gtl/gtl/point_3d_concept.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/point_3d_concept.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,48 @@
+struct point_3d_concept {
+ point_3d_concept() {}
+
+ template <typename point_3d_type>
+ struct registration {
+ typedef typename point_3d_traits<point_3d_type>::coordinate_type component_type;
+ };
+
+ template <orientation_2d_enum orient, typename T>
+ static inline typename point_traits<T>::coordinate_type get(const T& point) {
+ return point_traits<T>::get(point, orient); }
+
+ template <orientation_3d_enum orient, typename T>
+ static inline typename point_3d_traits<T>::coordinate_type get(const T& point) {
+ return point_3d_traits<T>::get(point, orient); }
+
+ template <typename T>
+ static inline typename point_3d_traits<T>::coordinate_type get(const T& point, orientation_3d orient) {
+ return point_3d_traits<T>::get(point, orient); }
+
+ template <orientation_2d_enum orient, typename T, typename coordinate_type>
+ static inline void set(T& point, coordinate_type value) {
+ point_traits<T>::set(point, orient, value); }
+ template <orientation_3d_enum orient, typename T, typename coordinate_type>
+ static inline void set(T& point, coordinate_type value) {
+ point_traits<T>::set(point, orient, value); }
+ template <typename T, typename coordinate_type>
+ static inline void set(T& point, orientation_3d orient, coordinate_type value) {
+ point_traits<T>::set(point, orient, value); }
+
+ template <typename T, typename coordinate_type1, typename coordinate_type2, typename coordinate_type3>
+ static inline T construct(coordinate_type1 x_value,
+ coordinate_type2 y_value,
+ coordinate_type3 z_value) {
+ return point_3d_traits<T>::construct(x_value, y_value, z_value); }
+
+ template <typename point_3d_type_1, typename point_3d_type_2>
+ static point_3d_type_1& assign(point_3d_type_1& lvalue, const point_3d_type_2& rvalue) {
+ set(lvalue, HORIZONTAL, get(rvalue, HORIZONTAL));
+ set(lvalue, VERTICAL, get(rvalue, VERTICAL));
+ set(lvalue, PROXIMAL, get(rvalue, PROXIMAL));
+ return lvalue;
+ }
+
+
+};
+
+

Added: sandbox/gtl/gtl/point_3d_data.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/point_3d_data.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,23 @@
+template <typename T>
+class point_3d_data {
+public:
+ typedef T coordinate_type;
+ inline point_3d_data(){}
+ inline point_3d_data(coordinate_type x, coordinate_type y) {
+ coords_[HORIZONTAL] = x; coords_[VERTICAL] = y; coords_[PROXIMAL] = 0; }
+ inline point_3d_data(coordinate_type x, coordinate_type y, coordinate_type z) {
+ coords_[HORIZONTAL] = x; coords_[VERTICAL] = y; coords_[PROXIMAL] = z; }
+ inline point_3d_data(const point_3d_data& that) { (*this) = that; }
+ inline point_3d_data& operator=(const point_3d_data& that) {
+ coords_[0] = that.coords_[0]; coords_[1] = that.coords_[1];
+ coords_[2] = that.coords_[2]; return *this; }
+ template <typename T2>
+ inline point_3d_data& operator=(const T2& rvalue);
+ inline coordinate_type get(orientation_3d orient) const {
+ return coords_[orient.to_int()]; }
+ inline void set(orientation_3d orient, coordinate_type value) {
+ coords_[orient.to_int()] = value; }
+private:
+ coordinate_type coords_[3];
+};
+

Added: sandbox/gtl/gtl/point_3d_traits.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/point_3d_traits.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,16 @@
+template <typename T>
+struct point_3d_traits {
+ typedef typename T::coordinate_type coordinate_type;
+
+ static inline coordinate_type get(const T& point, orientation_3d orient) {
+ return point.get(orient); }
+
+ static inline void set(T& point, orientation_3d orient, coordinate_type value) {
+ point.set(orient, value); }
+
+ static inline T construct(coordinate_type x_value,
+ coordinate_type y_value,
+ coordinate_type z_value) {
+ return T(x_value, y_value, z_value); }
+};
+

Added: sandbox/gtl/gtl/point_concept.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/point_concept.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,86 @@
+struct point_concept {
+ point_concept() {}
+
+ template <typename point_type>
+ struct registration {
+ typedef typename point_traits<point_type>::coordinate_type component_type;
+ };
+
+ template <typename T>
+ static inline typename point_traits<T>::coordinate_type get(const T& point, orientation_2d orient) {
+ return point_traits<T>::get(point, orient);
+ }
+
+ template <orientation_2d_enum orient, typename T>
+ static inline typename point_traits<T>::coordinate_type get(const T& point) {
+ return get(point, orient);
+ }
+
+ template <typename T, typename coordinate_type>
+ static inline void set(T& point, orientation_2d orient, coordinate_type value) {
+ point_traits<T>::set(point, orient, value);
+ }
+
+ template <orientation_2d_enum orient, typename T, typename coordinate_type>
+ static inline void set(T& point, coordinate_type value) {
+ set(point, orient, value);
+ }
+
+ template <typename point_type>
+ static void x(point_type& point) {
+ return get<HORIZONTAL>(point);
+ }
+
+ template <typename point_type>
+ static void y(point_type& point) {
+ return get<VERTICAL>(point);
+ }
+
+ template <typename point_type, typename coordinate_type>
+ static void x(point_type& point, coordinate_type value) {
+ set<HORIZONTAL>(point, value);
+ }
+
+ template <typename point_type, typename coordinate_type>
+ static void y(point_type& point, coordinate_type value) {
+ set<VERTICAL>(point, value);
+ }
+
+ template <typename T, typename coordinate_type1, typename coordinate_type2>
+ static inline T construct(coordinate_type1 x_value, coordinate_type2 y_value) {
+ return point_traits<T>::construct(x_value, y_value);
+ }
+
+ template <typename point_type_1, typename point_type_2>
+ static point_type_1& assign(point_type_1& lvalue, const point_type_2& rvalue) {
+ set(lvalue, HORIZONTAL, get(rvalue, HORIZONTAL));
+ set(lvalue, VERTICAL, get(rvalue, VERTICAL));
+ return lvalue;
+ }
+
+ template <typename T, typename T2>
+ static inline bool equivilence(const T& point1, const T2& point2) {
+ typename point_traits<T>::coordinate_type x1 = get<HORIZONTAL>(point1);
+ typename point_traits<T2>::coordinate_type x2 = get(point2, HORIZONTAL);
+ typename point_traits<T>::coordinate_type y1 = get(point1, VERTICAL);
+ typename point_traits<T2>::coordinate_type y2 = get<VERTICAL>(point2);
+ return x1 == x2 && y1 == y2;
+ }
+
+ template <typename point_type_1, typename point_type_2>
+ static typename point_traits<point_type_1>::coordinate_type
+ manhattan_distance(const point_type_1& point1, const point_type_2& point2) {
+ return distance(point1, point2, HORIZONTAL) + distance(point1, point2, VERTICAL);
+ }
+
+ template <typename point_type_1, typename point_type_2>
+ static typename point_traits<point_type_1>::coordinate_type
+ distance(const point_type_1& point1, const point_type_2& point2, orientation_2d orient) {
+ typename point_traits<point_type_1>::coordinate_type return_value =
+ get(point1, orient) - get(point2, orient);
+ return return_value < 0 ? -return_value : return_value;
+ }
+
+};
+
+

Added: sandbox/gtl/gtl/point_data.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/point_data.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,24 @@
+template <typename T>
+class point_data {
+public:
+ typedef T coordinate_type;
+ inline point_data(){}
+ inline point_data(coordinate_type x, coordinate_type y) {
+ coords_[HORIZONTAL] = x; coords_[VERTICAL] = y;
+ }
+ inline point_data(const point_data& that) { (*this) = that; }
+ inline point_data& operator=(const point_data& that) {
+ coords_[0] = that.coords_[0]; coords_[1] = that.coords_[1]; return *this;
+ }
+ template <typename T2>
+ inline point_data& operator=(const T2& rvalue);
+ inline coordinate_type get(orientation_2d orient) const {
+ return coords_[orient.to_int()];
+ }
+ inline void set(orientation_2d orient, coordinate_type value) {
+ coords_[orient.to_int()] = value;
+ }
+private:
+ coordinate_type coords_[2];
+};
+

Added: sandbox/gtl/gtl/point_traits.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/point_traits.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,15 @@
+template <typename T>
+struct point_traits {
+ typedef typename T::coordinate_type coordinate_type;
+
+ static inline coordinate_type get(const T& point, orientation_2d orient) {
+ return point.get(orient);
+ }
+ static inline void set(T& point, orientation_2d orient, coordinate_type value) {
+ point.set(orient, value);
+ }
+ static inline T construct(coordinate_type x_value, coordinate_type y_value) {
+ return T(x_value, y_value);
+ }
+};
+

Added: sandbox/gtl/gtl/polygon_concept.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/polygon_concept.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,391 @@
+struct polygon_concept {
+ inline polygon_concept() {}
+
+ template <class iterator_type, class point_type>
+ class iterator_points {
+ private:
+ iterator_type iter_;
+ iterator_type iter_end_;
+ point_type pt_;
+ typename point_traits<point_type>::coordinate_type firstX_;
+ orientation_2d orient_;
+ public:
+ inline iterator_points() {}
+ inline iterator_points(iterator_type iter, iterator_type iter_end) :
+ iter_(iter), iter_end_(iter_end), orient_(HORIZONTAL) {
+ if(iter_ != iter_end_) {
+ firstX_ = *iter_;
+ point_concept::set<HORIZONTAL>(pt_, firstX_);
+ ++iter_;
+ if(iter_ != iter_end_) {
+ point_concept::set<VERTICAL>(pt_, *iter_);
+ }
+ }
+ }
+ //use bitwise copy and assign provided by the compiler
+ inline iterator_points& operator++() {
+ ++iter_;
+ if(iter_ == iter_end_) {
+ if(point_concept::get<HORIZONTAL>(pt_) != firstX_) {
+ --iter_;
+ point_concept::set<HORIZONTAL>(pt_, firstX_);
+ }
+ } else {
+ point_concept::set(pt_, orient_, *iter_);
+ orient_.turn_90();
+ }
+ return *this;
+ }
+ inline iterator_points operator++(int) {
+ iterator_points tmp(*this);
+ ++(*this);
+ return tmp;
+ }
+ inline bool operator==(const iterator_points& that) const {
+ return (iter_ == that.iter_);
+ }
+ inline bool operator!=(const iterator_points& that) const {
+ return (iter_ != that.iter_);
+ }
+ inline const point_type& operator*() const { return pt_; }
+ };
+
+ template <class iT, typename coordinate_type>
+ class iterator_points_to_coords {
+ private:
+ iT iter_;
+ orientation_2d orient_;
+ public:
+ inline iterator_points_to_coords() {}
+ inline iterator_points_to_coords(iT iter) : iter_(iter), orient_(HORIZONTAL) {}
+ inline iterator_points_to_coords(const iterator_points_to_coords& that) :
+ iter_(that.iter_), orient_(that.orient_) {}
+ //use bitwise copy and assign provided by the compiler
+ inline iterator_points_to_coords& operator++() {
+ ++iter_;
+ orient_.turn_90();
+ return *this;
+ }
+ inline iterator_points_to_coords operator++(int) {
+ iT tmp(*this);
+ ++(*this);
+ return tmp;
+ }
+ inline bool operator==(const iterator_points_to_coords& that) const {
+ return (iter_ == that.iter_);
+ }
+ inline bool operator!=(const iterator_points_to_coords& that) const {
+ return (iter_ != that.iter_);
+ }
+ inline coordinate_type operator*() { return (*iter_).get(orient_); }
+ };
+
+ template<typename polygon_type, typename iterator_type>
+ static void set(polygon_type& polygon, iterator_type input_begin, iterator_type input_end) {
+ polygon_traits<polygon_type>::set(polygon, input_begin, input_end);
+ }
+
+ template<typename polygon_type, typename rectangle_type>
+ static void set(polygon_type& polygon, const rectangle_type& rect) {
+ typename polygon_traits<polygon_type>::coordinate_type coords[4] =
+ {rectangle_concept::xl(rect), rectangle_concept::yl(rect),
+ rectangle_concept::xh(rect), rectangle_concept::yh(rect)};
+ set(polygon, coords, coords+4);
+ }
+
+ template<typename polygon_type, typename point_iterator_type>
+ static void set_points(polygon_type& polygon, point_iterator_type begin_point, point_iterator_type end_point) {
+ return set(iterator_points_to_coords<point_iterator_type,
+ typename polygon_traits<polygon_type>::coordinate_type>(begin_point),
+ iterator_points_to_coords<point_iterator_type,
+ typename polygon_traits<polygon_type>::coordinate_type>(end_point));
+ }
+
+ template <typename polygon_type>
+ static typename polygon_traits<polygon_type>::iterator_type begin(const polygon_type& polygon) {
+ return polygon_traits<polygon_type>::begin(polygon);
+ }
+
+ template <typename polygon_type>
+ static typename polygon_traits<polygon_type>::iterator_type end(const polygon_type& polygon) {
+ return polygon_traits<polygon_type>::end(polygon);
+ }
+
+ template <typename polygon_type>
+ static iterator_points<typename polygon_traits<polygon_type>::iterator_type,
+ point_data<typename polygon_traits<polygon_type>::coordinate_type> >
+ begin_points(const polygon_type& polygon) {
+ return iterator_points<typename polygon_traits<polygon_type>::iterator_type,
+ point_data<typename polygon_traits<polygon_type>::coordinate_type> > (begin(polygon), end(polygon));
+ }
+
+ template <typename polygon_type>
+ static iterator_points<typename polygon_traits<polygon_type>::iterator_type,
+ point_data<typename polygon_traits<polygon_type>::coordinate_type> >
+ end_points(const polygon_type& polygon) {
+ return iterator_points<typename polygon_traits<polygon_type>::iterator_type,
+ point_data<typename polygon_traits<polygon_type>::coordinate_type> > (end(polygon), end(polygon));
+ }
+
+ template<typename T, class iT>
+ static T construct(iT inputBegin, iT inputEnd) { return polygon_traits<T>::construct(inputBegin, inputEnd); }
+
+ template<typename polygon_type, typename rectangle_type>
+ static polygon_type construct_from_rectangle(const rectangle_type& rect) {
+ polygon_type poly;
+ set(poly, rect);
+ return poly;
+ }
+
+ template <typename polygon_type, typename polygon_type2>
+ static polygon_type copy_construct(const polygon_type2& polygon) {
+ return construct(polygon_concept::begin(polygon), polygon_concept::end(polygon));
+ }
+
+ template <typename polygon_type>
+ static std::size_t size(const polygon_type& polygon) {
+ return polygon_traits<polygon_type>::size(polygon);
+ }
+
+ template <typename polygon_type_1, typename polygon_type_2>
+ static polygon_type_1& assign(polygon_type_1& lvalue, const polygon_type_2& rvalue) {
+ set(lvalue, begin(rvalue), end(rvalue));
+ return lvalue;
+ }
+
+ template <typename polygon_type>
+ static direction_1d winding(const polygon_type& polygon){
+ winding_direction wd = polygon_traits<polygon_type>::winding(polygon);
+ if(wd != unknown_winding) {
+ return wd == clockwise_winding ? LOW: HIGH;
+ }
+ direction_1d dir = HIGH;
+ typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
+ typedef typename polygon_traits<polygon_type>::iterator iterator;
+ iterator itr = begin(polygon);
+ coordinate_type firstx = *itr;
+ coordinate_type minX = firstx;
+ ++itr;
+ iterator end_itr = end(polygon);
+ if(itr == end_itr) return dir;
+ coordinate_type prevy = *itr;
+ coordinate_type firsty = *itr;
+ ++itr;
+ for( ; itr != end_itr; ++itr) {
+ coordinate_type x = *itr;
+ ++itr;
+ if(itr == end_itr) break;
+ coordinate_type y = *itr;
+ if(x <= minX) {
+ minX = x;
+ //edge directed downward on left side of figure is counterclockwise
+ dir = y < prevy ? HIGH : LOW;
+ }
+ prevy = y;
+ }
+ if(firstx <= minX) {
+ dir = firsty < prevy ? HIGH : LOW;
+ }
+ return dir;
+ }
+
+ template <typename polygon_type>
+ static rectangle_data<typename polygon_traits<polygon_type>::coordinate_type>
+ bounding_box(const polygon_type& polygon) {
+ typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
+ typedef typename polygon_traits<polygon_type>::iterator_type iterator;
+ coordinate_type xmin = 0;
+ coordinate_type ymin = 0;
+ coordinate_type xmax = 0;
+ coordinate_type ymax = 0;
+ bool first_iteration = true;
+ iterator itr_end = end(polygon);
+ for(iterator itr = begin(polygon); itr != itr_end; ++itr) {
+ coordinate_type x = *itr;
+ ++itr;
+ if(itr == itr_end) break;
+ coordinate_type y = *itr;
+ if(first_iteration) {
+ xmin = xmax = x;
+ ymin = ymax = x;
+ first_iteration = false;
+ }
+ xmin = std::min(xmin, x);
+ xmax = std::max(xmax, x);
+ ymin = std::min(ymin, y);
+ ymax = std::max(ymax, y);
+ }
+ typedef rectangle_data<coordinate_type> rectangle_type;
+ rectangle_type return_value = rectangle_concept::construct<rectangle_type>(xmin, ymin, xmax, ymax);
+ return return_value;
+ }
+
+ template <typename polygon_type>
+ static typename polygon_traits<polygon_type>::coordinate_type
+ area(const polygon_type& polygon) {
+ //for (long i = 2; i < _size; i += 2) res += ((double)_vertex[i-1])*((double)(_vertex[i-2] - _vertex[i]));
+ typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
+ typedef typename polygon_traits<polygon_type>::iterator_type iterator;
+ coordinate_type retval = 0;
+ iterator itr = begin(polygon);
+ iterator end_itr = end(polygon);
+ coordinate_type firstx = *itr;
+ coordinate_type prevx = *itr;
+ ++itr;
+ if(itr == end_itr) return 0;
+ coordinate_type prevy = *itr;
+ ++itr;
+ for( ; itr != end_itr; ++itr) {
+ coordinate_type x = *itr;
+ ++itr;
+ if(itr == end_itr) break;
+ coordinate_type y = *itr;
+ retval += (prevy * (prevx - x));
+ prevy = y;
+ prevx = x;
+ }
+ retval += (prevy * (prevx - firstx));
+ return retval >= 0 ? retval : -retval;
+ }
+
+ /// get the perimeter of the rectangle
+ template <typename polygon_type>
+ static typename polygon_traits<polygon_type>::coordinate_type
+ perimeter(const polygon_type& polygon) {
+ typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
+ typedef typename polygon_traits<polygon_type>::iterator_type iterator_type;
+ typedef iterator_points<iterator_type, point_data<coordinate_type> > iterator;
+ coordinate_type return_value = 0;
+ point_data<coordinate_type> previous_point, first_point;
+ iterator itr = begin_points(polygon);
+ iterator itr_end = end_points(polygon);
+ if(itr == itr_end) return return_value;
+ previous_point = first_point = *itr;
+ ++itr;
+ for( ; itr != itr_end; ++itr) {
+ ++itr;
+ if(itr == itr_end) break;
+ point_data<coordinate_type> current_point = *itr;
+ return_value += point_concept::manhattan_distance(current_point, previous_point);
+ previous_point = current_point;
+ }
+ return_value += point_concept::manhattan_distance(previous_point, first_point);
+ return return_value;
+ }
+
+ /// check if point is inside polygon
+ template <typename polygon_type, typename point_type>
+ static bool contains_point(const polygon_type& polygon, const point_type& point,
+ bool consider_touch = true) {
+ typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
+ typedef typename polygon_traits<polygon_type>::iterator_type iterator_type;
+ typedef iterator_points<iterator_type, point_data<coordinate_type> > iterator;
+ iterator iter, iter_end;
+ iter_end = end_points(polygon);
+ iter = begin_points(polygon);
+ point_data<coordinate_type> prev_pt = *iter;
+ unsigned int num = size(polygon);
+ unsigned int counts[2] = {0, 0};
+ for(unsigned int i = 0; i < num; ++i) {
+ if(i == num-1) iter = begin_points(polygon);
+ else ++iter;
+ point_data<coordinate_type> current_pt = *iter;
+ if(point_concept::get<HORIZONTAL>(current_pt) ==
+ point_concept::get<HORIZONTAL>(prev_pt)) {
+ unsigned int index = point_concept::get<HORIZONTAL>(current_pt) >
+ point_concept::get<HORIZONTAL>(point);
+ unsigned int increment = 0;
+ interval_data<coordinate_type> ivl =
+ interval_concept::construct<interval_data<coordinate_type> >(point_concept::get<VERTICAL>(current_pt),
+ point_concept::get<VERTICAL>(prev_pt));
+ if(interval_concept::contains_coordinate(ivl, point_concept::get<VERTICAL>(point), true)) {
+ if(point_concept::get<HORIZONTAL>(current_pt) ==
+ point_concept::get<HORIZONTAL>(point)) return consider_touch;
+ ++increment;
+ if(point_concept::get<VERTICAL>(current_pt) !=
+ point_concept::get<VERTICAL>(point) &&
+ point_concept::get<VERTICAL>(prev_pt) !=
+ point_concept::get<VERTICAL>(point)) {
+ ++increment;
+ }
+ counts[index] += increment;
+ }
+ }
+ prev_pt = current_pt;
+ }
+ //odd count implies boundary condition
+ if(counts[0] % 2 || counts[1] % 2) return consider_touch;
+ //an odd number of edges to the left implies interior pt
+ return counts[0] % 4;
+ }
+
+// //awaiting re-implementation of iterator_edges and edge concept
+// template <typename polygon_type, typename point_type>
+// static point_type project(const polygon_type& polygon, const point_type& point) const {
+// point_type return_value;
+// typedef iterator_edges<typename polygon_traits<polygon_type>::iterator_type,
+// edge_data<typename polygon_traits<polygon_type>::coordinate_type> > iterator;
+// iterator iter = begin_edges();
+// iterator iter_end = end_edges();
+// double dist = 0;
+// bool first_segment = true;
+// for( ; iter != iter_end; ++iter) {
+// point_type segement_point = segment_concept::project_point(*iter, point);
+// double seg_dist = point_concept::euclidian_distance(point, segment_point);
+// if(first_segment || seg_dist < dist) {
+// dist = seg_dist;
+// return_value = segment_point;
+// }
+// }
+// return return_value;
+// }
+
+// //awaiting re-implementation of iterator_edges and edge concept
+// template <typename polygon_type, typename point_type>
+// static point_type project(point_type& result, const polygon_type& polygon,
+// const point_type& point, direction_2d dir) {
+// typedef iterator_edges<typename polygon_traits<polygon_type>::iterator_type,
+// edge_data<typename polygon_traits<polygon_type>::coordinate_type> > iterator;
+// iterator iter = begin_edges();
+// iterator iter_end = end_edges();
+// double dist = 0;
+// bool found = false;
+// bool first_segment = true;
+// for( ; iter != iter_end; ++iter) {
+// point_type segement_point;
+// if(segment_concept::project_point(segment_point, *iter, point, dir)) {
+// found = true;
+// double seg_dist = point_concept::euclidian_distance(point, segment_point);
+// if(first_segment || seg_dist < dist) {
+// dist = seg_dist;
+// result = segment_point;
+// }
+// }
+// return found;
+// }
+
+ template <typename polygon_type, typename coordinate_type_1, typename coordinate_type_2>
+ static void move(polygon_type& polygon, coordinate_type_1 x_displacement, coordinate_type_2 y_displacement) {
+ std::vector<typename polygon_traits<polygon_type>::coordinate_type> coords;
+ coords.reserve(size(polygon));
+ bool pingpong = true;
+ for(typename polygon_traits<polygon_type>::iterator_type iter = begin(polygon);
+ iter != end(polygon); ++iter) {
+ coords.push_back((*iter) + predicated_value(pingpong, x_displacement, y_displacement));
+ pingpong = !pingpong;
+ }
+ set(polygon, coords.begin(), coords.end());
+ }
+
+ /// move polygon by delta in orient
+ template <typename polygon_type, typename coordinate_type_1>
+ static void move(polygon_type& polygon, orientation_2d orient, coordinate_type_1 displacement) {
+ if(orient == HORIZONTAL) {
+ move(displacement, 0);
+ } else {
+ move(0, displacement);
+ }
+ }
+};
+
+

Added: sandbox/gtl/gtl/polygon_data.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/polygon_data.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,44 @@
+template <typename T>
+class polygon_data {
+public:
+ typedef T coordinate_type;
+ typedef typename std::vector<coordinate_type>::const_iterator iterator_type;
+
+ inline polygon_data(){;} //do nothing default constructor
+
+ /// initialize a polygon from x,y values, it is assumed that the first is an x
+ /// and that the input is a well behaved polygon
+ template<class iT>
+ inline polygon_data& set(iT input_begin, iT input_end) {
+ coords_.clear(); //just in case there was some old data there
+ while(input_begin != input_end) {
+ coords_.insert(coords_.end(), *input_begin);
+ ++input_begin;
+ }
+ return *this;
+ }
+
+ /// copy constructor (since we have dynamic memory)
+ inline polygon_data(const polygon_data& that) : coords_(that.coords_) {}
+
+ /// assignment operator (since we have dynamic memory do a deep copy)
+ inline polygon_data& operator=(const polygon_data& that) {
+ coords_ = that.coords_;
+ return *this;
+ }
+
+ template <typename T2>
+ inline polygon_data& operator=(const T2& rvalue);
+
+ /// get begin iterator, returns a pointer to a const Unit
+ inline iterator_type begin() const { return coords_.begin(); }
+
+ /// get end iterator, returns a pointer to a const Unit
+ inline iterator_type end() const { return coords_.end(); }
+
+ inline std::size_t size() const { return coords_.size(); }
+
+private:
+ std::vector<coordinate_type> coords_;
+};
+

Added: sandbox/gtl/gtl/polygon_traits.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/polygon_traits.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,33 @@
+template <class T>
+struct polygon_traits {
+ typedef typename T::coordinate_type coordinate_type;
+ typedef typename T::iterator_type iterator_type;
+
+ /// Get the begin iterator
+ static inline iterator_type begin(const T& t) {
+ return t.begin();
+ }
+
+ /// Get the end iterator
+ static inline iterator_type end(const T& t) {
+ return t.end();
+ }
+
+ /// Set the data of a polygon with the unique coordinates in an iterator, starting with an x
+ template <class iT>
+ static inline T& set(T& t, iT input_begin, iT input_end) {
+ t.set(input_begin, input_end);
+ return t;
+ }
+
+ /// Get the number of sides of the polygon
+ static inline unsigned int size(const T& t) {
+ return t.size();
+ }
+
+ /// Get the winding direction of the polygon
+ static inline winding_direction winding(const T& t) {
+ return unknown_winding;
+ }
+};
+

Added: sandbox/gtl/gtl/post_concept_definitions.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/post_concept_definitions.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,42 @@
+template <typename T>
+template <typename interval_type>
+inline void rectangle_data<T>::set(orientation_2d orient, const interval_type& interval) {
+ ranges_[orient.to_int()].set(LOW, interval_concept::get(interval, LOW));
+ ranges_[orient.to_int()].set(HIGH, interval_concept::get(interval, HIGH));
+}
+
+template <class T>
+template <class T2>
+point_data<T>& point_data<T>::operator=(const T2& rvalue) {
+ point_concept::assign(*this, rvalue);
+ return *this;
+}
+
+template <class T>
+template <class T2>
+interval_data<T>& interval_data<T>::operator=(const T2& rvalue) {
+ interval_concept::assign(*this, rvalue);
+ return *this;
+}
+
+template <class T>
+template <class T2>
+rectangle_data<T>& rectangle_data<T>::operator=(const T2& rvalue) {
+ rectangle_concept::assign(*this, rvalue);
+ return *this;
+}
+
+template <class T>
+template <class T2>
+point_3d_data<T>& point_3d_data<T>::operator=(const T2& rvalue) {
+ point_3d_concept::assign(*this, rvalue);
+ return *this;
+}
+
+template <class T>
+template <class T2>
+polygon_data<T>& polygon_data<T>::operator=(const T2& rvalue) {
+ polygon_concept::assign(*this, rvalue);
+ return *this;
+}
+

Added: sandbox/gtl/gtl/post_geometry_traits_definitions.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/post_geometry_traits_definitions.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,11 @@
+template <typename rectangle_type, typename geometry_type>
+bool rectangle_concept::contains(const rectangle_type& rectangle, const geometry_type& contained_geometry_object) {
+ return rectangle_concept::contains_dispatch(rectangle, contained_geometry_object, typename geometry_traits<geometry_type>::geometry_concept());
+}
+
+template <typename geometry_type>
+struct component_type {
+ typedef typename geometry_traits<geometry_type>::geometry_concept::template
+ registration<geometry_type>::component_type type;
+};
+

Added: sandbox/gtl/gtl/rectangle_concept.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/rectangle_concept.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,106 @@
+struct rectangle_concept {
+ rectangle_concept() {}
+
+ template <typename rectangle_type>
+ struct registration {
+ typedef typename rectangle_traits<rectangle_type>::coordinate_type coordinate_type;
+ typedef interval_data<coordinate_type> component_type;
+ };
+
+ template <orientation_2d_enum orient, typename T>
+ static inline typename rectangle_traits<T>::interval_type
+ get(const T& rectangle) {
+ return rectangle_traits<T>::get(rectangle, orient);
+ }
+
+ template <typename T>
+ static inline typename rectangle_traits<T>::interval_type
+ get(const T& rectangle, orientation_2d orient) {
+ return rectangle_traits<T>::get(rectangle, orient);
+ }
+
+ template <orientation_2d_enum orient, typename T, typename T2>
+ static inline void set(T& rectangle, const T2& interval) {
+ rectangle_traits<T>::set(rectangle, orient, interval);
+ }
+
+ template <typename T, typename T2>
+ static inline void set(T& rectangle, orientation_2d orient, const T2& interval) {
+ rectangle_traits<T>::set(rectangle, orient, interval);
+ }
+
+ template <typename T, typename T2, typename T3>
+ static inline T construct(const T2& interval_horizontal,
+ const T3& interval_vertical) {
+ return rectangle_traits<T>::construct(interval_horizontal, interval_vertical); }
+
+ template <typename T, typename coordinate_type>
+ static inline T construct(coordinate_type xl, coordinate_type yl, coordinate_type xh, coordinate_type yh) {
+ return rectangle_traits<T>::construct(interval_data<coordinate_type>(xl, xh),
+ interval_data<coordinate_type>(yl, yh));
+ }
+
+ template <typename T, typename T2>
+ static T copy_construct(const T2& rectangle) {
+ return construct<T>
+ (get(rectangle, HORIZONTAL),
+ get(rectangle, VERTICAL));
+ }
+
+ template <typename rectangle_type_1, typename rectangle_type_2>
+ static rectangle_type_1& assign(rectangle_type_1& lvalue, const rectangle_type_2& rvalue) {
+ set(lvalue, HORIZONTAL, get(rvalue, HORIZONTAL));
+ set(lvalue, VERTICAL, get(rvalue, VERTICAL));
+ return lvalue;
+ }
+
+ template <typename T, typename T2>
+ static bool equivilence(const T& rect1, const T2& rect2) {
+ return interval_concept::equivilence(get(rect1, HORIZONTAL),
+ get(rect2, HORIZONTAL)) &&
+ interval_concept::equivilence(get(rect1, VERTICAL),
+ get(rect2, VERTICAL));
+ }
+
+ template <typename rectangle_type>
+ static typename rectangle_traits<rectangle_type>::coordinate_type
+ xl(const rectangle_type& rectangle) {
+ return interval_concept::get<LOW>(get<HORIZONTAL>(rectangle));
+ }
+
+ template <typename rectangle_type>
+ static typename rectangle_traits<rectangle_type>::coordinate_type
+ xh(const rectangle_type& rectangle) {
+ return interval_concept::get<HIGH>(get<HORIZONTAL>(rectangle));
+ }
+
+ template <typename rectangle_type>
+ static typename rectangle_traits<rectangle_type>::coordinate_type
+ yl(const rectangle_type& rectangle) {
+ return interval_concept::get<LOW>(get<VERTICAL>(rectangle));
+ }
+
+ template <typename rectangle_type>
+ static typename rectangle_traits<rectangle_type>::coordinate_type
+ yh(const rectangle_type& rectangle) {
+ return interval_concept::get<HIGH>(get<VERTICAL>(rectangle));
+ }
+
+ template <typename rectangle_type, typename rectangle_type2>
+ static bool contains_dispatch(const rectangle_type& rectangle, const rectangle_type2 rectangle_contained, rectangle_concept tag) {
+ std::cout << "rectangle contains rectangle\n";
+ }
+ template <typename rectangle_type, typename point_type>
+ static bool contains_dispatch(const rectangle_type& rectangle, const point_type point_contained, point_concept tag) {
+ std::cout << "rectangle contains point\n";
+ }
+ template <typename concept_type, typename rectangle_type, typename geometry_type>
+ static bool contains(const rectangle_type& rectangle, const geometry_type& contained_geometry_object) {
+ return contains_dispatch(rectangle, contained_geometry_object, concept_type());
+ }
+
+ template <typename rectangle_type, typename geometry_type>
+ static bool contains(const rectangle_type& rectangle, const geometry_type& contained_geometry_object);
+};
+
+

Added: sandbox/gtl/gtl/rectangle_data.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/rectangle_data.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,26 @@
+template <typename T>
+class rectangle_data {
+public:
+ typedef T coordinate_type;
+ inline rectangle_data() {}
+ template <typename interval_type_1, typename interval_type_2>
+ inline rectangle_data(const interval_type_1& hrange,
+ const interval_type_2& vrange) {
+ set(HORIZONTAL, hrange); set(VERTICAL, hrange); }
+
+ inline rectangle_data(const rectangle_data& that) { (*this) = that; }
+
+ inline rectangle_data& operator=(const rectangle_data& that) {
+ ranges_[0] = that.ranges_[0]; ranges_[1] = that.ranges_[1]; return *this;
+ }
+ template <typename T2>
+ inline rectangle_data& operator=(const T2& rvalue);
+
+ inline interval_data<coordinate_type> get(orientation_2d orient) const {
+ return ranges_[orient.to_int()]; }
+ template <typename interval_type>
+ inline void set(orientation_2d orient, const interval_type& interval);
+private:
+ interval_data<coordinate_type> ranges_[2];
+};
+

Added: sandbox/gtl/gtl/rectangle_traits.h
==============================================================================
--- (empty file)
+++ sandbox/gtl/gtl/rectangle_traits.h 2008-05-08 03:00:46 EDT (Thu, 08 May 2008)
@@ -0,0 +1,18 @@
+template <typename T>
+struct rectangle_traits {
+ typedef typename T::coordinate_type coordinate_type;
+ typedef interval_data<coordinate_type> interval_type;
+
+ static inline interval_type get(const T& rectangle, orientation_2d orient) {
+ return rectangle.get(orient); }
+
+ template <typename T2>
+ static inline void set(T& rectangle, orientation_2d orient, const T2& interval) {
+ rectangle.set(orient, interval); }
+
+ template <typename T2, typename T3>
+ static inline T construct(const T2& interval_horizontal,
+ const T3& interval_vertical) {
+ return T(interval_horizontal, interval_vertical); }
+};
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk