SignedDistance.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include "SignedDistance.h"
  2. #include <cmath>
  3. #include "arithmetics.hpp"
  4. namespace msdfgen {
  5. const SignedDistance SignedDistance::INFINITE(-1e240, 1);
  6. SignedDistance::SignedDistance() : sqDistance(-1e240), dot(1) { }
  7. SignedDistance::SignedDistance(double sqDistance, double d) : sqDistance(sqDistance), dot(d) { }
  8. double SignedDistance::distance() const {
  9. return sign(sqDistance)*sqrt(fabs(sqDistance));
  10. }
  11. bool operator<(SignedDistance a, SignedDistance b) {
  12. return fabs(a.sqDistance) < fabs(b.sqDistance) || (fabs(a.sqDistance) == fabs(b.sqDistance) && a.dot < b.dot);
  13. }
  14. bool operator>(SignedDistance a, SignedDistance b) {
  15. return fabs(a.sqDistance) > fabs(b.sqDistance) || (fabs(a.sqDistance) == fabs(b.sqDistance) && a.dot > b.dot);
  16. }
  17. bool operator<=(SignedDistance a, SignedDistance b) {
  18. return fabs(a.sqDistance) < fabs(b.sqDistance) || (fabs(a.sqDistance) == fabs(b.sqDistance) && a.dot <= b.dot);
  19. }
  20. bool operator>=(SignedDistance a, SignedDistance b) {
  21. return fabs(a.sqDistance) > fabs(b.sqDistance) || (fabs(a.sqDistance) == fabs(b.sqDistance) && a.dot >= b.dot);
  22. }
  23. }