summaryrefslogtreecommitdiffstatsci
path: root/src/cairo-tests/curves.cpp
diff options
context:
space:
mode:
authorsuyambulingamrm <suyambu.rm@samsung.com>2014-08-02 17:03:05 +0530
committersuyambulingamrm <suyambu.rm@samsung.com>2014-08-02 17:03:05 +0530
commit7cb71d5ed95246a80723550d04fbce102a0f440b (patch)
treedd0631cda5dfc95807af2c1198607ec9e79cdb89 /src/cairo-tests/curves.cpp
parent8f9cde1ab8bc38f7341da62e4654d04c1fb15534 (diff)
Issue #130. Add Cairo tests for curves, linear_gradient and radial_gradient.
Diffstat (limited to 'src/cairo-tests/curves.cpp')
-rw-r--r--src/cairo-tests/curves.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/cairo-tests/curves.cpp b/src/cairo-tests/curves.cpp
index 270e510..e40d3b2 100644
--- a/src/cairo-tests/curves.cpp
+++ b/src/cairo-tests/curves.cpp
@@ -6,17 +6,22 @@
*/
#include <config.h>
-#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
+#include <math.h>
#include "caskbench.h"
#include "caskbench_context.h"
#include "cairo-shapes.h"
+static double delta = 0;
+
int
ca_setup_curves(caskbench_context_t *ctx)
{
+ cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE);
+ cairo_set_line_width (ctx->cairo_cr, 1);
+
return 1;
}
@@ -28,6 +33,47 @@ ca_teardown_curves(void)
int
ca_test_curves(caskbench_context_t *ctx)
{
+ cairo_t *cr = ctx->cairo_cr;
+ int cp = ctx->canvas_width / 2; // center point
+ int rr = ctx->canvas_width / 2;
+ int nn = 32; // must be even
+ double step = (2 * M_PI) / nn;
+
+ for (int i=0; i<ctx->size; i++) {
+ double angle = delta; // in radians
+ double x = cp + rr * cos(angle);
+ double y = cp + rr * sin(angle);
+
+ // begin path
+ cairo_new_path(cr);
+ cairo_move_to (cr, x, y);
+
+ // segments
+ for (int j=0; j<nn; j++) {
+ double r = rr * drand48() / 8.0;
+
+ double angle1 = j * step + delta;
+ double x1 = cp + r * cos(angle1);
+ double y1 = cp + r * sin(angle1);
+
+ double x2 = cp + rr * cos(angle1);
+ double y2 = cp + rr * sin(angle1);
+
+ cairo_curve_to (ctx->cairo_cr,
+ x1, y1,
+ x2, y2, x2,y2);
+ }
+ cairo_close_path(cr);
+ cairoRandomizeColor(ctx);
+
+ // TODO: apply other fill types
+ if (ctx->shape_defaults.fill_type == CB_FILL_SOLID) {
+ cairo_fill (cr);
+ }
+ cairo_stroke (cr);
+
+ }
+ delta += 0.5;
return 1;
}