コード例 #1
0
void tst_QPainterPath::contains_QPointF_data()
{
    QTest::addColumn<QPainterPath>("path");
    QTest::addColumn<QPointF>("pt");
    QTest::addColumn<bool>("contained");

    QPainterPath path;
    path.addRect(0, 0, 100, 100);

    // #####
    // #   #
    // #   #
    // #   #
    // #####

    QTest::newRow("[0,0] in [0,0,100,100]") << path << QPointF(0, 0) << true;

    QTest::newRow("[99,0] in [0,0,100,100]") << path << QPointF(99, 0) << true;
    QTest::newRow("[0,99] in [0,0,100,100]") << path << QPointF(0, 99) << true;
    QTest::newRow("[99,99] in [0,0,100,100]") << path << QPointF(99, 99) << true;

    QTest::newRow("[99.99,0] in [0,0,100,100]") << path << QPointF(99.99, 0) << true;
    QTest::newRow("[0,99.99] in [0,0,100,100]") << path << QPointF(0, 99.99) << true;
    QTest::newRow("[99.99,99.99] in [0,0,100,100]") << path << QPointF(99.99, 99.99) << true;

    QTest::newRow("[0.01,0.01] in [0,0,100,100]") << path << QPointF(0.01, 0.01) << true;
    QTest::newRow("[0,0.01] in [0,0,100,100]") << path << QPointF(0, 0.01) << true;
    QTest::newRow("[0.01,0] in [0,0,100,100]") << path << QPointF(0.01, 0) << true;

    QTest::newRow("[-0.01,-0.01] in [0,0,100,100]") << path << QPointF(-0.01, -0.01) << false;
    QTest::newRow("[-0,-0.01] in [0,0,100,100]") << path << QPointF(0, -0.01) << false;
    QTest::newRow("[-0.01,0] in [0,0,100,100]") << path << QPointF(-0.01, 0) << false;


    QTest::newRow("[-10,0] in [0,0,100,100]") << path << QPointF(-10, 0) << false;
    QTest::newRow("[100,0] in [0,0,100,100]") << path << QPointF(100, 0) << false;

    QTest::newRow("[0,-10] in [0,0,100,100]") << path << QPointF(0, -10) << false;
    QTest::newRow("[0,100] in [0,0,100,100]") << path << QPointF(0, 100) << false;

    QTest::newRow("[100.1,0] in [0,0,100,100]") << path << QPointF(100.1, 0) << false;
    QTest::newRow("[0,100.1] in [0,0,100,100]") << path << QPointF(0, 100.1) << false;

    path.addRect(50, 50, 100, 100);

    // #####
    // #   #
    // # #####
    // # # # #
    // ##### #
    //   #   #
    //   #####

    QTest::newRow("[49,49] in 2 rects") << path << QPointF(49,49) << true;
    QTest::newRow("[50,50] in 2 rects") << path << QPointF(50,50) << false;
    QTest::newRow("[100,100] in 2 rects") << path << QPointF(100,100) << true;

    path.setFillRule(Qt::WindingFill);
    QTest::newRow("[50,50] in 2 rects (winding)") << path << QPointF(50,50) << true;

    path.addEllipse(0, 0, 150, 150);

    // #####
    // ##  ##
    // # #####
    // # # # #
    // ##### #
    //  ##  ##
    //   #####

    QTest::newRow("[50,50] in complex (winding)") << path << QPointF(50, 50) << true;

    path.setFillRule(Qt::OddEvenFill);
    QTest::newRow("[50,50] in complex (windinf)") << path << QPointF(50, 50) << true;
    QTest::newRow("[49,49] in complex") << path << QPointF(49,49) << false;
    QTest::newRow("[100,100] in complex") << path << QPointF(49,49) << false;


    // unclosed triangle
    path = QPainterPath();
    path.moveTo(100, 100);
    path.lineTo(130, 70);
    path.lineTo(150, 110);

    QTest::newRow("[100,100] in triangle") << path << QPointF(100, 100) << true;
    QTest::newRow("[140,100] in triangle") << path << QPointF(140, 100) << true;
    QTest::newRow("[130,80] in triangle") << path << QPointF(130, 80) << true;

    QTest::newRow("[110,80] in triangle") << path << QPointF(110, 80) << false;
    QTest::newRow("[150,100] in triangle") << path << QPointF(150, 100) << false;
    QTest::newRow("[120,110] in triangle") << path << QPointF(120, 110) << false;

    QRectF base_rect(0, 0, 20, 20);

    path = QPainterPath();
    path.addEllipse(base_rect);

    // not strictly precise, but good enougth to verify fair precision.
    QPainterPath inside;
    inside.addEllipse(base_rect.adjusted(5, 5, -5, -5));
    QPolygonF inside_poly = inside.toFillPolygon();
    for (int i=0; i<inside_poly.size(); ++i)
        QTest::newRow("inside_ellipse") << path << inside_poly.at(i) << true;

    QPainterPath outside;
    outside.addEllipse(base_rect.adjusted(-5, -5, 5, 5));
    QPolygonF outside_poly = outside.toFillPolygon();
    for (int i=0; i<outside_poly.size(); ++i)
        QTest::newRow("outside_ellipse") << path << outside_poly.at(i) << false;

    path = QPainterPath();
    base_rect = QRectF(50, 50, 200, 200);
    path.addEllipse(base_rect);
    path.setFillRule(Qt::WindingFill);

    QTest::newRow("topleft outside ellipse") << path << base_rect.topLeft() << false;
    QTest::newRow("topright outside ellipse") << path << base_rect.topRight() << false;
    QTest::newRow("bottomright outside ellipse") << path << base_rect.bottomRight() << false;
    QTest::newRow("bottomleft outside ellipse") << path << base_rect.bottomLeft() << false;

    // Test horizontal curve segment
    path = QPainterPath();
    path.moveTo(100, 100);
    path.cubicTo(120, 100, 180, 100, 200, 100);
    path.lineTo(150, 200);
    path.closeSubpath();

    QTest::newRow("horizontal cubic, out left") << path << QPointF(0, 100) << false;
    QTest::newRow("horizontal cubic, out right") << path << QPointF(300, 100) <<false;
    QTest::newRow("horizontal cubic, in mid") << path << QPointF(150, 100) << true;
}
コード例 #2
0
ファイル: test_rect.cpp プロジェクト: ArtHome12/ClanLib
void TestApp::test_rect(void)
{
	Console::write_line(" Header: rect.h");
	Console::write_line("  Class: Rect");

//XXXXXXXXXX
//XX####XXX
//XX####XXX
//XX####XXX
//XXXXXXXXXX

	Rect base_rect(2, 1, 6, 4);
	if (base_rect.get_width() != 4)
		fail();
	if (base_rect.get_height() != 3)
		fail();

	if (base_rect.left != 2)
		fail();

	if (base_rect.top != 1)
		fail();

	if (base_rect.contains(Point(base_rect.left - 1, base_rect.top)))
		fail();
	if (!base_rect.contains(Point(base_rect.left, base_rect.top)))
		fail();
	if (!base_rect.contains(Point(base_rect.left + 1, base_rect.top)))
		fail();
	if (base_rect.contains(Point(base_rect.left, base_rect.top-1)))
		fail();
	if (!base_rect.contains(Point(base_rect.left, base_rect.top+1)))
		fail();

	if (!base_rect.contains(Point(base_rect.right - 1, base_rect.top)))
		fail();
	if (base_rect.contains(Point(base_rect.right, base_rect.top)))
		fail();
	if (base_rect.contains(Point(base_rect.right + 1, base_rect.top)))
		fail();

	if (!base_rect.contains(Point(base_rect.right - 1, base_rect.bottom - 1)))
		fail();
	if (base_rect.contains(Point(base_rect.right - 1, base_rect.bottom)))
		fail();
	if (base_rect.contains(Point(base_rect.right - 1, base_rect.bottom + 1)))
		fail();

	if (!base_rect.contains(Point(base_rect.left, base_rect.bottom - 1)))
		fail();
	if (base_rect.contains(Point(base_rect.left, base_rect.bottom)))
		fail();
	if (base_rect.contains(Point(base_rect.left, base_rect.bottom + 1)))
		fail();

	Rect test_rect;
	
	test_rect = base_rect;
	if (!test_rect.is_overlapped(base_rect)) 
		fail();
	if (!base_rect.is_overlapped(test_rect)) 
		fail();

	test_rect = base_rect;
	test_rect.translate(Point(test_rect.get_width(), 0));
	if (test_rect.is_overlapped(base_rect)) 
		fail();
	if (base_rect.is_overlapped(test_rect)) 
		fail();

	test_rect = base_rect;
	test_rect.translate(Point(test_rect.get_width() - 1, 0));
	if (!test_rect.is_overlapped(base_rect)) 
		fail();
	if (!base_rect.is_overlapped(test_rect)) 
		fail();

	test_rect = base_rect;
	test_rect.translate(Point(0, test_rect.get_height()));
	if (test_rect.is_overlapped(base_rect)) 
		fail();
	if (base_rect.is_overlapped(test_rect)) 
		fail();

	test_rect = base_rect;
	test_rect.translate(Point(0, test_rect.get_height() - 1));
	if (!test_rect.is_overlapped(base_rect)) 
		fail();
	if (!base_rect.is_overlapped(test_rect)) 
		fail();

	
	test_rect = base_rect;
	if (!test_rect.is_inside(base_rect)) 
		fail();
	if (!base_rect.is_inside(test_rect)) 
		fail();

	test_rect = base_rect;
	test_rect.translate(Point(1, 0));
	if (test_rect.is_inside(base_rect)) 
		fail();
	if (base_rect.is_inside(test_rect)) 
		fail();
	test_rect = base_rect;
	test_rect.translate(Point(-1, 0));
	if (test_rect.is_inside(base_rect)) 
		fail();
	if (base_rect.is_inside(test_rect)) 
		fail();
	test_rect = base_rect;
	test_rect.translate(Point(0, 1));
	if (test_rect.is_inside(base_rect)) 
		fail();
	if (base_rect.is_inside(test_rect)) 
		fail();
	test_rect = base_rect;
	test_rect.translate(Point(0, -1));
	if (test_rect.is_inside(base_rect)) 
		fail();
	if (base_rect.is_inside(test_rect)) 
		fail();
}