edge-selectors.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include "Vector2.h"
  3. #include "SignedDistance.h"
  4. #include "edge-segments.h"
  5. namespace msdfgen {
  6. struct MultiDistance {
  7. double r, g, b;
  8. };
  9. /// Selects the nearest edge by its true distance.
  10. class TrueDistanceSelector {
  11. public:
  12. typedef double DistanceType;
  13. explicit TrueDistanceSelector(const Point2 &p = Point2());
  14. void addEdge(const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);
  15. void merge(const TrueDistanceSelector &other);
  16. DistanceType squaredDistance() const;
  17. private:
  18. Point2 p;
  19. SignedDistance minDistance;
  20. };
  21. class PseudoDistanceSelectorBase {
  22. public:
  23. static bool pointFacingEdge(const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge, const Point2 &p, double param);
  24. PseudoDistanceSelectorBase();
  25. void addEdgeTrueDistance(const EdgeSegment *edge, const SignedDistance &distance, double param);
  26. void addEdgePseudoDistance(const SignedDistance &distance);
  27. void merge(const PseudoDistanceSelectorBase &other);
  28. double computeSquaredDistance(const Point2 &p) const;
  29. private:
  30. SignedDistance minTrueDistance;
  31. SignedDistance minNegativePseudoDistance;
  32. SignedDistance minPositivePseudoDistance;
  33. const EdgeSegment *nearEdge;
  34. double nearEdgeParam;
  35. };
  36. /// Selects the nearest edge by its pseudo-distance.
  37. class PseudoDistanceSelector : public PseudoDistanceSelectorBase {
  38. public:
  39. typedef double DistanceType;
  40. explicit PseudoDistanceSelector(const Point2 &p = Point2());
  41. void addEdge(const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);
  42. DistanceType squaredDistance() const;
  43. private:
  44. Point2 p;
  45. };
  46. /// Selects the nearest edge for each of the three channels by its pseudo-distance.
  47. class MultiDistanceSelector {
  48. public:
  49. typedef MultiDistance DistanceType;
  50. explicit MultiDistanceSelector(const Point2 &p = Point2());
  51. void addEdge(const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);
  52. void merge(const MultiDistanceSelector &other);
  53. DistanceType squaredDistance() const;
  54. private:
  55. Point2 p;
  56. PseudoDistanceSelectorBase r, g, b;
  57. };
  58. }