// Copyright (c) 2010-2015 Barend Gehrels, Amsterdam, the Netherlands.
-// This file was modified by Oracle on 2016.
-// Modifications copyright (c) 2016, Oracle and/or its affiliates.
+// This file was modified by Oracle on 2016-2017.
+// Modifications copyright (c) 2016-2017, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
static std::string name() { return "flat"; }
};
-
-
-template <typename Geometry, typename RescalePolicy>
-std::size_t count_self_ips(Geometry const& geometry, RescalePolicy const& rescale_policy)
+struct ut_settings
{
- typedef typename bg::point_type<Geometry>::type point_type;
- typedef bg::detail::overlay::turn_info
- <
- point_type,
- typename bg::segment_ratio_type<point_type, RescalePolicy>::type
- > turn_info;
+ double tolerance;
+ bool test_validity;
+ bool test_area;
- std::vector<turn_info> turns;
+ explicit ut_settings(double tol = 0.01, bool val = true)
+ : tolerance(tol)
+ , test_validity(val)
+ , test_area(true)
+ {}
- bg::detail::self_get_turn_points::no_interrupt_policy policy;
- bg::self_turns
- <
- bg::detail::overlay::assign_null_policy
- >(geometry, rescale_policy, turns, policy);
+ static inline ut_settings ignore_validity()
+ {
+ ut_settings result;
+ result.test_validity = false;
+ return result;
+ }
- return turns.size();
-}
+ static inline ut_settings assertions_only()
+ {
+ ut_settings result;
+ result.test_validity = false;
+ result.test_area = false;
+ return result;
+ }
+
+ static inline double ignore_area() { return 9999.9; }
+};
template
<
DistanceStrategy const& distance_strategy,
SideStrategy const& side_strategy,
PointStrategy const& point_strategy,
- bool check_self_intersections,
int expected_count,
int expected_holes_count,
double expected_area,
- double tolerance,
- std::size_t* self_ip_count)
+ ut_settings const& settings)
{
namespace bg = boost::geometry;
typedef typename bg::point_type<Geometry>::type point_type;
typedef typename bg::rescale_policy_type<point_type>::type
rescale_policy_type;
+ typedef typename bg::strategy::intersection::services::default_strategy
+ <
+ typename bg::cs_tag<Geometry>::type
+ >::type strategy_type;
// Enlarge the box to get a proper rescale policy
bg::buffer(envelope, envelope, distance_strategy.max_distance(join_strategy, end_strategy));
+ strategy_type strategy;
rescale_policy_type rescale_policy
= bg::get_rescale_policy<rescale_policy_type>(envelope);
join_strategy,
end_strategy,
point_strategy,
+ strategy,
rescale_policy,
visitor);
buffer_mapper.map_input_output(mapper, geometry, buffered, distance_strategy.negative());
#endif
-
- typename bg::default_area_result<GeometryOut>::type area = bg::area(buffered);
-
//Uncomment to create simple CSV to compare/use in tests - adapt precision if necessary
//std::cout << complete.str() << "," << std::fixed << std::setprecision(0) << area << std::endl;
//return;
return;
}
- BOOST_CHECK_MESSAGE
- (
- ! bg::is_empty(buffered),
- complete.str() << " output is empty (unexpected)."
- );
+ if (settings.test_area)
+ {
+ BOOST_CHECK_MESSAGE
+ (
+ ! bg::is_empty(buffered),
+ complete.str() << " output is empty (unexpected)."
+ );
+ }
bg::model::box<point_type> envelope_output;
bg::assign_values(envelope_output, 0, 0, 1, 1);
bg::envelope(buffered, envelope_output);
- rescale_policy_type rescale_policy_output
- = bg::get_rescale_policy<rescale_policy_type>(envelope_output);
// std::cout << caseid << std::endl;
// std::cout << "INPUT: " << bg::wkt(geometry) << std::endl;
BOOST_CHECK_MESSAGE
(
int(nholes) == expected_holes_count,
- "#holes not as expected."
+ complete.str() << " #holes not as expected."
<< " Expected: " << expected_holes_count
<< " Detected: " << nholes
);
}
- if (expected_area > -0.1)
+ if (settings.test_area)
{
+ typename bg::default_area_result<GeometryOut>::type area = bg::area(buffered);
double const difference = area - expected_area;
BOOST_CHECK_MESSAGE
(
- bg::math::abs(difference) < tolerance,
+ bg::math::abs(difference) < settings.tolerance,
complete.str() << " not as expected. "
<< std::setprecision(18)
<< " Expected: " << expected_area
<< " Detected: " << area
<< " Diff: " << difference
+ << " Tol: " << settings.tolerance
<< std::setprecision(3)
<< " , " << 100.0 * (difference / expected_area) << "%"
);
-
- if (check_self_intersections)
- {
-
- try
- {
- bool has_self_ips = bg::detail::overlay::has_self_intersections(
- buffered, rescale_policy_output, false);
- // Be sure resulting polygon does not contain
- // self-intersections
- BOOST_CHECK_MESSAGE
- (
- ! has_self_ips,
- complete.str() << " output is self-intersecting. "
- );
- }
- catch(...)
- {
- BOOST_CHECK_MESSAGE
- (
- false,
- "Exception in checking self-intersections"
- );
- }
- }
}
-#ifdef BOOST_GEOMETRY_BUFFER_TEST_IS_VALID
- if (! bg::is_valid(buffered))
+ if (settings.test_validity && ! bg::is_valid(buffered))
{
- std::cout
- << "NOT VALID: " << complete.str() << std::endl
- << std::fixed << std::setprecision(16) << bg::wkt(buffered) << std::endl;
+ BOOST_CHECK_MESSAGE(bg::is_valid(buffered), complete.str() << " is not valid");
}
-// BOOST_CHECK_MESSAGE(bg::is_valid(buffered) == true, complete.str() << " is not valid");
-// BOOST_CHECK_MESSAGE(bg::intersects(buffered) == false, complete.str() << " intersects");
-#endif
#if defined(TEST_WITH_SVG_PER_TURN)
{
// self_ips NYI here
}
#elif defined(TEST_WITH_SVG)
- buffer_mapper.map_self_ips(mapper, buffered, rescale_policy_output);
+ rescale_policy_type rescale_policy_output
+ = bg::get_rescale_policy<rescale_policy_type>(envelope_output);
+ buffer_mapper.map_self_ips(mapper, buffered, strategy, rescale_policy_output);
#endif
- // Check for self-intersections
- if (self_ip_count != NULL)
- {
- std::size_t count = 0;
- if (bg::detail::overlay::has_self_intersections(buffered,
- rescale_policy_output, false))
- {
- count = count_self_ips(buffered, rescale_policy_output);
- }
-
- *self_ip_count += count;
- if (count > 0)
- {
- std::cout << complete.str() << " " << count << std::endl;
- }
- }
}
template
DistanceStrategy const& distance_strategy,
SideStrategy const& side_strategy,
PointStrategy const& point_strategy,
- bool check_self_intersections,
double expected_area,
- double tolerance,
- std::size_t* self_ip_count)
+ ut_settings const& settings = ut_settings())
{
test_buffer<GeometryOut>(caseid, geometry,
join_strategy, end_strategy, distance_strategy, side_strategy, point_strategy,
- check_self_intersections, -1, -1, expected_area, tolerance, self_ip_count);
+ -1, -1, expected_area, settings);
}
#ifdef BOOST_GEOMETRY_CHECK_WITH_POSTGIS
void test_one(std::string const& caseid, std::string const& wkt,
JoinStrategy const& join_strategy, EndStrategy const& end_strategy,
int expected_count, int expected_holes_count, double expected_area,
- double distance_left, double distance_right = same_distance,
- bool check_self_intersections = true,
- double tolerance = 0.01)
+ double distance_left, ut_settings const& settings = ut_settings(),
+ double distance_right = same_distance)
{
namespace bg = boost::geometry;
Geometry g;
(caseid, g,
join_strategy, end_strategy,
distance_strategy, side_strategy, circle_strategy,
- check_self_intersections,
expected_count, expected_holes_count, expected_area,
- tolerance, NULL);
+ settings);
#if !defined(BOOST_GEOMETRY_COMPILER_MODE_DEBUG) && defined(BOOST_GEOMETRY_COMPILER_MODE_RELEASE)
(caseid + "_sym", g,
join_strategy, end_strategy,
sym_distance_strategy, side_strategy, circle_strategy,
- check_self_intersections,
expected_count, expected_holes_count, expected_area,
- tolerance, NULL);
+ settings);
}
#endif
void test_one(std::string const& caseid, std::string const& wkt,
JoinStrategy const& join_strategy, EndStrategy const& end_strategy,
double expected_area,
- double distance_left, double distance_right = same_distance,
- bool check_self_intersections = true,
- double tolerance = 0.01)
+ double distance_left, ut_settings const& settings = ut_settings(),
+ double distance_right = same_distance)
{
test_one<Geometry, GeometryOut>(caseid, wkt, join_strategy, end_strategy,
-1 ,-1, expected_area,
- distance_left, distance_right, check_self_intersections, tolerance);
-}
-
-// Version (currently for the Aimes test) counting self-ip's instead of checking
-template
-<
- typename Geometry,
- typename GeometryOut,
- typename JoinStrategy,
- typename EndStrategy
->
-void test_one(std::string const& caseid, std::string const& wkt,
- JoinStrategy const& join_strategy, EndStrategy const& end_strategy,
- double expected_area,
- double distance_left, double distance_right,
- std::size_t& self_ip_count,
- double tolerance = 0.01)
-{
- namespace bg = boost::geometry;
- Geometry g;
- bg::read_wkt(wkt, g);
- bg::correct(g);
-
- bg::strategy::buffer::distance_asymmetric
- <
- typename bg::coordinate_type<Geometry>::type
- > distance_strategy(distance_left,
- bg::math::equals(distance_right, same_distance)
- ? distance_left : distance_right);
-
- bg::strategy::buffer::point_circle circle_strategy(88);
- bg::strategy::buffer::side_straight side_strategy;
- test_buffer<GeometryOut>(caseid, g,
- join_strategy, end_strategy,
- distance_strategy, side_strategy, circle_strategy,
- false, expected_area,
- tolerance, &self_ip_count);
+ distance_left, settings, distance_right);
}
template
SideStrategy const& side_strategy,
PointStrategy const& point_strategy,
double expected_area,
- double tolerance = 0.01)
+ ut_settings const& settings = ut_settings())
{
namespace bg = boost::geometry;
Geometry g;
(caseid, g,
join_strategy, end_strategy,
distance_strategy, side_strategy, point_strategy,
- true, expected_area, tolerance, NULL);
+ expected_area, settings);
}
-
-
#endif