// Boost.Geometry (aka GGL, Generic Geometry Library) test file // // Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include #include using namespace boost::geometry; // define a custom circle struct custom_circle { float x,y; int r; }; // adapt custom circle using traits namespace boost { namespace geometry { namespace traits { template<> struct tag { typedef nsphere_tag type; }; template<> struct point_type { typedef point type; }; template<> struct radius_type { typedef int type; }; template<> struct access { static inline const float& get(custom_circle const& c) { return c.x; } static inline void set(custom_circle& c, float const& value) { c.y = value; } }; template<> struct access { static inline const float& get(const custom_circle& c) { return c.y; } static inline void set(custom_circle& c, float const& value) { c.y = value; } }; template<> struct radius_access { static inline int get(custom_circle const& c) { return c.r; } static inline void set(custom_circle& c, int const& radius) { c.r = radius; } }; }}} // namespace boost::geometry::traits template void check_nsphere(S& to_check, RT radius, CT center_x, CT center_y, CT center_z) { BOOST_CONCEPT_ASSERT( (concept::ConstNsphere) ); BOOST_CONCEPT_ASSERT( (concept::Nsphere) ); BOOST_CHECK_EQUAL(get_radius<0>(to_check), radius); BOOST_CHECK_EQUAL(get<0>(to_check), center_x); BOOST_CHECK_EQUAL(get<1>(to_check), center_y); if (dimension::value >= 3) { BOOST_CHECK_EQUAL(get<2>(to_check), center_z); } } template void test_construction() { typedef typename coordinate_type

::type ctype; nsphere c1; check_nsphere(c1, 0, 0,0,0); P center; boost::geometry::assign(center, 1, 2, 3); nsphere c2(center, 4); check_nsphere(c2, 4, 1,2,3); } template void test_assignment_3d() { C c; // by hand set<0>(c, 5); set<1>(c, 50); set<2>(c, 500); set_radius<0>(c, 5000); check_nsphere(c, 5000, 5,50,500); assign(c, 6, 60, 600); check_nsphere(c, 5000, 6,60,600); } template void test_assignment_2d() { C c; // by hand set<0>(c, 5); set<1>(c, 50); set_radius<0>(c, 5000); } template void test_all() { test_construction(); test_assignment_3d >(); } template void test_all() { test_all(); test_all(); test_all(); } int test_main(int, char* []) { test_all(); test_all(); test_all(); test_all(); test_all >(); test_all >(); test_all >(); test_assignment_2d(); return 0; }