mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-10 23:42:12 +00:00
Merge branch 'develop' of https://github.com/boostorg/geometry into feature/distance-for-merge
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_GET_RELATIVE_ORDER_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/algorithms/distance.hpp>
|
||||
|
||||
#include <boost/geometry/strategies/intersection.hpp>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
|
||||
// Copyright (c) 2007-2014 Barend Gehrels, 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)
|
||||
|
||||
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP
|
||||
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP
|
||||
|
||||
|
||||
#include <boost/geometry/core/access.hpp>
|
||||
#include <boost/geometry/core/coordinate_type.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail { namespace intersection
|
||||
{
|
||||
|
||||
template <std::size_t Dimension, std::size_t DimensionCount>
|
||||
struct intersection_box_box
|
||||
{
|
||||
template
|
||||
<
|
||||
typename Box1, typename Box2,
|
||||
typename RobustPolicy,
|
||||
typename BoxOut,
|
||||
typename Strategy
|
||||
>
|
||||
static inline bool apply(Box1 const& box1,
|
||||
Box2 const& box2,
|
||||
RobustPolicy const& robust_policy,
|
||||
BoxOut& box_out,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
typedef typename coordinate_type<BoxOut>::type ct;
|
||||
|
||||
ct min1 = get<min_corner, Dimension>(box1);
|
||||
ct min2 = get<min_corner, Dimension>(box2);
|
||||
ct max1 = get<max_corner, Dimension>(box1);
|
||||
ct max2 = get<max_corner, Dimension>(box2);
|
||||
|
||||
if (max1 < min2 || max2 < min1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Set dimensions of output coordinate
|
||||
set<min_corner, Dimension>(box_out, min1 < min2 ? min2 : min1);
|
||||
set<max_corner, Dimension>(box_out, max1 > max2 ? max2 : max1);
|
||||
|
||||
return intersection_box_box<Dimension + 1, DimensionCount>
|
||||
::apply(box1, box2, robust_policy, box_out, strategy);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t DimensionCount>
|
||||
struct intersection_box_box<DimensionCount, DimensionCount>
|
||||
{
|
||||
template
|
||||
<
|
||||
typename Box1, typename Box2,
|
||||
typename RobustPolicy,
|
||||
typename BoxOut,
|
||||
typename Strategy
|
||||
>
|
||||
static inline bool apply(Box1 const&, Box2 const&,
|
||||
RobustPolicy const&, BoxOut&, Strategy const&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} // namespace detail::intersection
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
|
||||
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_INTERSECTION_BOX_BOX_HPP
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <boost/geometry/core/coordinate_dimension.hpp>
|
||||
#include <boost/geometry/algorithms/detail/overlay/intersection_insert.hpp>
|
||||
#include <boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp>
|
||||
#include <boost/geometry/algorithms/intersects.hpp>
|
||||
#include <boost/geometry/policies/robustness/get_rescale_policy.hpp>
|
||||
|
||||
@@ -19,68 +20,6 @@
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
#ifndef DOXYGEN_NO_DETAIL
|
||||
namespace detail { namespace intersection
|
||||
{
|
||||
|
||||
template <std::size_t Dimension, std::size_t DimensionCount>
|
||||
struct intersection_box_box
|
||||
{
|
||||
template
|
||||
<
|
||||
typename Box1, typename Box2,
|
||||
typename RobustPolicy,
|
||||
typename BoxOut,
|
||||
typename Strategy
|
||||
>
|
||||
static inline bool apply(Box1 const& box1,
|
||||
Box2 const& box2,
|
||||
RobustPolicy const& robust_policy,
|
||||
BoxOut& box_out,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
typedef typename coordinate_type<BoxOut>::type ct;
|
||||
|
||||
ct min1 = get<min_corner, Dimension>(box1);
|
||||
ct min2 = get<min_corner, Dimension>(box2);
|
||||
ct max1 = get<max_corner, Dimension>(box1);
|
||||
ct max2 = get<max_corner, Dimension>(box2);
|
||||
|
||||
if (max1 < min2 || max2 < min1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Set dimensions of output coordinate
|
||||
set<min_corner, Dimension>(box_out, min1 < min2 ? min2 : min1);
|
||||
set<max_corner, Dimension>(box_out, max1 > max2 ? max2 : max1);
|
||||
|
||||
return intersection_box_box<Dimension + 1, DimensionCount>
|
||||
::apply(box1, box2, robust_policy, box_out, strategy);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t DimensionCount>
|
||||
struct intersection_box_box<DimensionCount, DimensionCount>
|
||||
{
|
||||
template
|
||||
<
|
||||
typename Box1, typename Box2,
|
||||
typename RobustPolicy,
|
||||
typename BoxOut,
|
||||
typename Strategy
|
||||
>
|
||||
static inline bool apply(Box1 const&, Box2 const&,
|
||||
RobustPolicy const&, BoxOut&, Strategy const&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}} // namespace detail::intersection
|
||||
#endif // DOXYGEN_NO_DETAIL
|
||||
|
||||
|
||||
|
||||
#ifndef DOXYGEN_NO_DISPATCH
|
||||
namespace dispatch
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
|
||||
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
|
||||
|
||||
#include <boost/geometry/algorithms/intersection.hpp>
|
||||
#include <boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp>
|
||||
#include <boost/geometry/strategies/intersection.hpp>
|
||||
#include <boost/geometry/index/detail/algorithms/content.hpp>
|
||||
|
||||
namespace boost { namespace geometry { namespace index { namespace detail {
|
||||
@@ -25,7 +26,12 @@ inline typename default_content_result<Box>::type intersection_content(Box const
|
||||
if ( geometry::intersects(box1, box2) )
|
||||
{
|
||||
Box box_intersection;
|
||||
geometry::intersection(box1, box2, box_intersection);
|
||||
|
||||
strategy_intersection_empty dummy;
|
||||
geometry::detail::intersection::intersection_box_box
|
||||
<
|
||||
0, geometry::dimension<Box>::value
|
||||
>::apply(box1, box2, box_intersection, dummy);
|
||||
return detail::content(box_intersection);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
#include <boost/geometry/policies/robustness/segment_ratio.hpp>
|
||||
#include <boost/geometry/policies/robustness/segment_ratio_type.hpp>
|
||||
#include <boost/geometry/policies/robustness/robust_point_type.hpp>
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ public:
|
||||
typedef RobustPolicy rescale_policy_type;
|
||||
};
|
||||
|
||||
|
||||
// Version for box_box intersection or other detail calls not needing a strategy
|
||||
struct strategy_intersection_empty {};
|
||||
|
||||
|
||||
}} // namespace boost::geometry
|
||||
|
||||
@@ -47,6 +47,7 @@ test-suite boost-geometry-algorithms
|
||||
[ run intersects.cpp : : : <toolset>msvc:<cxxflags>/bigobj ]
|
||||
[ run length.cpp ]
|
||||
[ run make.cpp ]
|
||||
[ run num_points.cpp ]
|
||||
[ run overlaps.cpp ]
|
||||
[ run perimeter.cpp ]
|
||||
[ run point_on_surface.cpp ]
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
// Unit Tests
|
||||
|
||||
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013-2014 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_TEST_FROM_WKT_HPP
|
||||
#define BOOST_GEOMETRY_TEST_FROM_WKT_HPP
|
||||
|
||||
#include <boost/geometry/io/wkt/read.hpp>
|
||||
#include <boost/geometry/multi/io/wkt/read.hpp>
|
||||
|
||||
template <typename Geometry>
|
||||
Geometry from_wkt(std::string const& wkt)
|
||||
inline Geometry from_wkt(std::string const& wkt)
|
||||
{
|
||||
Geometry res;
|
||||
boost::geometry::read_wkt(wkt, res);
|
||||
return res;
|
||||
Geometry result;
|
||||
boost::geometry::read_wkt(wkt, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // BOOST_GEOMETRY_TEST_FROM_WKT_HPP
|
||||
|
||||
65
test/algorithms/num_points.cpp
Normal file
65
test/algorithms/num_points.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
// Unit Test
|
||||
|
||||
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2013-2014 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_TEST_MODULE
|
||||
#define BOOST_TEST_MODULE test_num_points
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/num_points.hpp>
|
||||
#include <boost/geometry/multi/algorithms/num_points.hpp>
|
||||
#include <boost/geometry/geometries/geometries.hpp>
|
||||
#include <boost/geometry/multi/geometries/multi_geometries.hpp>
|
||||
|
||||
#include <boost/geometry/io/wkt/read.hpp>
|
||||
#include <boost/geometry/multi/io/wkt/read.hpp>
|
||||
|
||||
template <typename Geometry>
|
||||
inline void test_num_points(std::string const& wkt, std::size_t expected)
|
||||
{
|
||||
namespace bg = boost::geometry;
|
||||
Geometry geometry;
|
||||
boost::geometry::read_wkt(wkt, geometry);
|
||||
std::size_t detected = bg::num_points(geometry);
|
||||
BOOST_CHECK_EQUAL(expected, detected);
|
||||
detected = bg::num_points(geometry, false);
|
||||
BOOST_CHECK_EQUAL(expected, detected);
|
||||
detected = bg::num_points(geometry, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_num_points_closed )
|
||||
{
|
||||
namespace bg = boost::geometry;
|
||||
typedef bg::model::point<double,2,bg::cs::cartesian> point;
|
||||
typedef bg::model::linestring<point> linestring;
|
||||
typedef bg::model::segment<point> segment;
|
||||
typedef bg::model::box<point> box;
|
||||
typedef bg::model::ring<point> ring;
|
||||
typedef bg::model::polygon<point> polygon;
|
||||
typedef bg::model::multi_point<point> multi_point;
|
||||
typedef bg::model::multi_linestring<linestring> multi_linestring;
|
||||
typedef bg::model::multi_polygon<polygon> multi_polygon;
|
||||
|
||||
test_num_points<point>("POINT(0 0)", 1u);
|
||||
test_num_points<linestring>("LINESTRING(0 0,1 1)", 2u);
|
||||
test_num_points<segment>("LINESTRING(0 0,1 1)", 2u);
|
||||
test_num_points<box>("POLYGON((0 0,10 10))", 4u);
|
||||
test_num_points<ring>("POLYGON((0 0,1 1,0 1,0 0))", 4u);
|
||||
test_num_points<polygon>("POLYGON((0 0,10 10,0 10,0 0))", 4u);
|
||||
test_num_points<polygon>("POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))", 10u);
|
||||
test_num_points<multi_point>("MULTIPOINT((0 0),(1 1))", 2u);
|
||||
test_num_points<multi_linestring>("MULTILINESTRING((0 0,1 1),(2 2,3 3,4 4))", 5u);
|
||||
test_num_points<multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 9u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user