Boost logo

Boost-Commit :

From: huseyinakcan_at_[hidden]
Date: 2007-07-23 22:28:32


Author: huseyinakcan
Date: 2007-07-23 22:28:31 EDT (Mon, 23 Jul 2007)
New Revision: 7518
URL: http://svn.boost.org/trac/boost/changeset/7518

Log:
container_add added to container_selectors.hpp with test cases.
new_edge added to halfedge_functions with test cases, that use
container_add.

Text files modified:
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp | 26 ++++++++++++++++
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.t.cpp | 39 ++++++++++++++++++++++++++
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.hpp | 59 ++++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.t.cpp | 45 +++++++++++++++++++++++++++++
   4 files changed, 167 insertions(+), 2 deletions(-)

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.hpp 2007-07-23 22:28:31 EDT (Mon, 23 Jul 2007)
@@ -367,6 +367,15 @@
         return container.end();
     }
 
+ static iterator container_add(ValueType& x, type& container)
+ // This utility adds an element at the end of the
+ // specified 'container', and returns an iterator
+ // pointing to that element.
+ {
+ container.push_back(x);
+ return --container_end(container);
+ }
+
     static ValueType& value(descriptor x, type& container)
             // This utility returns the value associated with the specified
             // descriptor 'x' of the specified 'container'.
@@ -451,6 +460,13 @@
         return container.end();
     }
 
+ static iterator container_add(ValueType& x, type& container)
+ // This utility adds an element at the
+ // specified 'container'.
+ {
+ return (container.insert(x)).first;
+ }
+
     static const ValueType& value(descriptor x, type& container)
             // This utility returns the value associated with the specified
             // descriptor 'x' of the specified 'container'.
@@ -556,12 +572,20 @@
     }
 
     static iterator container_end(type& container)
- // This utility returns an iterator to the beginning of the
+ // This utility returns an iterator to the end of the
         // specified 'container'.
     {
         return iterator(&container, container.end());
     }
 
+ static iterator container_add(ValueType x, type& container)
+ // This utility adds an element at the end of the
+ // specified 'container'.
+ {
+ container.push_back(x);
+ return --container_end(container);
+ }
+
     static ValueType& value(descriptor x, type& container)
             // This utility returns the value associated with the specified
             // descriptor 'x' of the specified 'container'.

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.t.cpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.t.cpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/container_selectors.t.cpp 2007-07-23 22:28:31 EDT (Mon, 23 Jul 2007)
@@ -126,6 +126,41 @@
     return true;
 }
 
+template <class ContainerGen, typename ValueType, typename ContainerS>
+bool container_gen_mutable_requirements() {
+ // Types must exist.
+ typedef typename ContainerGen::descriptor descriptor;
+ typedef typename ContainerGen::iterator iterator;
+
+ typename ContainerGen::type container;
+ ValueType array[] = { 0, 1, 2, 3 };
+ descriptor h0 = *ContainerGen::container_add(array[0], container);
+ descriptor h1 = *ContainerGen::container_add(array[1], container);
+ descriptor h2 = *ContainerGen::container_add(array[2], container);
+ descriptor h3 = *ContainerGen::container_add(array[3], container);
+ (void) h0; (void) h1; (void) h2; (void) h3;
+
+ // Value type of iterator must be a descriptor.
+ iterator begin = ContainerGen::container_begin(container);
+ descriptor theBegin = *begin;
+
+ // Descriptor must hold correct value:
+ BOOST_CHECK(( ContainerGen::value(theBegin, container) == 0 ));
+ BOOST_CHECK(( ContainerGen::value(*++begin, container) == 1 ));
+ BOOST_CHECK(( ContainerGen::value(*++begin, container) == 2 ));
+ BOOST_CHECK(( ContainerGen::value(*++begin, container) == 3 ));
+
+ // Value type of iterator must be a descriptor.
+ iterator end = ContainerGen::container_end(container);
+ descriptor theEnd = *--end;
+
+ // Descriptor must hold correct value:
+ BOOST_CHECK(( ContainerGen::value(theEnd, container) == 3 ));
+ BOOST_CHECK(( ContainerGen::value(*--end, container) == 2 ));
+ BOOST_CHECK(( ContainerGen::value(*--end, container) == 1 ));
+ BOOST_CHECK(( ContainerGen::value(*--end, container) == 0 ));
+ return true;
+}
 // ===========================================================================
 // USAGE EXAMPLE
 // ===========================================================================
@@ -253,6 +288,10 @@
     BOOST_CHECK(( container_gen_requirements<container_gen<setS, int>, int, setS>() ));
     BOOST_CHECK(( container_gen_requirements<container_gen<vecS, int>, int, vecS>() ));
 
+ BOOST_CHECK(( container_gen_mutable_requirements<container_gen<listS, int>, int, listS>() ));
+ BOOST_CHECK(( container_gen_mutable_requirements<container_gen<setS, int>, int, setS>() ));
+ BOOST_CHECK(( container_gen_mutable_requirements<container_gen<vecS, int>, int, vecS>() ));
+
     BOOST_CHECK(( usageExample() ));
     
     return 0;

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.hpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.hpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.hpp 2007-07-23 22:28:31 EDT (Mon, 23 Jul 2007)
@@ -27,6 +27,16 @@
 // - prev_at_target: returns a halfedge descriptor to the halfedge preceeding
 // the given halfedge around the target vertex, when halfedges
 // are ordered around a given vertex in clockwise order
+// - set_next_in_facet: sets 'g' as the halfedge succeeding 'h' in
+// the adjacent facet cycle, when facet cycles are oriented in
+// counter-clockwise order.
+// - set_next_at_source: sets 'g' as the halfedge succeeding 'h'
+// around the source vertex of 'h', when halfedges are ordered
+// around a given vertex in clockwise order.
+// - set_next_at_target: sets 'g' as the halfedge succeeding 'h'
+// around the target vertex of 'h', when halfedges are ordered
+// around a given vertex in clockwise order.
+//
 //
 ///Definitions
 //------------
@@ -109,6 +119,7 @@
>::opposite(h);
 }
 
+// \cond
 template<typename HalfedgeGen, typename HalfedgeDescriptor, typename Tag = next_in_facet_tag>
 struct next_in_facet_helper{
     static
@@ -223,6 +234,7 @@
                                 , hds));
     }
 };
+// \endcond
 
 template <typename HalfedgeS, typename VertexDescriptor, typename FacetDescriptor, typename Config>
 typename Config::halfedge_descriptor
@@ -266,6 +278,7 @@
     return next_at_target_helper<halfedgeGen, halfedge_descriptor, typename HalfedgeS::next_tag>::next_at_target(h,hds);
 }
 
+// \cond
 template<typename HalfedgeGen, typename HalfedgeDescriptor, typename Tag = prev_in_facet_tag>
 struct prev_in_facet_helper{
     static
@@ -380,6 +393,7 @@
                                 , hds));
     }
 };
+// \endcond
 
 template <typename HalfedgeS, typename VertexDescriptor, typename FacetDescriptor, typename Config>
 typename Config::halfedge_descriptor
@@ -423,6 +437,7 @@
     return prev_at_target_helper<halfedgeGen, halfedge_descriptor, typename HalfedgeS::prev_tag>::prev_at_target(h,hds);
 }
 
+// \cond
 template<typename HalfedgeGen, typename HalfedgeDescriptor, typename ContainerS, typename ThisTag, typename Tag>
 struct set_next_helper{
     static void
@@ -454,6 +469,7 @@
         h->m_next = g;
     }
 };
+// \endcond
 
 template <typename HalfedgeS, typename VertexDescriptor, typename FacetDescriptor, typename Config>
 void
@@ -512,6 +528,7 @@
                     ::set_next(h, g, hds);
 }
 
+// \cond
 template<typename HalfedgeGen, typename HalfedgeDescriptor, typename ContainerS, typename ThisTag, typename Tag>
 struct set_prev_helper{
     static void
@@ -543,6 +560,7 @@
         h->m_prev = g;
     }
 };
+// \endcond
 
 template <typename HalfedgeS, typename VertexDescriptor, typename FacetDescriptor, typename Config>
 void
@@ -601,6 +619,47 @@
                     ::set_prev(h, g, hds);
 }
 
+// \cond
+template<typename HalfedgeDescriptor, typename ContainerS>
+struct set_opposite_pair_helper{
+ static void
+ set_opposite(HalfedgeDescriptor& h, HalfedgeDescriptor& g)
+ {
+ h->m_opposite = g;
+ g->m_opposite = h;
+ }
+};
+
+template<typename HalfedgeDescriptor>
+struct set_opposite_pair_helper<HalfedgeDescriptor, vecS> {
+ static void
+ set_opposite(HalfedgeDescriptor& , HalfedgeDescriptor&)
+ {
+ // nothing to do
+ }
+};
+// \endcond
+
+template <typename HalfedgeS, typename VertexDescriptor, typename FacetDescriptor, typename Config>
+typename Config::halfedge_descriptor
+new_edge(halfedge_gen<HalfedgeS, VertexDescriptor, FacetDescriptor, Config>& hds)
+{
+ typedef halfedge_gen<HalfedgeS, VertexDescriptor, FacetDescriptor, Config> halfedgeGen;
+ typedef typename halfedgeGen::halfedge_descriptor halfedge_descriptor;
+ typedef typename halfedgeGen::halfedge_type halfedge_type;
+ typedef typename halfedgeGen::ContainerGen ContainerGen;
+
+ typedef typename halfedgeGen::halfedge_selector::container_selector containerS;
+
+ halfedge_type half_h;
+ halfedge_type half_g;
+ halfedge_descriptor h = *ContainerGen::container_add(half_h, hds.m_container);
+ halfedge_descriptor g = *ContainerGen::container_add(half_g, hds.m_container);
+ set_opposite_pair_helper<halfedge_descriptor, containerS>::set_opposite(h,g);
+ return g;
+}
+
+
 
 } // namespace hdstl
 } // namespace boost

Modified: sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.t.cpp
==============================================================================
--- sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.t.cpp (original)
+++ sandbox/SOC/2007/geometry/libs/hdstl/dev/halfedge_ds/halfedge_functions.t.cpp 2007-07-23 22:28:31 EDT (Mon, 23 Jul 2007)
@@ -1205,6 +1205,40 @@
     return true;
 }
 
+template <typename HalfedgeGen>
+bool halfedge_add_edge_test() {
+
+ // Types must exist.
+ typedef typename HalfedgeGen::halfedge_selector halfedge_selector;
+ typedef typename HalfedgeGen::halfedge_descriptor halfedge_descriptor;
+ typedef typename HalfedgeGen::halfedge_iterator halfedge_iterator;
+ typedef typename HalfedgeGen::halfedge_type halfedge_type;
+ typedef typename HalfedgeGen::ContainerGen container_gen;
+ typedef typename HalfedgeGen::ContainerGen::selector container_selector;
+ typedef typename HalfedgeGen::container_type container_type;
+
+
+ // Construct a halfedge_gen object, add hh and hg halfedge pair and
+ // test that they are added properly.
+
+ HalfedgeGen halfedgeGen;
+ halfedge_descriptor hg = static_cast<halfedge_descriptor>(new_edge(halfedgeGen));
+
+ halfedge_iterator begin = halfedges_begin(halfedgeGen);
+ halfedge_descriptor hh = *begin;
+ BOOST_CHECK(( opposite(hh, halfedgeGen) == hg));
+ BOOST_CHECK(( opposite(hg, halfedgeGen) == hh));
+
+ halfedge_descriptor hi = static_cast<halfedge_descriptor>(new_edge(halfedgeGen));
+ halfedge_iterator end = --halfedges_end(halfedgeGen);
+ halfedge_descriptor hj = *--end;
+ BOOST_CHECK(( opposite(hh, halfedgeGen) == hg));
+ BOOST_CHECK(( opposite(hg, halfedgeGen) == hh));
+ BOOST_CHECK(( opposite(hi, halfedgeGen) == hj));
+ BOOST_CHECK(( opposite(hj, halfedgeGen) == hi));
+
+ return true;
+}
 // ===========================================================================
 // USAGE EXAMPLE
 // ===========================================================================
@@ -1581,7 +1615,16 @@
                                                      prev_at_target_tag> >,
                         noVertexS, noFacetS> >
>() ));
-
+
+ // add_edge test
+ BOOST_CHECK(( halfedge_add_edge_test<
+ halfedge_gen<
+ halfedgeS<ContainerS, forwardS<next_at_target_tag> >,
+ int, int,
+ halfedge_config<
+ halfedgeS<ContainerS, forwardS<next_at_target_tag> >,
+ noVertexS, noFacetS> >
+ >() ));
     return true;
 }
 


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