Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/msdfgen/core/SignedDistance.hpp
9903 views
1
2
#pragma once
3
4
#include <cmath>
5
#include <cfloat>
6
#include "base.h"
7
8
namespace msdfgen {
9
10
/// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment.
11
class SignedDistance {
12
13
public:
14
double distance;
15
double dot;
16
17
inline SignedDistance() : distance(-DBL_MAX), dot(0) { }
18
inline SignedDistance(double dist, double d) : distance(dist), dot(d) { }
19
20
};
21
22
inline bool operator<(const SignedDistance a, const SignedDistance b) {
23
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot < b.dot);
24
}
25
26
inline bool operator>(const SignedDistance a, const SignedDistance b) {
27
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot > b.dot);
28
}
29
30
inline bool operator<=(const SignedDistance a, const SignedDistance b) {
31
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot <= b.dot);
32
}
33
34
inline bool operator>=(const SignedDistance a, const SignedDistance b) {
35
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot >= b.dot);
36
}
37
38
}
39
40