Interface Documentation
Version: invalid
geometry.hh
1 /*~--------------------------------------------------------------------------~*
2  * @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  * /@@///// /@@ @@////@@ @@////// /@@
4  * /@@ /@@ @@@@@ @@ // /@@ /@@
5  * /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  * /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  * /@@ /@@/@@//// //@@ @@ /@@/@@
8  * /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  * // /// ////// ////// //////// //
10  *
11  * Copyright (c) 2016 Los Alamos National Laboratory, LLC
12  * All rights reserved
13  *~--------------------------------------------------------------------------~*/
14 
21 #pragma once
22 
23 #if !defined(__FLECSI_PRIVATE__)
24 #error Do not include this file directly!
25 #endif
26 
28 
29 #include <array>
30 #include <bitset>
31 #include <cassert>
32 #include <cmath>
33 #include <float.h>
34 #include <iostream>
35 #include <math.h>
36 #include <vector>
37 
38 namespace flecsi {
39 namespace topo {
40 
41 /*-----------------------------------------------------------------------------*
42  * class ntree_geometry
43  *-----------------------------------------------------------------------------*/
44 template<typename T, size_t D>
45 struct ntree_geometry {};
46 
47 /*-----------------------------------------------------------------------------*
48  * class ntree_geometry 1D specification
49  *-----------------------------------------------------------------------------*/
50 template<typename T>
51 struct ntree_geometry<T, 1> {
52 
53  using point_t = util::point<T, 1>;
54  using element_t = T;
56  static constexpr element_t tol =
57  std::numeric_limits<element_t>::epsilon() * 10.;
58 
61  static bool
62  within(const point_t & origin, const point_t & center, element_t r1) {
63  return util::distance(origin, center) - r1 <= tol;
64  }
65 
67  static bool within_square(const point_t & origin,
68  const point_t & center,
69  element_t r1,
70  element_t r2) {
71  return util::distance(origin, center) <= std::max(r1, r2);
72  }
73 
76  static bool
77  within_box(const point_t & min, const point_t & max, const point_t & origin) {
78  return origin[0] <= max[0] && origin[0] >= min[0];
79  }
80 
82  static bool intersects_box_box(const point_t & min_b1,
83  const point_t & max_b1,
84  const point_t & min_b2,
85  const point_t & max_b2) {
86  return !((max_b1[0] < min_b2[0]) || (max_b2[0] < min_b1[0]));
87  }
88 
90  static bool intersects_sphere_sphere(const point_t & c1,
91  const element_t r1,
92  const point_t & c2,
93  const element_t r2) {
94  return util::distance(c1, c2) - (r1 + r2) <= tol;
95  }
96 
99  static bool intersects_sphere_box(const point_t & min,
100  const point_t & max,
101  const point_t & c,
102  const element_t r) {
103  point_t x = point_t(std::max(min[0], std::min(c[0], max[0])));
104  element_t dist = util::distance(x, c);
105  return dist - r <= tol;
106  }
107 
113  bool box_MAC(const point_t & position_source,
114  const point_t & position_sink,
115  const point_t & box_source_min,
116  const point_t & box_source_max,
117  double macangle) {
118  double dmax = util::distance(box_source_min, box_source_max);
119  double disttoc = util::distance(position_sink, position_source);
120  return dmax / disttoc - macangle <= tol;
121  }
122 }; // class ntree_geometry specification for 1D
123 
124 /*-----------------------------------------------------------------------------*
125  * class ntree_geometry 2D specification
126  *-----------------------------------------------------------------------------*/
127 template<typename T>
128 struct ntree_geometry<T, 2> {
129  using point_t = util::point<T, 2>;
130  using element_t = T;
131 
133  static constexpr element_t tol =
134  std::numeric_limits<element_t>::epsilon() * 10.;
135 
138  static bool
139  within(const point_t & origin, const point_t & center, element_t r1) {
140  return util::distance(origin, center) - r1 <= tol;
141  }
142 
144  static bool within_square(const point_t & origin,
145  const point_t & center,
146  element_t r1,
147  element_t r2) {
148  return util::distance(origin, center) <= std::max(r1, r2);
149  }
150 
153  static bool
154  within_box(const point_t & min, const point_t & max, const point_t & origin) {
155  return origin[0] <= max[0] && origin[0] > min[0] && origin[1] <= max[1] &&
156  origin[1] > min[1];
157  }
158 
160  static bool intersects_box_box(const point_t & min_b1,
161  const point_t & max_b1,
162  const point_t & min_b2,
163  const point_t & max_b2) {
164  return !((max_b1[0] < min_b2[0] || max_b1[1] < min_b2[1]) ||
165  (max_b2[0] < min_b1[0] || max_b2[1] < min_b1[1]));
166  }
167 
169  static bool intersects_sphere_sphere(const point_t & c1,
170  const element_t r1,
171  const point_t & c2,
172  const element_t r2) {
173  return util::distance(c1, c2) - (r1 + r2) <= tol;
174  }
175 
178  static bool intersects_sphere_box(const point_t & min,
179  const point_t & max,
180  const point_t & c,
181  const element_t r) {
182  point_t x = point_t(std::max(min[0], std::min(c[0], max[0])),
183  std::max(min[1], std::min(c[1], max[1])));
184  element_t dist = util::distance(x, c);
185  return dist - r <= tol;
186  }
187 
193  static bool box_MAC(const point_t & position_source,
194  const point_t & position_sink,
195  const point_t & box_source_min,
196  const point_t & box_source_max,
197  double macangle) {
198  double dmax = util::distance(box_source_min, box_source_max);
199  double disttoc = util::distance(position_sink, position_source);
200  return dmax / disttoc < macangle;
201  }
202 }; // class tree_geometry specification for 2D
203 
204 /*-----------------------------------------------------------------------------*
205  * class tree_geometry 3D specification
206  *-----------------------------------------------------------------------------*/
207 template<typename T>
208 struct ntree_geometry<T, 3> {
209  using point_t = util::point<T, 3>;
210  using element_t = T;
212  static constexpr element_t tol =
213  std::numeric_limits<element_t>::epsilon() * 10.;
214 
217  static bool
218  within(const point_t & origin, const point_t & center, element_t r1) {
219  return util::distance(origin, center) - r1 <= tol;
220  }
221 
223  inline static bool within_square(const point_t & origin,
224  const point_t & center,
225  const element_t & r1,
226  const element_t & r2) {
227  return util::distance(origin, center) <= std::max(r1, r2);
228  }
229 
232  static bool
233  within_box(const point_t & min, const point_t & max, const point_t & origin) {
234  return origin[0] <= max[0] && origin[0] > min[0] && origin[1] <= max[1] &&
235  origin[1] > min[1] && origin[2] <= max[2] && origin[2] > min[2];
236  }
237 
239  inline static bool intersects_box_box(const point_t & min_b1,
240  const point_t & max_b1,
241  const point_t & min_b2,
242  const point_t & max_b2) {
243  return !((max_b1[0] < min_b2[0] || max_b1[1] < min_b2[1] ||
244  max_b1[2] < min_b2[2]) ||
245  (max_b2[0] < min_b1[0] || max_b2[1] < min_b1[1] ||
246  max_b2[2] < min_b1[2]));
247  }
248 
250  static bool intersects_sphere_sphere(const point_t & c1,
251  const element_t r1,
252  const point_t & c2,
253  const element_t r2) {
254  return (c2[0] - c1[0]) * (c2[0] - c1[0]) +
255  (c2[1] - c1[1]) * (c2[1] - c1[1]) +
256  (c2[2] - c1[2]) * (c2[2] - c1[2]) <=
257  (r1 + r2) * (r1 + r2);
258  }
259 
262  static bool intersects_sphere_box(const point_t & min,
263  const point_t & max,
264  const point_t & c,
265  const element_t & r) {
266  point_t x = point_t(c[0] < max[0] ? c[0] : max[0],
267  c[1] < max[1] ? c[1] : max[1],
268  c[2] < max[2] ? c[2] : max[2]);
269  x = {x[0] < min[0] ? min[0] : x[0],
270  x[1] < min[1] ? min[1] : x[1],
271  x[2] < min[2] ? min[2] : x[2]};
272  element_t dist = (x[0] - c[0]) * (x[0] - c[0]) +
273  (x[1] - c[1]) * (x[1] - c[1]) +
274  (x[2] - c[2]) * (x[2] - c[2]);
275  return dist <= r * r;
276  }
277 
283  static bool box_MAC(const point_t & position_source,
284  const point_t & position_sink,
285  const point_t & box_source_min,
286  const point_t & box_source_max,
287  double macangle) {
288  double dmax = util::distance(box_source_min, box_source_max);
289  double disttoc = util::distance(position_sink, position_source);
290  return dmax / disttoc < macangle;
291  }
292 }; // class ntree_geometry specification for 3D
293 
294 } // namespace topo
295 } // namespace flecsi
296 
297 /*~-------------------------------------------------------------------------~-*
298  * Formatting options for vim.
299  * vim: set tabstop=2 shiftwidth=2 expandtab :
300  *~-------------------------------------------------------------------------~-*/
static bool within(const point_t &origin, const point_t &center, element_t r1)
Definition: geometry.hh:62
static bool intersects_sphere_sphere(const point_t &c1, const element_t r1, const point_t &c2, const element_t r2)
Intersection of two spheres based on center and radius.
Definition: geometry.hh:169
static bool within_square(const point_t &origin, const point_t &center, element_t r1, element_t r2)
Return true if dist^2 < radius^2.
Definition: geometry.hh:67
static bool within_square(const point_t &origin, const point_t &center, const element_t &r1, const element_t &r2)
Return true if dist^2 < radius^2.
Definition: geometry.hh:223
static bool within(const point_t &origin, const point_t &center, element_t r1)
Definition: geometry.hh:218
static bool intersects_sphere_box(const point_t &min, const point_t &max, const point_t &c, const element_t &r)
Definition: geometry.hh:262
static bool intersects_sphere_box(const point_t &min, const point_t &max, const point_t &c, const element_t r)
Definition: geometry.hh:178
static bool box_MAC(const point_t &position_source, const point_t &position_sink, const point_t &box_source_min, const point_t &box_source_max, double macangle)
Definition: geometry.hh:283
static bool box_MAC(const point_t &position_source, const point_t &position_sink, const point_t &box_source_min, const point_t &box_source_max, double macangle)
Definition: geometry.hh:193
static bool intersects_sphere_box(const point_t &min, const point_t &max, const point_t &c, const element_t r)
Definition: geometry.hh:99
static bool within(const point_t &origin, const point_t &center, element_t r1)
Definition: geometry.hh:139
static bool within_box(const point_t &min, const point_t &max, const point_t &origin)
Definition: geometry.hh:154
Definition: dimensioned_array.hh:58
static bool intersects_sphere_sphere(const point_t &c1, const element_t r1, const point_t &c2, const element_t r2)
Intersection of two spheres based on center and radius.
Definition: geometry.hh:90
static bool intersects_box_box(const point_t &min_b1, const point_t &max_b1, const point_t &min_b2, const point_t &max_b2)
Intersection between two boxes defined by there min and max bound.
Definition: geometry.hh:82
static bool intersects_box_box(const point_t &min_b1, const point_t &max_b1, const point_t &min_b2, const point_t &max_b2)
Intersection between two boxes defined by there min and max bound.
Definition: geometry.hh:160
static bool intersects_sphere_sphere(const point_t &c1, const element_t r1, const point_t &c2, const element_t r2)
Intersection of two spheres based on center and radius.
Definition: geometry.hh:250
static bool within_box(const point_t &min, const point_t &max, const point_t &origin)
Definition: geometry.hh:77
static bool intersects_box_box(const point_t &min_b1, const point_t &max_b1, const point_t &min_b2, const point_t &max_b2)
Intersection between two boxes defined by there min and max bound.
Definition: geometry.hh:239
Definition: geometry.hh:45
bool box_MAC(const point_t &position_source, const point_t &position_sink, const point_t &box_source_min, const point_t &box_source_max, double macangle)
Definition: geometry.hh:113
static bool within_box(const point_t &min, const point_t &max, const point_t &origin)
Definition: geometry.hh:233
static bool within_square(const point_t &origin, const point_t &center, element_t r1, element_t r2)
Return true if dist^2 < radius^2.
Definition: geometry.hh:144
Definition: control.hh:31