Shape.h 1.8 KB

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