Shape.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <vector>
  3. #include "Contour.h"
  4. #include "YAxisOrientation.h"
  5. #include "Scanline.h"
  6. namespace msdfgen {
  7. // Threshold of the dot product of adjacent edge directions to be considered convergent.
  8. #define MSDFGEN_CORNER_DOT_EPSILON .000001
  9. /// Vector shape representation.
  10. class Shape {
  11. public:
  12. struct Bounds {
  13. // NOTE: b is actually the lower Y-coordinate and t the higher Y-coordinate. For Y_DOWNWARD orientation, b is actually the top and t the bottom. May be renamed in a future version.
  14. double l, b, r, t;
  15. };
  16. /// The list of contours the shape consists of.
  17. std::vector<Contour> contours;
  18. /// Specifies whether the shape uses bottom-to-top (false) or top-to-bottom (true) Y coordinates.
  19. /// DEPRECATED - use getYAxisOrientation / setYAxisOrientation instead.
  20. bool inverseYAxis;
  21. Shape();
  22. /// Adds a contour.
  23. void addContour(const Contour &contour);
  24. #ifdef MSDFGEN_USE_CPP11
  25. void addContour(Contour &&contour);
  26. #endif
  27. /// Adds a blank contour and returns its reference.
  28. Contour &addContour();
  29. /// Normalizes the shape geometry for distance field generation.
  30. void normalize();
  31. /// Performs basic checks to determine if the object represents a valid shape.
  32. bool validate() const;
  33. /// Adjusts the bounding box to fit the shape.
  34. void bound(double &xMin, double &yMin, double &xMax, double &yMax) const;
  35. /// Adjusts the bounding box to fit the shape border's mitered corners.
  36. void boundMiters(double &xMin, double &yMin, double &xMax, double &yMax, double border, double miterLimit, int polarity) const;
  37. /// Computes the minimum bounding box that fits the shape, optionally with a (mitered) border.
  38. Bounds getBounds(double border = 0, double miterLimit = 0, int polarity = 0) const;
  39. /// Outputs the scanline that intersects the shape at y.
  40. void scanline(Scanline &line, double y) const;
  41. /// Returns the total number of edge segments
  42. int edgeCount() const;
  43. /// Assumes its contours are unoriented (even-odd fill rule). Attempts to orient them to conform to the non-zero winding rule.
  44. void orientContours();
  45. /// Returns the orientation of the axis of the shape's Y coordinates.
  46. YAxisOrientation getYAxisOrientation() const;
  47. /// Sets the orientation of the axis of the shape's Y coordinates.
  48. void setYAxisOrientation(YAxisOrientation yAxisOrientation);
  49. };
  50. }