Scanline.h 947 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <vector>
  3. namespace msdfgen {
  4. /// Represents a horizontal scanline intersecting a shape.
  5. class Scanline {
  6. public:
  7. /// An intersection with the scanline.
  8. struct Intersection {
  9. /// X coordinate
  10. double x;
  11. /// Normalized Y direction of the oriented edge at the point of intersection
  12. int direction;
  13. };
  14. Scanline();
  15. /// Populates the intersection list.
  16. void setIntersections(const std::vector<Intersection> &intersections);
  17. #ifdef MSDFGEN_USE_CPP11
  18. void setIntersections(std::vector<Intersection> &&intersections);
  19. #endif
  20. /// Returns the number of intersections left of x.
  21. int countIntersections(double x) const;
  22. /// Returns the total sign of intersections left of x.
  23. int sumIntersections(double x) const;
  24. private:
  25. std::vector<Intersection> intersections;
  26. mutable int lastIndex;
  27. void preprocess();
  28. int moveTo(double x) const;
  29. };
  30. }