Blame test/arc-direction.c

Packit 324a5c
/*
Packit 324a5c
 * Copyright © 2012 Intel Corporation
Packit 324a5c
 *
Packit 324a5c
 * Permission is hereby granted, free of charge, to any person
Packit 324a5c
 * obtaining a copy of this software and associated documentation
Packit 324a5c
 * files (the "Software"), to deal in the Software without
Packit 324a5c
 * restriction, including without limitation the rights to use, copy,
Packit 324a5c
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 324a5c
 * of the Software, and to permit persons to whom the Software is
Packit 324a5c
 * furnished to do so, subject to the following conditions:
Packit 324a5c
 *
Packit 324a5c
 * The above copyright notice and this permission notice shall be
Packit 324a5c
 * included in all copies or substantial portions of the Software.
Packit 324a5c
 *
Packit 324a5c
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 324a5c
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 324a5c
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 324a5c
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 324a5c
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 324a5c
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 324a5c
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 324a5c
 * SOFTWARE.
Packit 324a5c
 *
Packit 324a5c
 * Author: Chris Wilson <chris@chris-wilson.co.uk>
Packit 324a5c
 */
Packit 324a5c
Packit 324a5c
#include "cairo-test.h"
Packit 324a5c
Packit 324a5c
#define SIZE		(2 * 20)
Packit 324a5c
#define PAD		(2)
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw_arcs (cairo_t *cr)
Packit 324a5c
{
Packit 324a5c
    double start = M_PI/12, stop = 2*start;
Packit 324a5c
Packit 324a5c
    cairo_move_to (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_arc (cr, SIZE/2, SIZE/2, SIZE/2, start, stop);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
Packit 324a5c
    cairo_translate (cr, SIZE+PAD, 0);
Packit 324a5c
    cairo_move_to (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_arc (cr, SIZE/2, SIZE/2, SIZE/2, 2*M_PI-stop, 2*M_PI-start);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
Packit 324a5c
    cairo_translate (cr, 0, SIZE+PAD);
Packit 324a5c
    cairo_move_to (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_arc_negative (cr, SIZE/2, SIZE/2, SIZE/2, 2*M_PI-stop, 2*M_PI-start);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
Packit 324a5c
    cairo_translate (cr, -SIZE-PAD, 0);
Packit 324a5c
    cairo_move_to (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_arc_negative (cr, SIZE/2, SIZE/2, SIZE/2, start, stop);
Packit 324a5c
    cairo_fill (cr);
Packit 324a5c
Packit 324a5c
    return CAIRO_TEST_SUCCESS;
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    cairo_save (cr);
Packit 324a5c
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
Packit 324a5c
    cairo_paint (cr);
Packit 324a5c
    cairo_restore (cr);
Packit 324a5c
Packit 324a5c
    cairo_save (cr);
Packit 324a5c
    cairo_translate (cr, PAD, PAD);
Packit 324a5c
    draw_arcs(cr);
Packit 324a5c
    cairo_restore (cr);
Packit 324a5c
Packit 324a5c
    cairo_set_source_rgb (cr, 1, 0, 0);
Packit 324a5c
    cairo_translate (cr, 2*SIZE+3*PAD, 0);
Packit 324a5c
    cairo_save (cr);
Packit 324a5c
    cairo_translate (cr, 2*SIZE+2*PAD, PAD);
Packit 324a5c
    cairo_scale (cr, -1, 1);
Packit 324a5c
    draw_arcs(cr);
Packit 324a5c
    cairo_restore (cr);
Packit 324a5c
Packit 324a5c
    cairo_set_source_rgb (cr, 1, 0, 1);
Packit 324a5c
    cairo_translate (cr, 0, 2*SIZE+3*PAD);
Packit 324a5c
    cairo_save (cr);
Packit 324a5c
    cairo_translate (cr, 2*SIZE+2*PAD, 2*SIZE+2*PAD);
Packit 324a5c
    cairo_scale (cr, -1, -1);
Packit 324a5c
    draw_arcs(cr);
Packit 324a5c
    cairo_restore (cr);
Packit 324a5c
Packit 324a5c
    cairo_set_source_rgb (cr, 0, 0, 1);
Packit 324a5c
    cairo_translate (cr, -(2*SIZE+3*PAD), 0);
Packit 324a5c
    cairo_save (cr);
Packit 324a5c
    cairo_translate (cr, PAD, 2*SIZE+2*PAD);
Packit 324a5c
    cairo_scale (cr, 1, -1);
Packit 324a5c
    draw_arcs(cr);
Packit 324a5c
    cairo_restore (cr);
Packit 324a5c
Packit 324a5c
    return CAIRO_TEST_SUCCESS;
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
CAIRO_TEST (arc_direction,
Packit 324a5c
	    "Test drawing positive/negative arcs",
Packit 324a5c
	    "arc, fill", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    2*(3*PAD + 2*SIZE), 2*(3*PAD + 2*SIZE),
Packit 324a5c
	    NULL, draw)
Packit 324a5c