Shape.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // The proportional amount by which a curve's control point will be adjusted to eliminate convergent corners.
  9. #define MSDFGEN_DECONVERGENCE_FACTOR .000001
  10. /// Vector shape representation.
  11. class Shape {
  12. public:
  13. struct Bounds {
  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. bool inverseYAxis;
  20. Shape();
  21. /// Adds a contour.
  22. void addContour(const Contour &contour);
  23. #ifdef MSDFGEN_USE_CPP11
  24. void addContour(Contour &&contour);
  25. #endif
  26. /// Adds a blank contour and returns its reference.
  27. Contour & addContour();
  28. /// Normalizes the shape geometry for distance field generation.
  29. void normalize();
  30. /// Performs basic checks to determine if the object represents a valid shape.
  31. bool validate() const;
  32. /// Adjusts the bounding box to fit the shape.
  33. void bound(double &l, double &b, double &r, double &t) const;
  34. /// Adjusts the bounding box to fit the shape border's mitered corners.
  35. void boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const;
  36. /// Computes the minimum bounding box that fits the shape, optionally with a (mitered) border.
  37. Bounds getBounds(double border = 0, double miterLimit = 0, int polarity = 0) const;
  38. /// Outputs the scanline that intersects the shape at y.
  39. void scanline(Scanline &line, double y) const;
  40. /// Returns the total number of edge segments
  41. int edgeCount() const;
  42. /// Assumes its contours are unoriented (even-odd fill rule). Attempts to orient them to conform to the non-zero winding rule.
  43. void orientContours();
  44. };
  45. }