Interface Documentation
Version: invalid
point.hh
Go to the documentation of this file.
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 
15 #pragma once
16 
19 #include "flecsi/util/common.hh"
21 
22 #include <array>
23 #include <cmath>
24 
25 namespace flecsi {
26 namespace util {
27 
28 //----------------------------------------------------------------------------//
37 //----------------------------------------------------------------------------//
38 
39 template<typename TYPE, size_t DIMENSION>
41 
42 //----------------------------------------------------------------------------//
49 //----------------------------------------------------------------------------//
50 
51 template<typename TYPE, size_t DIMENSION>
52 constexpr point<TYPE, DIMENSION> operator*(TYPE const val,
53  point<TYPE, DIMENSION> const & p) {
55  for(size_t d(0); d < DIMENSION; ++d) {
56  tmp[d] *= val;
57  } // for
58 
59  return tmp;
60 } // operator *
61 
62 //----------------------------------------------------------------------------//
72 //----------------------------------------------------------------------------//
73 
74 template<typename TYPE, size_t DIMENSION>
75 TYPE
77  TYPE sum(0);
78  for(size_t d(0); d < DIMENSION; ++d) {
79  sum += (square)(a[d] - b[d]);
80  } // for
81 
82  return std::sqrt(sum);
83 } // distance
84 
85 //----------------------------------------------------------------------------//
95 //----------------------------------------------------------------------------//
96 
97 template<typename TYPE, size_t DIMENSION>
98 constexpr point<TYPE, DIMENSION>
100  return point<TYPE, DIMENSION>((a + b) / 2.0);
101 } // midpoint
102 
103 //----------------------------------------------------------------------------//
112 //----------------------------------------------------------------------------//
113 
114 template<template<typename...> class CONTAINER, typename TYPE, size_t DIMENSION>
115 constexpr auto
116 centroid(CONTAINER<point<TYPE, DIMENSION>> const & points) {
117  point<TYPE, DIMENSION> tmp(0.0);
118 
119  for(auto p : points) {
120  tmp += p;
121  } // for
122 
123  tmp /= points.size();
124 
125  return tmp;
126 } // centroid
127 
128 //----------------------------------------------------------------------------//
137 //----------------------------------------------------------------------------//
138 
139 template<typename TYPE, size_t DIMENSION>
140 constexpr auto
141 centroid(std::initializer_list<point<TYPE, DIMENSION>> points) {
142  point<TYPE, DIMENSION> tmp(0.0);
143 
144  for(auto p : points) {
145  tmp += p;
146  } // for
147 
148  tmp /= points.size();
149 
150  return tmp;
151 } // centroid
152 
153 } // namespace util
154 } // namespace flecsi
T square(const T &a)
P.O.D.
Definition: common.hh:72
constexpr auto centroid(CONTAINER< point< TYPE, DIMENSION >> const &points)
Definition: point.hh:116
constexpr point< TYPE, DIMENSION > operator*(TYPE const val, point< TYPE, DIMENSION > const &p)
Definition: point.hh:52
Definition: dimensioned_array.hh:58
constexpr point< TYPE, DIMENSION > midpoint(point< TYPE, DIMENSION > const &a, point< TYPE, DIMENSION > const &b)
Definition: point.hh:99
TYPE distance(point< TYPE, DIMENSION > const &a, point< TYPE, DIMENSION > const &b)
Definition: point.hh:76
static constexpr size_t size()
Return the size of the array.
Definition: dimensioned_array.hh:101
Definition: control.hh:31