Skip to content

Commit 9c51a62

Browse files
committed
Style fixes, removal of unused parameters and addition of some explanations in comments.
1 parent c773353 commit 9c51a62

File tree

11 files changed

+163
-33
lines changed

11 files changed

+163
-33
lines changed

extensions/example/generic_robust_predicates/static_side_2d.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct side_robust_with_static_filter
5656
bg::get<1>(p2),
5757
bg::get<0>(p),
5858
bg::get<1>(p));
59-
if(sign != bg::detail::generic_robust_predicates::sign_uncertain)
59+
if (sign != bg::detail::generic_robust_predicates::sign_uncertain)
6060
{
6161
return sign;
6262
}
@@ -68,7 +68,7 @@ struct side_robust_with_static_filter
6868
}
6969
};
7070

71-
int main(int argc, char** argv)
71+
int main()
7272
{
7373
point p1(0.0, 0.0);
7474
point p2(1.0, 1.0);

include/boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/almost_static_filter.hpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ template <typename Filter, std::size_t N, std::size_t End>
2828
struct make_filter_impl
2929
{
3030
template <typename ExtremaArray, typename ...Reals>
31-
static Filter apply(const ExtremaArray& extrema, const Reals&... args)
31+
static Filter apply(ExtremaArray const& extrema, Reals const&... args)
3232
{
3333
return make_filter_impl<Filter, N + 1, End>
3434
::apply(extrema, args..., extrema[N]);
@@ -39,13 +39,27 @@ template <typename Filter, std::size_t End>
3939
struct make_filter_impl<Filter, End, End>
4040
{
4141
template <typename ExtremaArray, typename ...Reals>
42-
static Filter apply(const ExtremaArray& extrema, const Reals&... args)
42+
static Filter apply(ExtremaArray const& extrema, Reals const&... args)
4343
{
4444
Filter f(args...);
4545
return f;
4646
}
4747
};
4848

49+
//The almost static filter holds an instance of a static filter and applies it
50+
//when it is called. Its static filter can be updated and applied like this:
51+
//
52+
//almost_static_filter<...> f;
53+
//
54+
//f.update(max1, max2, ..., min1, min2, ...);
55+
//
56+
//f.apply(arg1, arg2, ...);
57+
//
58+
//Unlike with the static filter, global bounds do not need to be known at
59+
//construction time and with incremental algorithms where inputs with higher
60+
//magnitude are added later, the earlier applications of the filter may benefit
61+
//from more optimistic error bounds.
62+
4963
template
5064
<
5165
typename Expression,
@@ -72,13 +86,13 @@ class almost_static_filter
7286
std::numeric_limits<ct>::infinity());
7387
}
7488
template <typename ...Reals>
75-
int apply(const Reals&... args) const
89+
int apply(Reals const&... args) const
7690
{
7791
return m_filter.apply(args...);
7892
}
7993

8094
template <typename ...Reals>
81-
inline void update_extrema(const Reals&... args)
95+
inline void update_extrema(Reals const&... args)
8296
{
8397
std::array<ct, sizeof...(Reals)> input {{ static_cast<ct>(args)... }};
8498
for(int i = 0; i < m_extrema.size() / 2; ++i)
@@ -92,7 +106,7 @@ class almost_static_filter
92106
}
93107

94108
template <typename ...Reals>
95-
inline bool update_extrema_check(const Reals&... args)
109+
inline bool update_extrema_check(Reals const&... args)
96110
{
97111
bool changed = false;
98112
std::array<ct, sizeof...(Reals)> input {{ static_cast<ct>(args)... }};

include/boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/approximate.hpp

+29-18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace boost { namespace geometry
2828
namespace detail { namespace generic_robust_predicates
2929
{
3030

31+
//The templates in this file are meant to be used for the evaluation of
32+
//expressions with floating-point precision and floating-point rounding.
33+
//The most important template in this file is approximate_interim.
34+
3135
template
3236
<
3337
typename Node,
@@ -37,7 +41,7 @@ template
3741
>
3842
struct get_nth_real_impl
3943
{
40-
static inline Real apply(const InputArr& input)
44+
static inline Real apply(InputArr const& input)
4145
{
4246
return input[N - 1];
4347
}
@@ -51,7 +55,7 @@ template
5155
>
5256
struct get_nth_real_impl<Node, 0, Real, InputArr>
5357
{
54-
static inline Real apply(const InputArr&)
58+
static inline Real apply(InputArr const&)
5559
{
5660
return Node::value;
5761
}
@@ -64,7 +68,7 @@ template
6468
typename Real,
6569
typename InputArr
6670
>
67-
inline Real get_nth_real(const InputArr& input)
71+
inline Real get_nth_real(InputArr const& input)
6872
{
6973
return get_nth_real_impl<Node, Node::argn, Real, InputArr>::apply(input);
7074
}
@@ -80,7 +84,7 @@ template
8084
>
8185
struct get_approx_impl
8286
{
83-
static inline Real apply(Arr& interim_results, const InputArr& input)
87+
static inline Real apply(Arr& interim_results, InputArr const&)
8488
{
8589
return interim_results[boost::mp11::mp_find<All, Node>::value];
8690
}
@@ -96,7 +100,7 @@ template
96100
>
97101
struct get_approx_impl<All, Node, Real, Arr, true, InputArr>
98102
{
99-
static inline Real apply(Arr& interim_results, const InputArr& input)
103+
static inline Real apply(Arr&, InputArr const& input)
100104
{
101105
return get_nth_real<Node, Node::argn, Real, InputArr>(input);
102106
}
@@ -110,7 +114,7 @@ template
110114
typename Arr,
111115
typename InputArr
112116
>
113-
inline Real get_approx(Arr& interim_results, const InputArr& input)
117+
inline Real get_approx(Arr& interim_results, InputArr const& input)
114118
{
115119
return get_approx_impl
116120
<
@@ -145,7 +149,7 @@ template
145149
>
146150
struct approximate_remainder_impl
147151
{
148-
static inline void apply(Arr& interim_results, const InputArr& input)
152+
static inline void apply(Arr& interim_results, InputArr const& input)
149153
{
150154
using node = boost::mp11::mp_front<Remaining>;
151155
approximate_interim_impl
@@ -178,7 +182,7 @@ struct approximate_remainder_impl
178182
InputArr
179183
>
180184
{
181-
static inline void apply(Arr& interim_results, const InputArr& input) {}
185+
static inline void apply(Arr&, InputArr const&) {}
182186
};
183187

184188
template
@@ -189,7 +193,7 @@ template
189193
typename Arr,
190194
typename InputArr
191195
>
192-
inline void approximate_remainder(Arr& interim_results, const InputArr& input)
196+
inline void approximate_remainder(Arr& interim_results, InputArr const& input)
193197
{
194198
approximate_remainder_impl
195199
<
@@ -220,7 +224,7 @@ struct approximate_interim_impl
220224
InputArr
221225
>
222226
{
223-
static inline void apply(Arr& interim_results, const InputArr& input)
227+
static inline void apply(Arr& interim_results, InputArr const& input)
224228
{
225229
using node = boost::mp11::mp_front<Remaining>;
226230
interim_results[boost::mp11::mp_find<All, node>::value] =
@@ -255,7 +259,7 @@ struct approximate_interim_impl
255259
InputArr
256260
>
257261
{
258-
static inline void apply(Arr& interim_results, const InputArr& input)
262+
static inline void apply(Arr& interim_results, InputArr const& input)
259263
{
260264
using node = boost::mp11::mp_front<Remaining>;
261265
interim_results[boost::mp11::mp_find<All, node>::value] = std::max(
@@ -290,7 +294,7 @@ struct approximate_interim_impl
290294
InputArr
291295
>
292296
{
293-
static inline void apply(Arr& interim_results, const InputArr& input)
297+
static inline void apply(Arr& interim_results, InputArr const& input)
294298
{
295299
using node = boost::mp11::mp_front<Remaining>;
296300
interim_results[boost::mp11::mp_find<All, node>::value] = std::min(
@@ -325,7 +329,7 @@ struct approximate_interim_impl
325329
InputArr
326330
>
327331
{
328-
static inline void apply(Arr& interim_results, const InputArr& input)
332+
static inline void apply(Arr& interim_results, InputArr const& input)
329333
{
330334
using node = boost::mp11::mp_front<Remaining>;
331335
interim_results[boost::mp11::mp_find<All, node>::value] =
@@ -360,7 +364,7 @@ struct approximate_interim_impl
360364
InputArr
361365
>
362366
{
363-
static inline void apply(Arr& interim_results, const InputArr& input)
367+
static inline void apply(Arr& interim_results, InputArr const& input)
364368
{
365369
using node = boost::mp11::mp_front<Remaining>;
366370
interim_results[boost::mp11::mp_find<All, node>::value] =
@@ -395,7 +399,7 @@ struct approximate_interim_impl
395399
InputArr
396400
>
397401
{
398-
static inline void apply(Arr& interim_results, const InputArr& input)
402+
static inline void apply(Arr& interim_results, InputArr const& input)
399403
{
400404
using node = boost::mp11::mp_front<Remaining>;
401405
interim_results[boost::mp11::mp_find<All, node>::value] =
@@ -432,7 +436,7 @@ struct approximate_interim_impl
432436
InputArr
433437
>
434438
{
435-
static inline void apply(Arr& interim_results, const InputArr& input)
439+
static inline void apply(Arr& interim_results, InputArr const& input)
436440
{
437441
approximate_remainder
438442
<
@@ -443,6 +447,13 @@ struct approximate_interim_impl
443447
}
444448
};
445449

450+
//All expects an boost::mp11::mp_list of all expressions that need to be
451+
//evaluated. Remaining expects an boost::mp11::mp_list of the expressions
452+
//that are left to be evaluated. In the first call it is expected to be
453+
//equal to All and it serves as an anchor for template recursion. Real is a
454+
//floating-point type. The remaining template arguments are deduced from
455+
//parameters.
456+
446457
template
447458
<
448459
typename All,
@@ -451,7 +462,7 @@ template
451462
typename Arr,
452463
typename InputArr
453464
>
454-
inline void approximate_interim(Arr& interim_results, const InputArr& input)
465+
inline void approximate_interim(Arr& interim_results, InputArr const& input)
455466
{
456467
approximate_remainder
457468
<
@@ -462,7 +473,7 @@ inline void approximate_interim(Arr& interim_results, const InputArr& input)
462473
}
463474

464475
template<typename Expression, typename Real, typename InputArr>
465-
inline Real approximate_value(const InputArr& input)
476+
inline Real approximate_value(InputArr const& input)
466477
{
467478
using stack = typename boost::mp11::mp_unique<post_order<Expression>>;
468479
using evals = typename boost::mp11::mp_remove_if<stack, is_leaf>;

include/boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/coefficient_list.hpp

+32
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ namespace boost { namespace geometry
2525
namespace detail { namespace generic_robust_predicates
2626
{
2727

28+
//The templates in this file are helpers for the computation of error maps and
29+
//error expressions (see also error_bound.hpp). A coefficient list is a
30+
//boost::mp11::mp_list that contains integers that represent the coefficients
31+
//of an polynomial. This is used for the polynomials in epsilon that occur in
32+
//forward error analysis, e.g. epsilon + 2 * epsilon^2 + epsilon^3 would be
33+
//represented by the type mp_list<mp_int<1>, mp_int<2>, mp_int<1>>.
34+
//
35+
//See p. 39 in "Adaptive Precision Floating-Point Arithmetic and Fast Robust
36+
//Geometric Predicates" by Jonathan Richard Shewchuk (can be downloaded from
37+
//https://www.cs.cmu.edu/~quake/robust.html) for the inspiration for the
38+
//methods implemented below.
39+
2840
//only meant to be used in assertions
2941
template <typename T> using is_mp_int =
3042
boost::mp11::mp_same<T, boost::mp11::mp_int<T::value>>;
@@ -68,12 +80,21 @@ struct coeff_truncate_impl
6880
static_assert(is_coeff_list<L>::value, "type should be a coefficient list");
6981
};
7082

83+
//Because of the way floating-point numbers are rounded, for a given epsilon
84+
//polynomial we only care about the first two non-zero coefficients.
85+
//e.g. if a*eps + b*eps^2 + c*eps^3 is considered then c * eps^3 is always
86+
//neglible unless c is so large that it must have resulted from the analysis
87+
//of an expression that is so complex that it cannot be feasibly processed
88+
//by the methods implemented in this feature.
7189
template <typename L> using coeff_truncate = typename coeff_truncate_impl<L>::type;
7290

7391
template <typename L> using app_zero_b =
7492
boost::mp11::mp_push_front<L, boost::mp11::mp_int<0>>;
7593
template <typename L> using app_zero_f =
7694
boost::mp11::mp_push_back<L, boost::mp11::mp_int<0>>;
95+
96+
//For a coefficient list representing the polynomial p, the following template
97+
//produces the coefficient list representing p * (1 + eps).
7798
template <typename L> using mult_by_1_p_eps = coeff_truncate
7899
<
79100
boost::mp11::mp_transform
@@ -110,6 +131,9 @@ struct mult_by_1_p_eps_pow_impl<L, N, boost::mp11::mp_true>
110131
using type = L;
111132
};
112133

134+
135+
//For a coefficient list representing the polynomial p, the following template
136+
//produces the cofficient list representing p * (1 + eps)^N
113137
template <typename L, typename N> using mult_by_1_p_eps_pow = coeff_truncate
114138
<
115139
typename mult_by_1_p_eps_pow_impl<L, N>::type
@@ -123,6 +147,9 @@ template <typename L> using div_by_1_m_eps_helper =
123147
boost::mp11::mp_plus
124148
>;
125149

150+
//For a coefficient list representing a polynomial p in eps, the following
151+
//template computes a coefficient list representing a polynomial q such that
152+
//q * (1 - p) >= p.
126153
template <typename L> using div_by_1_m_eps = coeff_truncate
127154
<
128155
boost::mp11::mp_push_back
@@ -406,6 +433,11 @@ struct coeff_round_impl<L, 0> { using type = L; };
406433
template <typename L>
407434
struct coeff_round_impl<L, 1> { using type = L; };
408435

436+
//The following template rounds a coefficient list up such that the
437+
//corresponding polynomial evaluated for epsilon is a representable
438+
//floating-point number.
439+
//
440+
//e.g. 3 * eps + 12 * eps^2 + 1 * eps^3 is rounded to 3 * eps + 16 * eps^2
409441
template <typename L> using coeff_round = typename coeff_round_impl<L>::type;
410442

411443
template <typename IV1, typename IV2> using indexed_value_product =

include/boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/error_bound.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ namespace boost { namespace geometry
2626
namespace detail { namespace generic_robust_predicates
2727
{
2828

29+
//The templates in this file are utilities for the generation of error
30+
//expressions for given arithmetic expressions. This is done using forward
31+
//error analysis methods at compile time. This analysis produces an error map
32+
//that is folded into an error expression.
33+
//
34+
//An Error Map is a template fulfilling the boost::mp11 map concept. The keys K
35+
//are expressions (as in expression trees and the values V are lists of
36+
//integers. Each key-value pair represents the contribution of an error term to
37+
//the total error, i.e. the error expression is something like the sum of
38+
//abs<K> * (V[0] * epsilon + V[1] * epsilon^2 + ...)
39+
//
40+
//over all key-value pairs KV in the error map.
41+
//
42+
//See p. 39 in "Adaptive Precision Floating-Point Arithmetic and Fast Robust
43+
//Geometric Predicates" by Jonathan Richard Shewchuk (can be downloaded from
44+
//https://www.cs.cmu.edu/~quake/robust.html) for the inspiration for the
45+
//methods implemented below.
46+
2947
template <typename KV> using second_is_coeff_list =
3048
is_coeff_list< boost::mp11::mp_second<KV> >;
3149

include/boost/geometry/extensions/generic_robust_predicates/strategies/cartesian/detail/expression_tree.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ namespace boost { namespace geometry
2525
namespace detail { namespace generic_robust_predicates
2626
{
2727

28+
//The templates in this file are designed to represent arithmetic expressions
29+
//In the type system so that they can be processed at compile-time for the
30+
//automatic creation of floating-point filters.
31+
//
32+
//E.g. the arithmetic expression a * b + c can be represented by the type
33+
//
34+
//sum< product < argument<1>, argument<2> >, argument<3> >
35+
//
36+
//The arguments represent the input variables and are the leaves of the
37+
//expression tree (other possible leaves are constants). Because they represent
38+
//placeholders their indexing is one-based rather than zero-based, similar to
39+
//the placeholders for std::bind.
40+
2841
enum class operator_types {
2942
sum, difference, product, abs, no_op, max, min
3043
};
@@ -144,6 +157,12 @@ struct static_constant_interface : public leaf
144157
template <typename Node>
145158
using is_leaf = boost::mp11::mp_bool<Node::is_leaf>;
146159

160+
//post_order_impl and post_order are templates for compile-time traversion of
161+
//expression trees. The post_order traversal was chosen because it guarantees
162+
//that children (subexpressions) are evaluated before there parents as is
163+
//necessary for the evaluation of the arithmetic expressions that these
164+
//expression trees represent.
165+
147166
template
148167
<
149168
typename In,

0 commit comments

Comments
 (0)