PLaSK library
Loading...
Searching...
No Matches
axes.cpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#include "axes.hpp"
15#include "exceptions.hpp"
16#include "utils/string.hpp"
17
18namespace plask {
19
20const AxisNames& AxisNames::Register::get(const std::string &name) const {
21 auto i = axisNames.find(removedChars(name, ",._ \t"));
22 if (i == axisNames.end())
23 throw NoSuchAxisNames(name);
24 return i->second;
25}
26
28 //c0, c1, c2, axis names:
30 ("x", "y", "z", "yz", "z_up")
31 ("z", "x", "y", "xy", "y_up")
32 ("y", "z", "x", "zx", "x_up")
33 ("p", "r", "z", "rz", "rad")
34 ("l", "t", "v", "abs")
35 ("long", "tran", "vert", "absolute");
36
37
38AxisNames::AxisNames(const std::string& c0_name, const std::string& c1_name, const std::string& c2_name)
40
41std::size_t AxisNames::operator [](const std::string &name) const {
42 if (name == byIndex[0] || name == "l" || name == "long") return 0;
43 if (name == byIndex[1] || name == "t" || name == "tran") return 1;
44 if (name == byIndex[2] || name == "v" || name == "vert") return 2;
45 return 3;
46}
47
48Primitive<3>::Direction AxisNames::get3D(const std::string &name) const {
49 std::size_t res = operator [] (name);
50 if (res == 3) throw Exception("\"{0}\" is not proper axis name.", name);
52}
53
54Primitive<2>::Direction AxisNames::get2D(const std::string &name) const {
55 std::size_t res = operator [] (name);
56 if (res == 0 || res == 3) throw Exception("\"{0}\" is not proper 2D axis name.", name);
57 return Primitive<2>::Direction(res - 1);
58}
59
60std::string AxisNames::str() const {
61 if (byIndex[0].length() == 1 && byIndex[1].length() == 1 && byIndex[2].length() == 1)
62 return byIndex[0] + byIndex[1] + byIndex[2];
63 return byIndex[0] + "," + byIndex[1] + "," + byIndex[2];
64}
65
69
71 return
72 this->byIndex[0] == to_compare.byIndex[0] &&
73 this->byIndex[1] == to_compare.byIndex[1] &&
74 this->byIndex[2] == to_compare.byIndex[2];
75}
76
77} // namespace plask