NiHu  2.0
interval.hpp
Go to the documentation of this file.
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
27 #ifndef INTERVAL_HPP_INCLUDED
28 #define INTERVAL_HPP_INCLUDED
29 
30 #include "../core/global_definitions.hpp"
31 
32 #include "algorithm.hpp"
33 #include "integer.hpp"
34 #include "vector.hpp"
35 
36 #include <ratio>
37 #include <stdexcept>
38 
39 namespace tmp
40 {
41 
43 typedef std::giga ratio_infinite;
44 
56 template <class X, class Y>
58 {
60  typedef break_point type;
62  typedef X x;
64  typedef Y y;
65 
71  template<class scalar_t = double>
72  constexpr static scalar_t x_value(void)
73  {
74  return scalar_t(x::num)/scalar_t(x::den);
75  }
76 };
77 
78 
89 template <class Inter1, class Inter2>
91 {
97  template <class Iter, class Begin>
98  struct copy_cond
99  {
103  typedef typename tmp::deref<Iter>::type cur;
105  typedef typename std::integral_constant<
106  bool,
107  std::ratio_greater<
108  typename cur::x,
109  typename prev::x
110  >::type::value
111  &&
112  tmp::less<
113  typename cur::y,
114  typename prev::y
115  >::type::value
116  > type;
117  };
118 
124  template <class Begin>
125  struct copy_cond<Begin, Begin> : std::true_type {};
126 
128  template <class BP1, class BP2>
130  typename BP1::y,
131  typename BP2::y
132  > {};
133 
135  template <class BP1, class BP2>
136  struct compare_by_x_asc : std::ratio_less<
137  typename BP1::x,
138  typename BP2::x
139  > {};
140 
142  typedef typename tmp::bubble_sort<
146 
148  typedef typename tmp::bubble_sort<
149  half_sorted,
152 
154  typedef typename tmp::copy_if<
155  sorted,
157  typename tmp::empty<sorted>::type,
159  >,
162 };
163 
173 template <class interval>
174 int eval_interval(double r)
175 {
177  typedef typename tmp::deref<
179  >::type bp;
180  // compare radius with first x value
181  if (r < bp::x_value())
182  return bp::y::value;
183  else
184  return eval_interval<typename tmp::pop_front<interval>::type>(r);
185 }
186 
188 template <>
189 int eval_interval<tmp::vector<> >(double);
190 
191 } // end of namespace tmp
192 
193 #endif /* INTERVAL_HPP_INCLUDED */
194 
tmp::less
General declaration of the less oparation.
Definition: relation.hpp:41
tmp::break_point::x
X x
the x data
Definition: interval.hpp:62
tmp::deref
metafunction to dereference an iterator
Definition: sequence.hpp:114
tmp
template metaprogramming functions
Definition: asymptotic_types.hpp:101
tmp::merge_intervals::sorted
tmp::bubble_sort< half_sorted, compare_by_y_desc< tmp::_1, tmp::_2 > >::type sorted
sort by y descending
Definition: interval.hpp:151
tmp::bubble_sort
sort a sequence by bubble sort
Definition: algorithm.hpp:390
tmp::begin
return begin iterator of a sequence
Definition: sequence.hpp:79
tmp::copy_if
copy elements from a container into an other
Definition: algorithm.hpp:249
tmp::merge_intervals::type
tmp::copy_if< sorted, tmp::inserter< typename tmp::empty< sorted >::type, tmp::push_back< tmp::_1, tmp::_2 > >, copy_cond< tmp::_1, typename tmp::begin< sorted >::type > >::type type
zip using the copy condition
Definition: interval.hpp:161
integer.hpp
integer type representation and basic integer arithmetics
algorithm.hpp
vectoralgorithms
tmp::merge_intervals::copy_cond::cur
tmp::deref< Iter >::type cur
current element
Definition: interval.hpp:103
tmp::break_point::type
break_point type
Self-returning.
Definition: interval.hpp:60
tmp::empty
return empty sequence
Definition: sequence.hpp:64
tmp::merge_intervals::compare_by_x_asc
comparison condition to sort in ascending order by x
Definition: interval.hpp:136
tmp::merge_intervals::copy_cond
Copy condition when zipping an interval.
Definition: interval.hpp:98
tmp::ratio_infinite
std::giga ratio_infinite
define giga as the infinite as it fits into 32 bits
Definition: interval.hpp:43
tmp::concatenate
concatenate two sequences into a new sequence
Definition: algorithm.hpp:257
vector.hpp
implementation of a compile time vector tmp::vector
tmp::merge_intervals::compare_by_y_desc
comparison condition to sort in descending order by y
Definition: interval.hpp:129
tmp::merge_intervals
Merge two intervals.
Definition: interval.hpp:90
tmp::push_back
push an element to the back
Definition: sequence.hpp:99
tmp::break_point::y
Y y
the y data
Definition: interval.hpp:64
tmp::break_point::x_value
constexpr static scalar_t x_value(void)
Convert rational x value to scalar(double)
Definition: interval.hpp:72
tmp::eval_interval
int eval_interval(double r)
Evaluate an interval at a given distance.
Definition: interval.hpp:174
tmp::merge_intervals::copy_cond::prev
tmp::deref< typename tmp::prev< Iter >::type >::type prev
previous element
Definition: interval.hpp:101
tmp::merge_intervals::half_sorted
tmp::bubble_sort< typename tmp::concatenate< Inter1, Inter2 >::type, compare_by_x_asc< tmp::_1, tmp::_2 > >::type half_sorted
sort the concatenated intervals by x ascending
Definition: interval.hpp:145
tmp::merge_intervals::copy_cond::type
std::integral_constant< bool, std::ratio_greater< typename cur::x, typename prev::x >::type::value &&tmp::less< typename cur::y, typename prev::y >::type::value > type
copy if cur.x > prev.x and cur.y < prev.y
Definition: interval.hpp:116
tmp::break_point
A break point consisting of a X and a Y value.
Definition: interval.hpp:57
NiHu::bessel::Y
std::complex< double > Y(std::complex< double > const &z)
Bessel function Y_nu(z)
Definition: math_functions.hpp:315
tmp::inserter
a compile time inserter
Definition: sequence.hpp:118