Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tf_debug.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20#ifndef _SOURCE_TF_DEBUG_H_
21#define _SOURCE_TF_DEBUG_H_
22
23#include <iostream>
24#include <Magnum/Magnum.h>
25#include <Magnum/Math/Vector3.h>
26#include <Magnum/Math/Matrix3.h>
27#include <Corrade/Utility/Debug.h>
28#include <sstream>
29#include <array>
30
31
32inline std::ostream& operator<<(std::ostream& os, const Magnum::Vector3& vec)
33{
34 os << "{" << vec[0] << "," << vec[1] << "," << vec[2] << "}";
35 return os;
36}
37
38inline std::ostream& operator<<(std::ostream& os, const Magnum::Vector3ui& vec)
39{
40 os << "{" << vec[0] << "," << vec[1] << "," << vec[2] << "}";
41 return os;
42}
43
44inline std::ostream& operator<<(std::ostream& os, const Magnum::Math::Matrix3<float>& m)
45{
46 os << "{" << m.row(0) << "," << std::endl
47 << " " << m.row(1) << "," << std::endl
48 << " " << m.row(2) << "}" << std::endl;
49 return os;
50}
51
52
53template <typename ArrayType, size_t Length>
54std::ostream& operator << (std::ostream& stream, const std::array<ArrayType, Length>);
55
56
57template <typename ArrayType>
58std::ostream& operator << (std::ostream& stream, const std::array<ArrayType, 2> a) {
59 stream << "{" << a[0] << ", " << a[1] << "}";
60 return stream;
61}
62
63template <typename ArrayType>
64std::ostream& operator << (std::ostream& stream, const std::array<ArrayType, 3> a) {
65 stream << "{" << a[0] << ", " << a[1] << ", " << a[2] << "}";
66 return stream;
67}
68
69template <typename ArrayType>
70std::ostream& operator << (std::ostream& stream, const std::array<ArrayType, 4> a) {
71 stream << "{" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] <<"}";
72 return stream;
73}
74
75template<typename MagnumType>
76std::string to_string(const MagnumType &val) {
77 std::ostringstream ss;
78 ss << std::fixed;
79 ss.precision(4);
80 ss << val;
81 return ss.str();
82}
83
84#endif // _SOURCE_TF_DEBUG_H_