Wildmeshing Toolkit
Loading...
Searching...
No Matches
ExactPosition.hpp
1#pragma once
2
3#include <wmtk/Types.hpp>
4
5#include <memory>
6
7namespace wmtk {
8
29template <class VecR, class VecD>
31{
32public:
33 ExactPosition() = default;
35 : m_p(o.m_p ? std::make_unique<VecR>(*o.m_p) : nullptr)
36 {}
37 ExactPosition& operator=(const ExactPosition& o)
38 {
39 if (this == &o) return *this;
40 if (!o.m_p) {
41 m_p.reset();
42 } else if (m_p) {
43 *m_p = *o.m_p;
44 } else {
45 m_p = std::make_unique<VecR>(*o.m_p);
46 }
47 return *this;
48 }
49
51 VecR value(const VecD& posf) const { return m_p ? *m_p : to_rational(posf); }
52
54 bool coord_equals(int k, const VecD& posf, const Rational& r) const
55 {
56 return m_p ? (*m_p)[k] == r : Rational(posf[k]) == r;
57 }
58
60 void store(const VecR& p)
61 {
62 if (m_p) {
63 *m_p = p;
64 } else {
65 m_p = std::make_unique<VecR>(p);
66 }
67 }
68
70 void clear() { m_p.reset(); }
71
72 bool stored() const { return static_cast<bool>(m_p); }
73
74private:
75 std::unique_ptr<VecR> m_p;
76};
77
78} // namespace wmtk
A vertex's exact (rational) position, stored only while it differs from the vertex's double position.
Definition ExactPosition.hpp:31
bool coord_equals(int k, const VecD &posf, const Rational &r) const
Whether coordinate k equals r, without materialising the whole position.
Definition ExactPosition.hpp:54
void store(const VecR &p)
Store an exact position that may differ from the double one.
Definition ExactPosition.hpp:60
VecR value(const VecD &posf) const
The exact position of a vertex whose double position is posf.
Definition ExactPosition.hpp:51
void clear()
The exact position is the double one: drop the stored copy.
Definition ExactPosition.hpp:70
Definition Rational.hpp:10