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