Skip to content

Commit da4aed4

Browse files
committed
Add example for static filter usage.
1 parent 219875b commit da4aed4

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

extensions/example/Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ project boost-geometry-examples-extensions
1313
;
1414

1515
build-project gis ;
16+
build-project generic_robust_predicates ;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Boost.Geometry (aka GGL, Generic Geometry Library)
2+
3+
# Use, modification and distribution is subject to the Boost Software License,
4+
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5+
# http://www.boost.org/LICENSE_1_0.txt)
6+
7+
8+
project boost-geometry-example-extensions-generic_robust_predicates
9+
:
10+
;
11+
12+
exe static_side_2d : static_side_2d.cpp ;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Boost.Geometry (aka GGL, Generic Geometry Library)
2+
3+
// Copyright (c) 2020 Tinko Bartels, Berlin, Germany.
4+
5+
// Contributed and/or modified by Tinko Bartels,
6+
// as part of Google Summer of Code 2020 program.
7+
8+
// Use, modification and distribution is subject to the Boost Software License,
9+
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10+
// http://www.boost.org/LICENSE_1_0.txt)
11+
12+
13+
#define BOOST_GEOMETRY_NO_BOOST_TEST
14+
15+
#include <iostream>
16+
17+
#include <boost/geometry/core/cs.hpp>
18+
#include <boost/geometry/geometries/point.hpp>
19+
20+
#include <boost/geometry/extensions/triangulation/strategies/cartesian/side_robust.hpp>
21+
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expressions.hpp>
22+
#include <boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/stage_a.hpp>
23+
24+
25+
namespace bg = boost::geometry;
26+
using point = bg::model::point<double, 2, bg::cs::cartesian>;
27+
28+
template <typename CalculationType>
29+
struct side_robust_with_static_filter
30+
{
31+
private:
32+
using ct = CalculationType;
33+
using expression = bg::detail::generic_robust_predicates::orient2d;
34+
using filter = bg::detail::generic_robust_predicates::stage_a_static
35+
<
36+
expression,
37+
ct
38+
>;
39+
filter m_filter;
40+
public:
41+
side_robust_with_static_filter(ct x_max, ct y_max, ct x_min, ct y_min)
42+
: m_filter(x_max, y_max, x_max, y_max, x_max, y_max,
43+
x_min, y_min, x_min, y_min, x_min, y_min) {};
44+
45+
template
46+
<
47+
typename P1,
48+
typename P2,
49+
typename P
50+
>
51+
inline int apply(P1 const& p1, P2 const& p2, P const& p) const
52+
{
53+
int sign = m_filter.apply(bg::get<0>(p1),
54+
bg::get<1>(p1),
55+
bg::get<0>(p2),
56+
bg::get<1>(p2),
57+
bg::get<0>(p),
58+
bg::get<1>(p));
59+
if(sign != bg::detail::generic_robust_predicates::sign_uncertain)
60+
{
61+
return sign;
62+
}
63+
else
64+
{
65+
//fallback if filter fails.
66+
return bg::strategy::side::side_robust<double>::apply(p1, p2, p);
67+
}
68+
}
69+
};
70+
71+
int main(int argc, char** argv)
72+
{
73+
point p1(0.0, 0.0);
74+
point p2(1.0, 1.0);
75+
point p (0.0, 1.0);
76+
side_robust_with_static_filter<double> static_strategy(2.0, 2.0, 1.0, 1.0);
77+
std::cout << "Side value: " << static_strategy.apply(p1, p2, p) << "\n";
78+
return 0;
79+
}

0 commit comments

Comments
 (0)