2
0

SignedDistance.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <cmath>
  3. #include <cfloat>
  4. namespace msdfgen {
  5. /// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment.
  6. class SignedDistance {
  7. public:
  8. double distance;
  9. double dot;
  10. inline SignedDistance() : distance(-DBL_MAX), dot(0) { }
  11. inline SignedDistance(double dist, double d) : distance(dist), dot(d) { }
  12. };
  13. inline bool operator<(const SignedDistance a, const SignedDistance b) {
  14. return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot < b.dot);
  15. }
  16. inline bool operator>(const SignedDistance a, const SignedDistance b) {
  17. return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot > b.dot);
  18. }
  19. inline bool operator<=(const SignedDistance a, const SignedDistance b) {
  20. return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot <= b.dot);
  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. }