diff --git a/c++/contourgl/polyspan.cpp b/c++/contourgl/polyspan.cpp index fe6747f..ebcea9e 100644 --- a/c++/contourgl/polyspan.cpp +++ b/c++/contourgl/polyspan.cpp @@ -23,6 +23,9 @@ #include "polyspan.h" +using namespace std; + + Polyspan::Polyspan(): open_index(0), cur_x(0.0), @@ -83,6 +86,7 @@ void Polyspan::sort_marks() { current.setcover(0, 0); sort(covers.begin() + open_index, covers.end()); + flags &= ~NotSorted; } } @@ -171,12 +175,12 @@ void Polyspan::line_to(Real x, Real y) { || (cur_x < window.minx && x < window.minx) ) { //clip both vertices - but only needed in the x direction - cur_x = std::max(cur_x, (Real)window.minx); - cur_x = std::min(cur_x, (Real)window.maxx); + cur_x = max(cur_x, (Real)window.minx); + cur_x = min(cur_x, (Real)window.maxx); //clip the dest values - y is already clipped - x = std::max(x, (Real)window.minx); - x = std::min(x, (Real)window.maxx); + x = max(x, (Real)window.minx); + x = min(x, (Real)window.maxx); //must start at new point... move_pen((int)floor(cur_x), (int)floor(cur_y)); @@ -257,10 +261,10 @@ void Polyspan::line_to(Real x, Real y) { } bool Polyspan::clip_conic(const Vector * const p, const ContextRect &r) { - const Real minx = std::min(std::min(p[0][0], p[1][0]), p[2][0]); - const Real miny = std::min(std::min(p[0][1], p[1][1]), p[2][1]); - const Real maxx = std::max(std::max(p[0][0], p[1][0]), p[2][0]); - const Real maxy = std::max(std::max(p[0][1], p[1][1]), p[2][1]); + const Real minx = min(min(p[0][0], p[1][0]), p[2][0]); + const Real miny = min(min(p[0][1], p[1][1]), p[2][1]); + const Real maxx = max(max(p[0][0], p[1][0]), p[2][0]); + const Real maxy = max(max(p[0][1], p[1][1]), p[2][1]); return (minx > r.maxx) || (maxx < r.minx) || @@ -278,7 +282,7 @@ Real Polyspan::max_edges_conic(const Vector *const p) { const Real d1 = x1*x1 + y1*y1; const Real d2 = x2*x2 + y2*y2; - return std::max(d1,d2); + return max(d1,d2); } void Polyspan::subd_conic_stack(Vector *arc) { @@ -406,7 +410,7 @@ Real Polyspan::max_edges_cubic(const Vector *const p) { const Real d2 = x2*x2 + y2*y2; const Real d3 = x3*x3 + y3*y3; - return std::max(std::max(d1, d2), d3); + return max(max(d1, d2), d3); } void Polyspan::subd_cubic_stack(Vector *arc) { diff --git a/c++/contourgl/test.cpp b/c++/contourgl/test.cpp index dcb60c7..e1e9f16 100644 --- a/c++/contourgl/test.cpp +++ b/c++/contourgl/test.cpp @@ -176,16 +176,26 @@ public: }; Test::Wrapper::Wrapper(const std::string &filename): - filename(filename), surface(), t(get_clock()) + filename(filename), + surface(), + tga(filename.size() > 4 && filename.substr(filename.size()-4, 4) == ".tga"), + t(get_clock()) +{ } + +Test::Wrapper::Wrapper(const std::string &filename, Surface &surface): + filename(filename), + surface(&surface), + tga(filename.size() > 4 && filename.substr(filename.size()-4, 4) == ".tga"), + t(get_clock()) { } Test::Wrapper::~Wrapper() { - if (!surface) glFinish(); + if (!surface && tga) glFinish(); Real ms = 1000.0*(Real)(get_clock() - t)/(Real)(CLOCKS_PER_SEC); cout << setw(8) << fixed << setprecision(3) << ms << " ms - " << filename << endl; - if (filename.size() > 4 && filename.substr(filename.size()-4, 4) == ".tga") { + if (tga) { if (surface) Helper::save_surface(*surface, filename); else @@ -206,7 +216,17 @@ void Test::test1() { cout << c.size() << " vertices" << endl; glPushAttrib(GL_ALL_ATTRIB_BITS); - glColor4d(0.0, 0.0, 1.0, 1.0); + + int random = (int)get_clock(); + { + Wrapper t("test_1_control_timer_200000_simple_ops"); + int j = random; + for(long long i = 0; i < 200000; ++i) + if (j > i) ++j; + glColor4f(j%2, j%2, j%2, j%2); + } + + glColor4f(0.f, 0.f, 1.f, 1.f); { Wrapper t("test_1_contour.tga"); @@ -250,7 +270,7 @@ void Test::test2() { Vector min_size(1.75/1024.0, 1.75/1024.0); { - Wrapper("test_2_split"); + Wrapper t("test_2_split"); cc.split(c, bounds, min_size); } @@ -319,6 +339,14 @@ void Test::test2() { glEnd(); } + glPushAttrib(GL_ALL_ATTRIB_BITS); + //glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + { + Wrapper t("test_2_array.tga"); + glDrawArrays(GL_POINTS, 0, count); + } + glPopAttrib(); + { Wrapper t("test_2_contour_fill.tga"); Helper::draw_contour(count, false, false); @@ -366,7 +394,7 @@ void Test::test3() { Color color(0.f, 0.f, 1.f, 1.f); { - Wrapper("test_3_build_polyspan"); + Wrapper t("test_3_build_polyspan"); c.to_polyspan(polyspan); } @@ -385,7 +413,7 @@ void Test::test3() { { - Wrapper("test_3_polyspan_sort"); + Wrapper t("test_3_polyspan_sort"); polyspan.sort_marks(); } diff --git a/c++/contourgl/test.h b/c++/contourgl/test.h index f35f57a..6bfa1ce 100644 --- a/c++/contourgl/test.h +++ b/c++/contourgl/test.h @@ -31,13 +31,14 @@ public: private: std::string filename; Surface *surface; + bool tga; clock_t t; - Wrapper(const Wrapper&): surface(), t() { } + Wrapper(const Wrapper&): surface(), tga(), t() { } Wrapper& operator= (const Wrapper&) { return *this; } public: Wrapper(const std::string &filename); - Wrapper(const std::string &filename, Surface &surface): filename(filename), surface(&surface), t(clock()) { } + Wrapper(const std::string &filename, Surface &surface); ~Wrapper(); };