2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 08.03.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_SIMPLEX_H
|
|
|
|
#define ENGINE_SIMPLEX_H
|
|
|
|
|
2021-10-16 16:14:51 +03:00
|
|
|
#include <list>
|
2021-10-12 17:12:47 +03:00
|
|
|
|
2022-07-11 16:58:05 +03:00
|
|
|
#include "../math/Vec3D.h"
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
enum class SimplexType {
|
|
|
|
Zero,
|
|
|
|
Point,
|
|
|
|
Line,
|
|
|
|
Triangle,
|
|
|
|
Tetrahedron
|
|
|
|
};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
struct Simplex final {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-16 16:14:51 +03:00
|
|
|
std::list<Vec3D> _points{};
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
Simplex() = default;
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
Simplex(std::initializer_list<Vec3D> list) {
|
2021-10-31 11:39:08 +03:00
|
|
|
for (const auto &v : list) {
|
2021-10-12 17:12:47 +03:00
|
|
|
_points.push_back(v);
|
2021-10-31 11:39:08 +03:00
|
|
|
if (_points.size() > 4) {
|
2021-10-12 17:12:47 +03:00
|
|
|
_points.pop_front();
|
2021-10-31 11:39:08 +03:00
|
|
|
}
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
void push_front(const Vec3D &point) {
|
2021-10-12 17:12:47 +03:00
|
|
|
_points.push_front(point);
|
2021-10-31 11:39:08 +03:00
|
|
|
if (_points.size() > 4) {
|
2021-10-12 17:12:47 +03:00
|
|
|
_points.pop_back();
|
2021-10-31 11:39:08 +03:00
|
|
|
}
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
|
2021-10-16 16:14:51 +03:00
|
|
|
Vec3D operator[](unsigned i) const {
|
|
|
|
auto it = _points.begin();
|
2021-10-31 11:39:08 +03:00
|
|
|
for (unsigned k = 0; k < i; k++) {
|
2021-10-16 16:14:51 +03:00
|
|
|
++it;
|
2021-10-31 11:39:08 +03:00
|
|
|
}
|
2021-10-16 16:14:51 +03:00
|
|
|
return *it;
|
|
|
|
|
|
|
|
}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
[[nodiscard]] unsigned size() const { return _points.size(); }
|
|
|
|
|
|
|
|
[[nodiscard]] auto begin() const { return _points.begin(); }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
[[nodiscard]] auto end() const { return _points.end(); }
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
[[nodiscard]] SimplexType type() const { return static_cast<SimplexType>(_points.size()); }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_SIMPLEX_H
|