Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically generated, fast floating-point predicates #739

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/example/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ project boost-geometry-examples-extensions
;

build-project gis ;
build-project generic_robust_predicates ;
12 changes: 12 additions & 0 deletions extensions/example/generic_robust_predicates/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Boost.Geometry (aka GGL, Generic Geometry Library)

# 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)


project boost-geometry-example-extensions-generic_robust_predicates
:
;

exe static_side_2d : static_side_2d.cpp ;
79 changes: 79 additions & 0 deletions extensions/example/generic_robust_predicates/static_side_2d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2020 Tinko Bartels, Berlin, Germany.

// Contributed and/or modified by Tinko Bartels,
// as part of Google Summer of Code 2020 program.

// 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)


#define BOOST_GEOMETRY_NO_BOOST_TEST

#include <iostream>

#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>

#include <boost/geometry/extensions/triangulation/strategies/cartesian/side_robust.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expressions.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/stage_a.hpp>


namespace bg = boost::geometry;
using point = bg::model::point<double, 2, bg::cs::cartesian>;

template <typename CalculationType>
struct side_robust_with_static_filter
{
private:
using ct = CalculationType;
using expression = bg::detail::generic_robust_predicates::orient2d;
using filter = bg::detail::generic_robust_predicates::stage_a_static
<
expression,
ct
>;
filter m_filter;
public:
side_robust_with_static_filter(ct x_max, ct y_max, ct x_min, ct y_min)
: m_filter(x_max, y_max, x_max, y_max, x_max, y_max,
x_min, y_min, x_min, y_min, x_min, y_min) {};

template
<
typename P1,
typename P2,
typename P
>
inline int apply(P1 const& p1, P2 const& p2, P const& p) const
{
int sign = m_filter.apply(bg::get<0>(p1),
bg::get<1>(p1),
bg::get<0>(p2),
bg::get<1>(p2),
bg::get<0>(p),
bg::get<1>(p));
if (sign != bg::detail::generic_robust_predicates::sign_uncertain)
{
return sign;
}
else
{
//fallback if filter fails.
return bg::strategy::side::side_robust<double>::apply(p1, p2, p);
}
}
};

int main()
{
point p1(0.0, 0.0);
point p2(1.0, 1.0);
point p (0.0, 1.0);
side_robust_with_static_filter<double> static_strategy(2.0, 2.0, 1.0, 1.0);
std::cout << "Side value: " << static_strategy.apply(p1, p2, p) << "\n";
return 0;
}
1 change: 1 addition & 0 deletions extensions/test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ build-project gis ;
build-project iterators ;
build-project nsphere ;
build-project triangulation ;
build-project generic_robust_predicates ;
13 changes: 13 additions & 0 deletions extensions/test/generic_robust_predicates/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Boost.Geometry (aka GGL, Generic Geometry Library)
#
# 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)

test-suite boost-geometry-extensions-generic_robust_predicates
:
[ run expression_eval.cpp ]
[ run side3d.cpp ]
[ run staged.cpp ]
;

62 changes: 62 additions & 0 deletions extensions/test/generic_robust_predicates/expression_eval.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2020 Tinko Bartels, Berlin, Germany.

// Contributed and/or modified by Tinko Bartels,
// as part of Google Summer of Code 2020 program.

// 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 <array>

#include <geometry_test_common.hpp>

#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expression_tree.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expression_eval.hpp>

template <typename CalculationType>
void test_all()
{
using bg::detail::generic_robust_predicates::_1;
using bg::detail::generic_robust_predicates::_2;
using bg::detail::generic_robust_predicates::_3;
using bg::detail::generic_robust_predicates::_4;
using bg::detail::generic_robust_predicates::sum;
using bg::detail::generic_robust_predicates::difference;
using bg::detail::generic_robust_predicates::product;
using bg::detail::generic_robust_predicates::max;
using bg::detail::generic_robust_predicates::abs;
using bg::detail::generic_robust_predicates::post_order;
using bg::detail::generic_robust_predicates::evaluate_expression;
using bg::detail::generic_robust_predicates::evaluate_expressions;
using ct = CalculationType;
ct r1 = evaluate_expression<sum<_1, _2>>(
std::array<ct, 2>{1.0, 2.0});
BOOST_CHECK_EQUAL(3.0, r1);
ct r2 = evaluate_expression<max<abs<_1>, abs<_2>>>(
std::array<ct, 2>{-10.0, 2.0});
BOOST_CHECK_EQUAL(10.0, r2);

using expression = product
<
difference<_1, _2>,
difference<_3, _4>
>;
using evals = post_order<expression>;
std::array<ct, boost::mp11::mp_size<evals>::value> r;
std::array<ct, 4> input {5.0, 3.0, 2.0, 8.0};
evaluate_expressions(input, r, evals{});
BOOST_CHECK_EQUAL(2.0, r[0]);
BOOST_CHECK_EQUAL(-6.0, r[1]);
BOOST_CHECK_EQUAL(-12.0, r[2]);
}


int test_main(int, char* [])
{
test_all<double>();
return 0;
}
76 changes: 76 additions & 0 deletions extensions/test/generic_robust_predicates/side3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2020 Tinko Bartels, Berlin, Germany.

// Contributed and/or modified by Tinko Bartels,
// as part of Google Summer of Code 2020 program.

// 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 <array>

#include <geometry_test_common.hpp>

#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expressions.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/stage_a.hpp>

template <typename CalculationType>
void test_all()
{
using bg::detail::generic_robust_predicates::orient3d;
using bg::detail::generic_robust_predicates::stage_a_semi_static;
using bg::detail::generic_robust_predicates::stage_a_almost_static;
using bg::detail::generic_robust_predicates::stage_a_static;
using ct = CalculationType;
using semi_static = stage_a_semi_static<orient3d, ct>;
BOOST_CHECK_EQUAL(1,
semi_static::apply(1, 0, 0,
0, 1, 0,
1, 1, 0,
0, 0, 1));
BOOST_CHECK_EQUAL(-1,
semi_static::apply(1, 0, 0,
0, 1, 0,
1, 1, 0,
0, 0, -1));
BOOST_CHECK_EQUAL(0,
semi_static::apply(1, 0, 0,
0, 1, 0,
1, 1, 0,
0, 0, 0));
stage_a_static<orient3d, ct> stat(10, 10, 10,
10, 10, 10,
10, 10, 10,
10, 10, 10,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0);
BOOST_CHECK_EQUAL(1, stat.apply(1, 0, 0,
0, 1, 0,
1, 1, 0,
0, 0, 1));

stage_a_static<orient3d, ct> pessimistic(1e40, 1e40, 1e40,
1e40, 1e40, 1e40,
1e40, 1e40, 1e40,
1e40, 1e40, 1e40,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0);
BOOST_CHECK_EQUAL(bg::detail::generic_robust_predicates::sign_uncertain,
pessimistic.apply(1, 0, 0,
0, 1, 0,
1, 1, 0,
0, 0, 1));
}

int test_main(int, char* [])
{
test_all<double>();
return 0;
}
43 changes: 43 additions & 0 deletions extensions/test/generic_robust_predicates/staged.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test

// Copyright (c) 2020 Tinko Bartels, Berlin, Germany.

// Contributed and/or modified by Tinko Bartels,
// as part of Google Summer of Code 2020 program.

// 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 <geometry_test_common.hpp>

#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expressions.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/stage_a.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/stage_d.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/stage_b.hpp>
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/staged_predicate.hpp>

using namespace boost::geometry::detail::generic_robust_predicates;

template <typename CalculationType>
void test_all()
{
using ct = CalculationType;
using expression = orient2d;
using filter1 = stage_a_static<expression, ct>;
using filter2 = stage_a_almost_static<expression, ct>;
using filter3 = stage_a_semi_static<expression, ct>;
using filter4 = stage_b<expression, ct>;
using filter5 = stage_d<expression, ct>;
using staged = staged_predicate<ct, filter1, filter2, filter3, filter4, filter5>;
staged s(1e20, 1e20, 1e20, 1e20, 1e20, 1e20, 0., 0., 0., 0., 0., 0.);
s.update(1e20, 1e20, 1e20, 1e20, 1e20, 1e20, 0., 0., 0., 0., 0., 0.);
BOOST_CHECK_EQUAL(1, s.apply(1e-20, 1e-20, 1, 1-1e-10, 1e20, 1e20));
}

int test_main(int, char* [])
{
test_all<double>();
return 0;
}
Loading