World Builder  0.1.0-pre
A geodyanmic initial conditions generator
point.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 by the authors of the World Builder code.
3 
4  This file is part of the World Builder.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 2 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 Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
20 #include <world_builder/assert.h>
22 
23 namespace WorldBuilder
24 {
25  namespace Types
26  {
27  template <int dim>
28  Point<dim>::Point(const WorldBuilder::Point<dim> &default_value, const std::string &description)
29  :
30  value(default_value),
31  default_value(default_value),
32  description(description)
33  {
34  this->type_name = dim == 2 ? type::Point2D : type::Point3D;
35  }
36 
37  template <int dim>
39  :
40  value(value),
41  default_value(default_value),
42  description(description)
43  {
44  this->type_name = dim == 2 ? type::Point2D : type::Point3D;
45  }
46 
47  template <int dim>
49  {}
50 
51  template <int dim>
52  std::unique_ptr<Interface>
54  {
55  return std::unique_ptr<Interface>(new Point(value, default_value, description));
56  }
57 
58 
59  template<int dim>
60  double Point<dim>::operator*(const Point<dim> &point_) const
61  {
62  const std::array<double,dim> array = point_.value.get_array();
63  double dot_product = 0;
64  for (unsigned int i = 0; i < dim; ++i)
65  dot_product += value[i] * array[i];
66  return dot_product;
67  }
68 
69 
70  template<int dim>
72  Point<dim>::operator*(const double scalar) const
73  {
74  // initialize the array to zero.
75  std::array<double,dim> array = WorldBuilder::Point<dim>().get_array();
76  for (unsigned int i = 0; i < dim; ++i)
77  array[i] += value[i] * scalar;
78  return WorldBuilder::Point<dim>(array);
79  }
80 
81  template<int dim>
83  Point<dim>::operator+(const Point<dim> &point_) const
84  {
86  point_tmp += point_.value;
87 
88  return point_tmp;
89  }
90 
91  template<int dim>
93  Point<dim>::operator-(const Point<dim> &point_) const
94  {
96  point_tmp -= point_.value;
97 
98  return point_tmp;
99  }
100 
104  template<int dim>
105  const double &
106  Point<dim>::operator[](const unsigned int index) const
107  {
108  return value[index];
109  }
110 
111 
115  template<int dim>
116  double &
117  Point<dim>::operator[](const unsigned int index)
118  {
119  return value[index];
120  }
121 
122  template<int dim>
124  operator*(const double scalar, const Point<dim> &point)
125  {
126  return point.value*scalar;
127  }
128 
129  template class Point<2>;
130  template class Point<3>;
131  template WorldBuilder::Point<2> operator*(const double scalar, const Point<2> &point);
132  template WorldBuilder::Point<3> operator*(const double scalar, const Point<3> &point);
133  }
134 }
135 
double operator*(const Point< dim > &point) const
Definition: point.cc:60
WorldBuilder::Point< dim > operator-(const Point< dim > &point) const
Definition: point.cc:93
WorldBuilder::Point< dim > operator+(const Point< dim > &point) const
Definition: point.cc:83
Point(const WorldBuilder::Point< dim > &default_value, const std::string &description)
Definition: point.cc:28
const double & operator[](const unsigned int index) const
Definition: point.cc:106
WorldBuilder::Point< dim > default_value
Definition: point.h:99
std::string description
Definition: point.h:100
virtual std::unique_ptr< Interface > clone() const
Definition: point.cc:53
WorldBuilder::Point< dim > value
Definition: point.h:98