diff options
| author | Matthias Melcher <github@matthiasm.com> | 2022-11-30 22:40:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-30 22:40:52 +0100 |
| commit | bf825f8ebd18615fdbecb449c14300105d469a24 (patch) | |
| tree | 2e9c3f075b124347eea974c9b429c06d5f29df78 /src | |
| parent | bc3bbb7ca028db377ec4b2acbe74d8f2c8a5c149 (diff) | |
Add a unit test for drawing complex shapes (#565)
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Graphics_Driver.cxx | 1 | ||||
| -rw-r--r-- | src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx | 5 | ||||
| -rw-r--r-- | src/fl_curve.cxx | 13 | ||||
| -rw-r--r-- | src/fl_vertex.cxx | 15 |
4 files changed, 28 insertions, 6 deletions
diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index 967b0159b..35697c256 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -55,6 +55,7 @@ Fl_Graphics_Driver::Fl_Graphics_Driver() p_size = 0; xpoint = NULL; what = NONE; + n = 0; }; /** Destructor */ diff --git a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx index 7cd144ce6..b5ec90bf4 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Graphics_Driver_vertex.cxx @@ -41,6 +41,7 @@ // double Fl_OpenGL_Graphics_Driver::transform_dy(double x, double y) void Fl_OpenGL_Graphics_Driver::begin_points() { + Fl_Graphics_Driver::begin_points(); glBegin(GL_POINTS); } @@ -49,6 +50,7 @@ void Fl_OpenGL_Graphics_Driver::end_points() { } void Fl_OpenGL_Graphics_Driver::begin_line() { + Fl_Graphics_Driver::begin_line(); glBegin(GL_LINE_STRIP); } @@ -57,6 +59,7 @@ void Fl_OpenGL_Graphics_Driver::end_line() { } void Fl_OpenGL_Graphics_Driver::begin_loop() { + Fl_Graphics_Driver::begin_loop(); glBegin(GL_LINE_LOOP); } @@ -65,6 +68,7 @@ void Fl_OpenGL_Graphics_Driver::end_loop() { } void Fl_OpenGL_Graphics_Driver::begin_polygon() { + Fl_Graphics_Driver::begin_polygon(); glBegin(GL_POLYGON); } @@ -73,6 +77,7 @@ void Fl_OpenGL_Graphics_Driver::end_polygon() { } void Fl_OpenGL_Graphics_Driver::begin_complex_polygon() { + Fl_Graphics_Driver::begin_complex_polygon(); glBegin(GL_POLYGON); } diff --git a/src/fl_curve.cxx b/src/fl_curve.cxx index 58cb2767a..c3324f96e 100644 --- a/src/fl_curve.cxx +++ b/src/fl_curve.cxx @@ -46,21 +46,22 @@ void Fl_Graphics_Driver::curve(double X0, double Y0, fl_transformed_vertex(x,y); double x1 = fl_transform_x(X1,Y1); - double yy1 = fl_transform_y(X1,Y1); + double y1 = fl_transform_y(X1,Y1); double x2 = fl_transform_x(X2,Y2); double y2 = fl_transform_y(X2,Y2); double x3 = fl_transform_x(X3,Y3); double y3 = fl_transform_y(X3,Y3); // find the area: - double a = fabs((x-x2)*(y3-yy1)-(y-y2)*(x3-x1)); - double b = fabs((x-x3)*(y2-yy1)-(y-y3)*(x2-x1)); + double a = fabs((x-x2)*(y3-y1)-(y-y2)*(x3-x1)); + double b = fabs((x-x3)*(y2-y1)-(y-y3)*(x2-x1)); if (b > a) a = b; // use that to guess at the number of segments: int nSeg = int(sqrt(a)/4); if (nSeg > 1) { if (nSeg > 100) nSeg = 100; // make huge curves not hang forever + if (nSeg < 9) nSeg = 9; // make tiny curevs look bearable double e = 1.0/nSeg; @@ -74,9 +75,9 @@ void Fl_Graphics_Driver::curve(double X0, double Y0, double dx2 = dx3 + 2*xb*e*e; // calculate the coefficients of 3rd order equation: - double ya = (y3-3*y2+3*yy1-y); - double yb = 3*(y2-2*yy1+y); - double yc = 3*(yy1-y); + double ya = (y3-3*y2+3*y1-y); + double yb = 3*(y2-2*y1+y); + double yc = 3*(y1-y); // calculate the forward differences: double dy1 = ((ya*e+yb)*e+yc)*e; double dy3 = 6*ya*e*e*e; diff --git a/src/fl_vertex.cxx b/src/fl_vertex.cxx index c17a89e23..c02e24ff8 100644 --- a/src/fl_vertex.cxx +++ b/src/fl_vertex.cxx @@ -57,6 +57,21 @@ void Fl_Graphics_Driver::pop_matrix() { m = stack[--sptr]; } +/** see fl_load_identity() */ +void Fl_Graphics_Driver::load_identity() { + m = m0; +} + +/** see fl_load_matrix() */ +void Fl_Graphics_Driver::load_matrix(double a, double b, double c, double d, double x, double y) { + m.a = a; + m.b = b; + m.c = c; + m.d = d; + m.x = x; + m.y = y; +} + /** see fl_mult_matrix() */ void Fl_Graphics_Driver::mult_matrix(double a, double b, double c, double d, double x, double y) { matrix o; |
