vectozavr-shooter/engine/physics/Simplex.h

56 lines
1.1 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 08.03.2021.
//
#ifndef ENGINE_SIMPLEX_H
#define ENGINE_SIMPLEX_H
#include "../Vec3D.h"
#include <list>
enum class SimplexType {
Zero,
Point,
Line,
Triangle,
Tetrahedron
};
2021-09-13 15:53:43 +03:00
struct Simplex final {
2021-09-13 15:53:43 +03:00
private:
std::list<Vec3D> _points{};
2021-09-13 15:53:43 +03:00
public:
Simplex() = default;
Simplex(std::initializer_list<Vec3D> list) {
for (const auto & v : list) {
_points.push_back(v);
if(_points.size() > 4)
_points.pop_front();
2021-09-13 15:53:43 +03:00
}
}
void push_front(const Vec3D& point) {
_points.push_front(point);
if(_points.size() > 4)
_points.pop_back();
2021-09-13 15:53:43 +03:00
}
Vec3D operator[](unsigned i) const {
auto it = _points.begin();
2021-10-18 21:58:19 +03:00
for(unsigned k=0; k<i; k++)
++it;
return *it;
}
[[nodiscard]] unsigned size() const { return _points.size(); }
[[nodiscard]] auto begin() const { return _points.begin(); }
[[nodiscard]] auto end() const { return _points.end(); }
2021-09-13 15:53:43 +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