diff --git a/include/boost/geometry/extensions/nsphere/algorithms/disjoint.hpp b/include/boost/geometry/extensions/nsphere/algorithms/disjoint.hpp index 31cc8d6ea..4e73ba8e7 100644 --- a/include/boost/geometry/extensions/nsphere/algorithms/disjoint.hpp +++ b/include/boost/geometry/extensions/nsphere/algorithms/disjoint.hpp @@ -132,7 +132,7 @@ struct disjoint static inline bool apply(Point const& p, NSphere const& s) { typedef typename coordinate_system::type p_cs; - typedef typename typename coordinate_system::type s_cs; + typedef typename coordinate_system::type s_cs; static const bool check_cs = ::boost::is_same::value && ::boost::is_same::value; BOOST_MPL_ASSERT_MSG(check_cs, NOT_IMPLEMENTED_FOR_THOSE_COORDINATE_SYSTEMS, (p_cs, s_cs)); @@ -149,7 +149,7 @@ struct disjoint static inline bool apply(NSphere const& s, Box const& b) { typedef typename coordinate_system::type b_cs; - typedef typename typename coordinate_system::type s_cs; + typedef typename coordinate_system::type s_cs; static const bool check_cs = ::boost::is_same::value && ::boost::is_same::value; BOOST_MPL_ASSERT_MSG(check_cs, NOT_IMPLEMENTED_FOR_THOSE_COORDINATE_SYSTEMS, (b_cs, s_cs)); @@ -165,15 +165,20 @@ struct disjoint::type s1_cs; - typedef typename typename coordinate_system::type s2_cs; + typedef typename coordinate_system::type s1_cs; + typedef typename coordinate_system::type s2_cs; static const bool check_cs = ::boost::is_same::value && ::boost::is_same::value; BOOST_MPL_ASSERT_MSG(check_cs, NOT_IMPLEMENTED_FOR_THOSE_COORDINATE_SYSTEMS, (s1_cs, s2_cs)); - return get_radius<0>(s1) + get_radius<0>(s2) + /*return get_radius<0>(s1) + get_radius<0>(s2) < ::sqrt(geometry::detail::disjoint::points_or_spheres_comparable_distance_cartesian< - Point, NSphere, 0, DimensionCount - >::apply(p, s)); + NSphere1, NSphere2, 0, DimensionCount + >::apply(s1, s2));*/ + + return get_radius<0>(s1) * get_radius<0>(s1) + 2 * get_radius<0>(s1) * get_radius<0>(s2) + get_radius<0>(s2) * get_radius<0>(s2) + < geometry::detail::disjoint::points_or_spheres_comparable_distance_cartesian< + NSphere1, NSphere2, 0, DimensionCount + >::apply(s1, s2); } }; diff --git a/include/boost/geometry/extensions/nsphere/index/detail/algorithms/content.hpp b/include/boost/geometry/extensions/nsphere/index/detail/algorithms/content.hpp new file mode 100644 index 000000000..d1fc044b1 --- /dev/null +++ b/include/boost/geometry/extensions/nsphere/index/detail/algorithms/content.hpp @@ -0,0 +1,76 @@ +// Boost.Geometry Index +// +// n-dimensional content (hypervolume) - 2d area, 3d volume, ... +// +// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. +// +// 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) + +#ifndef BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP +#define BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP + +#include + +namespace boost { namespace geometry { namespace index { namespace detail { + +namespace dispatch { + +// TODO replace it by comparable_content? +// probably radius^Dimension would be sufficient +// WARNING! this would work only if the same Geometries were compared +// so it shouldn't be used in the case of Variants! +// The same with margin()! + +template +struct content_nsphere +{ + BOOST_STATIC_ASSERT(2 < Dimension); + + typedef typename detail::default_content_result::type result_type; + + static inline result_type apply(NSphere const& s) + { + return (content_nsphere::apply(s) + * 2 * get_radius<0>(s) * get_radius<0>(s) + * ::boost::math::constants::pi()) / Dimension; + } +}; + +template +struct content_nsphere +{ + typedef typename detail::default_content_result::type result_type; + + static inline result_type apply(NSphere const& s) + { + return ::boost::math::constants::pi() * get_radius<0>(s) * get_radius<0>(s); + } +}; + +template +struct content_nsphere +{ + typedef typename detail::default_content_result::type result_type; + + static inline result_type apply(NSphere const& s) + { + return 2 * get_radius<0>(s); + } +}; + +template +struct content +{ + static typename default_content_result::type apply(Indexable const& i) + { + return dispatch::content_nsphere::value>::apply(i); + } +}; + +} // namespace dispatch + +}}}} // namespace boost::geometry::index::detail + +#endif // BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP diff --git a/include/boost/geometry/extensions/nsphere/index/detail/algorithms/is_valid.hpp b/include/boost/geometry/extensions/nsphere/index/detail/algorithms/is_valid.hpp new file mode 100644 index 000000000..fec746168 --- /dev/null +++ b/include/boost/geometry/extensions/nsphere/index/detail/algorithms/is_valid.hpp @@ -0,0 +1,33 @@ +// Boost.Geometry Index +// +// n-dimensional Indexable validity check +// +// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. +// +// 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) + +#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP +#define BOOST_GEOMETRY_EXTENSIONS_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP + +#include + +namespace boost { namespace geometry { namespace index { namespace detail { + +namespace dispatch { + +template +struct is_valid +{ + static inline bool apply(Indexable const& i) + { + return 0 <= geometry::get_radius<0>(i); + } +}; + +} // namespace dispatch + +}}}} // namespace boost::geometry::index::detail + +#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP diff --git a/include/boost/geometry/extensions/nsphere/index/detail/algorithms/margin.hpp b/include/boost/geometry/extensions/nsphere/index/detail/algorithms/margin.hpp new file mode 100644 index 000000000..472c31776 --- /dev/null +++ b/include/boost/geometry/extensions/nsphere/index/detail/algorithms/margin.hpp @@ -0,0 +1,59 @@ +// Boost.Geometry Index +// +// n-dimensional margin value (hypersurface), 2d perimeter, 3d surface, etc... +// +// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. +// +// 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) + +#ifndef BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_ALGORITHMS_MARGIN_HPP +#define BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_ALGORITHMS_MARGIN_HPP + +#include + +namespace boost { namespace geometry { namespace index { namespace detail { + +template +struct comparable_margin_nsphere +{ + BOOST_STATIC_ASSERT(1 < Dimension); + BOOST_STATIC_ASSERT(Dimension <= detail::traits::dimension::value); + + static inline typename default_margin_result::type apply(NSphere const& s) + { + return comparable_margin_nsphere::apply(s) + * geometry::get_radius<0>(s); + } +}; + +template +struct comparable_margin_nsphere +{ + static inline typename default_margin_result::type apply(NSphere const& s) + { + return 1; + } +}; + +namespace dispatch { + +template +struct comparable_margin +{ + typedef typename default_margin_result::type result_type; + + static inline result_type apply(NSphere const& g) + { + return comparable_margin_nsphere< + NSphere, dimension::value + >::apply(g); + } +}; + +} // namespace dispatch + +}}}} // namespace boost::geometry::index::detail + +#endif // BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_ALGORITHMS_MARGIN_HPP diff --git a/include/boost/geometry/extensions/nsphere/index/detail/indexable.hpp b/include/boost/geometry/extensions/nsphere/index/detail/indexable.hpp new file mode 100644 index 000000000..c82d5e9b4 --- /dev/null +++ b/include/boost/geometry/extensions/nsphere/index/detail/indexable.hpp @@ -0,0 +1,30 @@ +// Boost.Geometry Index +// +// Indexable's traits and related functions +// +// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. +// +// 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 + +#ifndef BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_INDEXABLE_HPP +#define BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_INDEXABLE_HPP + +namespace boost { namespace geometry { namespace index { namespace detail { + +namespace dispatch { + +template +struct point_type +{ + typedef typename geometry::traits::point_type::type type; +}; + +} // namespace dispatch + +}}}} // namespace boost::geometry::index::detail + +#endif // BOOST_GEOMETRY_EXTENSIONS_NSPHERE_INDEX_DETAIL_INDEXABLE_HPP diff --git a/include/boost/geometry/extensions/nsphere/nsphere.hpp b/include/boost/geometry/extensions/nsphere/nsphere.hpp index 0f5ea1ea6..2fea4360c 100644 --- a/include/boost/geometry/extensions/nsphere/nsphere.hpp +++ b/include/boost/geometry/extensions/nsphere/nsphere.hpp @@ -35,4 +35,9 @@ #include #include +#include +#include +#include +#include + #endif // BOOST_GEOMETRY_EXTENSIONS_NSPHERE_HPP diff --git a/include/boost/geometry/index/detail/algorithms/content.hpp b/include/boost/geometry/index/detail/algorithms/content.hpp index 5425d9db7..1b6e370a1 100644 --- a/include/boost/geometry/index/detail/algorithms/content.hpp +++ b/include/boost/geometry/index/detail/algorithms/content.hpp @@ -1,6 +1,6 @@ // Boost.Geometry Index // -// n-dimensional box's content (hypervolume) - 2d area, 3d volume, ... +// n-dimensional content (hypervolume) - 2d area, 3d volume, ... // // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland. // @@ -19,7 +19,7 @@ template struct default_content_result { typedef typename select_most_precise< - typename detail::traits::coordinate_type::type, + typename coordinate_type::type, long double >::type type; }; @@ -27,20 +27,20 @@ struct default_content_result namespace dispatch { template -struct content_for_each_dimension +struct content_box { BOOST_STATIC_ASSERT(0 < CurrentDimension); - BOOST_STATIC_ASSERT(CurrentDimension <= traits::dimension::value); + //BOOST_STATIC_ASSERT(CurrentDimension <= traits::dimension::value); static inline typename detail::default_content_result::type apply(Box const& b) { - return content_for_each_dimension::apply(b) * + return content_box::apply(b) * ( detail::get(b) - detail::get(b) ); } }; template -struct content_for_each_dimension +struct content_box { static inline typename detail::default_content_result::type apply(Box const& b) { @@ -51,7 +51,7 @@ struct content_for_each_dimension template struct content { - // TODO: awulkiew - static assert? + BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_INDEXABLE_AND_TAG, (Indexable, Tag)); }; template @@ -68,7 +68,7 @@ struct content { static typename default_content_result::type apply(Indexable const& b) { - return dispatch::content_for_each_dimension::value>::apply(b); + return dispatch::content_box::value>::apply(b); } }; @@ -78,7 +78,7 @@ template typename default_content_result::type content(Indexable const& b) { return dispatch::content::type + typename tag::type >::apply(b); } diff --git a/include/boost/geometry/index/detail/algorithms/margin.hpp b/include/boost/geometry/index/detail/algorithms/margin.hpp index 03e981190..7389ec72d 100644 --- a/include/boost/geometry/index/detail/algorithms/margin.hpp +++ b/include/boost/geometry/index/detail/algorithms/margin.hpp @@ -13,6 +13,9 @@ #include +// WARNING! comparable_margin() will work only if the same Geometries are compared +// so it shouldn't be used in the case of Variants! + namespace boost { namespace geometry { namespace index { namespace detail { template @@ -90,11 +93,15 @@ struct default_margin_result // } //}; +// TODO - test if this definition of margin is ok for Dimension > 2 +// Now it's sum of edges lengths +// maybe margin_for_each_dimension should be used to get more or less hypersurface? + template struct simple_margin_for_each_dimension { BOOST_STATIC_ASSERT(0 < CurrentDimension); - BOOST_STATIC_ASSERT(CurrentDimension <= detail::traits::dimension::value); + //BOOST_STATIC_ASSERT(CurrentDimension <= dimension::value); static inline typename default_margin_result::type apply(Box const& b) { @@ -112,17 +119,49 @@ struct simple_margin_for_each_dimension } }; -template -typename default_margin_result::type comparable_margin(Box const& b) +namespace dispatch { + +template +struct comparable_margin { - //return detail::margin_for_each_dimension::value>::apply(b); - return detail::simple_margin_for_each_dimension::value>::apply(b); + BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY, (Geometry, Tag)); +}; + +template +struct comparable_margin +{ + typedef typename default_margin_result::type result_type; + + static inline result_type apply(Geometry const& g) { return 0; } +}; + +template +struct comparable_margin +{ + typedef typename default_margin_result::type result_type; + + static inline result_type apply(Box const& g) + { + //return detail::margin_for_each_dimension::value>::apply(g); + return detail::simple_margin_for_each_dimension::value>::apply(g); + } +}; + +} // namespace dispatch + +template +typename default_margin_result::type comparable_margin(Geometry const& g) +{ + return dispatch::comparable_margin< + Geometry, + typename tag::type + >::apply(g); } //template //typename default_margin_result::type margin(Box const& b) //{ -// return 2 * detail::margin_for_each_dimension::value>::apply(b); +// return 2 * detail::margin_for_each_dimension::value>::apply(b); //} }}}} // namespace boost::geometry::index::detail