2
0

Shape.h 1.5 KB

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