SignedDistance.hpp 1.1 KB

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