2
0

Shape.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <vector>
  3. #include "types.h"
  4. #include "Contour.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 ::msdfgen::real(.000001)
  9. // The proportional amount by which a curve's control point will be adjusted to eliminate convergent corners.
  10. #define MSDFGEN_DECONVERGENCE_FACTOR ::msdfgen::real(.000001)
  11. /// Vector shape representation.
  12. class Shape {
  13. public:
  14. struct Bounds {
  15. real l, b, r, t;
  16. };
  17. /// The list of contours the shape consists of.
  18. std::vector<Contour> contours;
  19. /// Specifies whether the shape uses bottom-to-top (false) or top-to-bottom (true) Y coordinates.
  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(real &l, real &b, real &r, real &t) const;
  35. /// Adjusts the bounding box to fit the shape border's mitered corners.
  36. void boundMiters(real &l, real &b, real &r, real &t, real border, real miterLimit, int polarity) const;
  37. /// Computes the minimum bounding box that fits the shape, optionally with a (mitered) border.
  38. Bounds getBounds(real border = 0, real miterLimit = 0, int polarity = 0) const;
  39. /// Outputs the scanline that intersects the shape at y.
  40. void scanline(Scanline &line, real 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. };
  46. }