ShapeDistanceFinder.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <vector>
  3. #include "Vector2.h"
  4. #include "edge-selectors.h"
  5. #include "contour-combiners.h"
  6. namespace msdfgen {
  7. /// Finds the distance between a point and a Shape. ContourCombiner dictates the distance metric and its data type.
  8. template <class ContourCombiner>
  9. class ShapeDistanceFinder {
  10. public:
  11. typedef typename ContourCombiner::DistanceType DistanceType;
  12. // Passed shape object must persist until the distance finder is destroyed!
  13. explicit ShapeDistanceFinder(const Shape &shape);
  14. /// Finds the distance from origin. Not thread-safe! Is fastest when subsequent queries are close together.
  15. DistanceType distance(const Point2 &origin);
  16. /// Finds the distance between shape and origin. Does not allocate result cache used to optimize performance of multiple queries.
  17. static DistanceType oneShotDistance(const Shape &shape, const Point2 &origin);
  18. private:
  19. const Shape &shape;
  20. ContourCombiner contourCombiner;
  21. std::vector<typename ContourCombiner::EdgeSelectorType::EdgeCache> shapeEdgeCache;
  22. };
  23. typedef ShapeDistanceFinder<SimpleContourCombiner<TrueDistanceSelector> > SimpleTrueShapeDistanceFinder;
  24. }
  25. #include "ShapeDistanceFinder.hpp"