diff --git a/src/zm_image.cpp b/src/zm_image.cpp index b0380f7c1..1acb49e03 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -2469,7 +2469,7 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) { size_t n_coords = polygon.GetVertices().size(); - std::vector global_edges; + std::vector global_edges; global_edges.reserve(n_coords); for (size_t j = 0, i = n_coords - 1; j < n_coords; i = j++) { const Vector2 &p1 = polygon.GetVertices()[i]; @@ -2487,9 +2487,9 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) { d.x_ / static_cast(d.y_)); } - std::sort(global_edges.begin(), global_edges.end(), Edge::CompareYX); + std::sort(global_edges.begin(), global_edges.end(), PolygonFill::Edge::CompareYX); - std::vector active_edges; + std::vector active_edges; active_edges.reserve(global_edges.size()); int32 scan_line = global_edges[0].min_y; @@ -2513,7 +2513,7 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) { ++it; } } - std::sort(active_edges.begin(), active_edges.end(), Edge::CompareX); + std::sort(active_edges.begin(), active_edges.end(), PolygonFill::Edge::CompareX); if (!(scan_line % density)) { for (auto it = active_edges.begin(); it != active_edges.end(); ++it) { @@ -2555,10 +2555,6 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) { } } -void Image::Fill(Rgb colour, const Polygon &polygon) { - Fill(colour, 1, polygon); -} - void Image::Rotate(int angle) { angle %= 360; diff --git a/src/zm_image.h b/src/zm_image.h index 71a211fa2..2a3c68232 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -278,7 +278,7 @@ class Image { void Fill( Rgb colour, const Box *limits=0 ); void Fill( Rgb colour, int density, const Box *limits=0 ); void Outline( Rgb colour, const Polygon &polygon ); - void Fill(Rgb colour, const Polygon &polygon); + void Fill(Rgb colour, const Polygon &polygon) { Fill(colour, 1, polygon); }; void Fill(Rgb colour, int density, const Polygon &polygon); void Rotate( int angle ); @@ -292,6 +292,31 @@ class Image { void Deinterlace_4Field(const Image* next_image, unsigned int threshold); }; +// Scan-line polygon fill algorithm +namespace PolygonFill { +class Edge { + public: + Edge() = default; + Edge(int32 min_y, int32 max_y, double min_x, double _1_m) : min_y(min_y), max_y(max_y), min_x(min_x), _1_m(_1_m) {} + + static bool CompareYX(const Edge &e1, const Edge &e2) { + if (e1.min_y == e2.min_y) + return e1.min_x < e2.min_x; + return e1.min_y < e2.min_y; + } + + static bool CompareX(const Edge &e1, const Edge &e2) { + return e1.min_x < e2.min_x; + } + + public: + int32 min_y; + int32 max_y; + double min_x; + double _1_m; +}; +} + #endif // ZM_IMAGE_H /* Blend functions */ diff --git a/src/zm_poly.h b/src/zm_poly.h index fa91f58d1..c25033262 100644 --- a/src/zm_poly.h +++ b/src/zm_poly.h @@ -23,28 +23,6 @@ #include "zm_box.h" #include -class Edge { - public: - Edge() = default; - Edge(int32 min_y, int32 max_y, double min_x, double _1_m) : min_y(min_y), max_y(max_y), min_x(min_x), _1_m(_1_m) {} - - static bool CompareYX(const Edge &e1, const Edge &e2) { - if (e1.min_y == e2.min_y) - return e1.min_x < e2.min_x; - return e1.min_y < e2.min_y; - } - - static bool CompareX(const Edge &e1, const Edge &e2) { - return e1.min_x < e2.min_x; - } - - public: - int32 min_y; - int32 max_y; - double min_x; - double _1_m; -}; - // This class represents convex or concave non-self-intersecting polygons. class Polygon { public: