// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test Helper
-// Copyright (c) 2010-2015 Barend Gehrels, Amsterdam, the Netherlands.
+// Copyright (c) 2010-2019 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2016-2017.
// Modifications copyright (c) 2016-2017, Oracle and/or its affiliates.
#include <iomanip>
#include <boost/foreach.hpp>
-#include <geometry_test_common.hpp>
+#include "geometry_test_common.hpp"
#include <boost/geometry/algorithms/envelope.hpp>
#include <boost/geometry/algorithms/area.hpp>
const double same_distance = -999;
#if defined(TEST_WITH_SVG)
-# include <test_buffer_svg.hpp>
-# include <test_buffer_svg_per_turn.hpp>
+# include "test_buffer_svg.hpp"
+# include "test_buffer_svg_per_turn.hpp"
#endif
//-----------------------------------------------------------------------------
double tolerance;
bool test_validity;
bool test_area;
+ bool use_ln_area;
+ int points_per_circle;
- explicit ut_settings(double tol = 0.01, bool val = true)
+ explicit ut_settings(double tol = 0.01, bool val = true, int points = 88)
: tolerance(tol)
, test_validity(val)
, test_area(true)
+ , use_ln_area(false)
+ , points_per_circle(points)
{}
static inline ut_settings ignore_validity()
typename DistanceStrategy,
typename SideStrategy,
typename PointStrategy,
+ typename AreaStrategy,
typename Geometry
>
-void test_buffer(std::string const& caseid, Geometry const& geometry,
+void test_buffer(std::string const& caseid,
+ bg::model::multi_polygon<GeometryOut>& buffered,
+ Geometry const& geometry,
JoinStrategy const& join_strategy,
EndStrategy const& end_strategy,
DistanceStrategy const& distance_strategy,
SideStrategy const& side_strategy,
PointStrategy const& point_strategy,
+ AreaStrategy const& area_strategy,
int expected_count,
int expected_holes_count,
double expected_area,
<< (end_name.empty() ? "" : "_") << end_name
<< (distance_strategy.negative() ? "_deflate" : "")
<< (bg::point_order<GeometryOut>::value == bg::counterclockwise ? "_ccw" : "")
+#if defined(BOOST_GEOMETRY_USE_RESCALING)
+ << "_rescaled"
+#endif
// << "_" << point_buffer_count
;
<
typename bg::cs_tag<Geometry>::type
>::type strategy_type;
+ typedef typename strategy_type::envelope_strategy_type envelope_strategy_type;
// Enlarge the box to get a proper rescale policy
bg::buffer(envelope, envelope, distance_strategy.max_distance(join_strategy, end_strategy));
rescale_policy_type rescale_policy
= bg::get_rescale_policy<rescale_policy_type>(envelope);
- bg::model::multi_polygon<GeometryOut> buffered;
+ envelope_strategy_type envelope_strategy;
+ buffered.clear();
bg::detail::buffer::buffer_inserter<GeometryOut>(geometry,
std::back_inserter(buffered),
distance_strategy,
bg::model::box<point_type> envelope_output;
bg::assign_values(envelope_output, 0, 0, 1, 1);
- bg::envelope(buffered, envelope_output);
+ bg::envelope(buffered, envelope_output, envelope_strategy);
// std::cout << caseid << std::endl;
// std::cout << "INPUT: " << bg::wkt(geometry) << std::endl;
if (settings.test_area)
{
- typename bg::default_area_result<GeometryOut>::type area = bg::area(buffered);
- double const difference = area - expected_area;
+ // Because areas vary hugely in buffer, the Boost.Test methods are not convenient.
+ // Use just the abs - but if areas are really small that is not convenient neither.
+ // Therefore there is a logarithmic option too.
+ typename bg::default_area_result<GeometryOut>::type area = bg::area(buffered, area_strategy);
+ double const difference = settings.use_ln_area
+ ? std::log(area) - std::log(expected_area)
+ : area - expected_area;
BOOST_CHECK_MESSAGE
(
bg::math::abs(difference) < settings.tolerance,
<< std::setprecision(3)
<< " , " << 100.0 * (difference / expected_area) << "%"
);
+// if (settings.use_ln_area)
+// {
+// std::cout << complete.str()
+// << std::setprecision(6)
+// << " ln(detected)=" << std::log(area)
+// << " ln(expected)=" << std::log(expected_area)
+// << " diff=" << difference
+// << " detected=" << area
+// << std::endl;
+// }
}
- if (settings.test_validity && ! bg::is_valid(buffered))
+#if ! defined(BOOST_GEOMETRY_TEST_ALWAYS_CHECK_VALIDITY)
+ if (settings.test_validity)
+#endif
{
- BOOST_CHECK_MESSAGE(bg::is_valid(buffered), complete.str() << " is not valid");
+ if (! bg::is_valid(buffered))
+ {
+ BOOST_CHECK_MESSAGE(bg::is_valid(buffered), complete.str() << " is not valid");
+ }
}
#if defined(TEST_WITH_SVG_PER_TURN)
typename PointStrategy,
typename Geometry
>
-void test_buffer(std::string const& caseid, Geometry const& geometry,
+void test_buffer(std::string const& caseid, bg::model::multi_polygon<GeometryOut>& buffered, Geometry const& geometry,
JoinStrategy const& join_strategy,
EndStrategy const& end_strategy,
DistanceStrategy const& distance_strategy,
double expected_area,
ut_settings const& settings = ut_settings())
{
- test_buffer<GeometryOut>(caseid, geometry,
+ typename bg::strategy::area::services::default_strategy
+ <
+ typename bg::cs_tag<Geometry>::type
+ >::type area_strategy;
+
+ test_buffer<GeometryOut>(caseid, buffered, geometry,
join_strategy, end_strategy, distance_strategy, side_strategy, point_strategy,
+ area_strategy,
-1, -1, expected_area, settings);
}
bg::read_wkt(wkt, g);
bg::correct(g);
-
#ifdef BOOST_GEOMETRY_CHECK_WITH_POSTGIS
std::cout
<< (counter > 0 ? "union " : "")
bg::strategy::buffer::side_straight side_strategy;
- bg::strategy::buffer::point_circle circle_strategy(88);
+ bg::strategy::buffer::point_circle circle_strategy(settings.points_per_circle);
bg::strategy::buffer::distance_asymmetric
<
bg::math::equals(distance_right, same_distance)
? distance_left : distance_right);
+ typename bg::strategy::area::services::default_strategy
+ <
+ typename bg::cs_tag<Geometry>::type
+ >::type area_strategy;
+
+ bg::model::multi_polygon<GeometryOut> buffered;
test_buffer<GeometryOut>
- (caseid, g,
+ (caseid, buffered, g,
join_strategy, end_strategy,
distance_strategy, side_strategy, circle_strategy,
+ area_strategy,
expected_count, expected_holes_count, expected_area,
settings);
> sym_distance_strategy(distance_left);
test_buffer<GeometryOut>
- (caseid + "_sym", g,
+ (caseid + "_sym", buffered, g,
join_strategy, end_strategy,
sym_distance_strategy, side_strategy, circle_strategy,
+ area_strategy,
expected_count, expected_holes_count, expected_area,
settings);
bg::read_wkt(wkt, g);
bg::correct(g);
+ bg::model::multi_polygon<GeometryOut> buffered;
+
test_buffer<GeometryOut>
- (caseid, g,
+ (caseid, buffered, g,
join_strategy, end_strategy,
distance_strategy, side_strategy, point_strategy,
expected_area, settings);