World Builder  1.1.0-pre
A geodynamic initial conditions generator
natural_coordinate.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018-2024 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 */
19 
21 
22 namespace WorldBuilder
23 {
24  namespace Objects
25  {
26  NaturalCoordinate::NaturalCoordinate(const std::array<double,3> &position,
27  const CoordinateSystems::Interface &coordinate_system_)
28  {
29  coordinate_system = coordinate_system_.natural_coordinate_system();
30  coordinates = coordinate_system_.cartesian_to_natural_coordinates(position);
31  }
32 
33 
34  // todo, should be possible to make this without the interface, since the Point knows the coord system.
35  NaturalCoordinate::NaturalCoordinate(const Point<3> &position,
36  const CoordinateSystems::Interface &coordinate_system_)
37  {
38  coordinate_system = coordinate_system_.natural_coordinate_system();
39  coordinates = coordinate_system_.cartesian_to_natural_coordinates(position.get_array());
40  }
41 
42 
43  const std::array<double,3> &NaturalCoordinate::get_coordinates() const
44  {
45  return coordinates;
46  }
47 
48 
49  std::array<double,2> NaturalCoordinate::get_surface_coordinates() const
50  {
51  std::array<double,2> coordinate;
52 
53  switch (coordinate_system)
54  {
56  coordinate[0] = coordinates[0];
57  coordinate[1] = coordinates[1];
58  break;
59 
61  coordinate[0] = coordinates[1];
62  coordinate[1] = coordinates[2];
63  break;
64 
65  default:
66  WBAssertThrow (false, "Coordinate system not implemented.");
67  }
68 
69  return coordinate;
70  }
71 
72 
74  {
75  Point<2> coordinate(0,0,coordinate_system);
76 
77  switch (coordinate_system)
78  {
80  coordinate[0] = coordinates[0];
81  coordinate[1] = coordinates[1];
82  break;
83 
85  coordinate[0] = coordinates[1];
86  coordinate[1] = coordinates[2];
87  break;
88 
89  default:
90  WBAssertThrow (false, "Coordinate system not implemented.");
91  }
92 
93  return coordinate;
94  }
95 
96 
99  {
100  return coordinate_system;
101  }
102 
103 
105  {
106  switch (coordinate_system)
107  {
109  return coordinates[2];
110 
112  return coordinates[0];
113 
114  default:
115  WBAssertThrow (false, "Coordinate system not implemented.");
116  }
117 
118  return coordinates[2];
119  }
120  } // namespace Objects
121 } // namespace WorldBuilder
std::array< double, 2 > get_surface_coordinates() const
CoordinateSystem get_coordinate_system() const
#define WBAssertThrow(condition, message)
Definition: assert.h:40
NaturalCoordinate(const std::array< double, 3 > &position, const ::WorldBuilder::CoordinateSystems::Interface &coordinate_system)
const std::array< double, 3 > & get_coordinates() const