示例#1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(RectTest, FromMinMax)
{
    {
        Rectd rect = Rectd::fromMinMax(Vec2d(-1, 2), Vec2d(10, 12));
        EXPECT_TRUE(rect.isValid());
        EXPECT_DOUBLE_EQ(-1, rect.min().x());
        EXPECT_DOUBLE_EQ(2,  rect.min().y());
        EXPECT_DOUBLE_EQ(10, rect.max().x());
        EXPECT_DOUBLE_EQ(12, rect.max().y());
        EXPECT_DOUBLE_EQ(11, rect.width());
        EXPECT_DOUBLE_EQ(10, rect.height());
    }

    {
        Recti rect = Recti::fromMinMax(Vec2i(-1, 2), Vec2i(10, 12));
        EXPECT_TRUE(rect.isValid());
        EXPECT_EQ(-1, rect.min().x());
        EXPECT_EQ( 2, rect.min().y());
        EXPECT_EQ(10, rect.max().x());
        EXPECT_EQ(12, rect.max().y());
        EXPECT_EQ(11, rect.width());
        EXPECT_EQ(10, rect.height());
    }

    {
        Rectui rect = Rectui::fromMinMax(Vec2ui(1, 2), Vec2ui(11, 22));
        EXPECT_TRUE(rect.isValid());
        EXPECT_EQ( 1, rect.min().x());
        EXPECT_EQ( 2, rect.min().y());
        EXPECT_EQ(11, rect.max().x());
        EXPECT_EQ(22, rect.max().y());
        EXPECT_EQ(10, rect.width());
        EXPECT_EQ(20, rect.height());
    }
}
示例#2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(RectTest, RectTypes)
{
    // Rectf
    {
        Rectf rect;
        EXPECT_FLOAT_EQ(0.0f, rect.min().x());
        EXPECT_FLOAT_EQ(0.0f, rect.min().y());
        EXPECT_FLOAT_EQ(0.0f, rect.width());
        EXPECT_FLOAT_EQ(0.0f, rect.height());

        EXPECT_FALSE(rect.isValid());
    }

    {
        Rectf rect(-1.0f, -2.0f, 5.0f, 10.0f);
        EXPECT_FLOAT_EQ(-1.0f, rect.min().x());
        EXPECT_FLOAT_EQ(-2.0f, rect.min().y());
        EXPECT_FLOAT_EQ(5.0f, rect.width());
        EXPECT_FLOAT_EQ(10.0f, rect.height());

        EXPECT_TRUE(rect.isValid());
    }

    // Recti
    {
        Recti rect;
        EXPECT_EQ(0, rect.min().x());
        EXPECT_EQ(0, rect.min().y());
        EXPECT_EQ(0, rect.width());
        EXPECT_EQ(0, rect.height());

        EXPECT_FALSE(rect.isValid());
    }

    {
        Recti rect(-1, -2, 5, 10);
        EXPECT_EQ(-1, rect.min().x());
        EXPECT_EQ(-2, rect.min().y());
        EXPECT_EQ(5, rect.width());
        EXPECT_EQ(10, rect.height());

        EXPECT_TRUE(rect.isValid());
    }

    // Rectui
    {
        Rectui rect;
        EXPECT_EQ(0, rect.min().x());
        EXPECT_EQ(0, rect.min().y());
        EXPECT_EQ(0, rect.width());
        EXPECT_EQ(0, rect.height());

        EXPECT_FALSE(rect.isValid());
    }

    {
        Rectui rect(1, 2, 5, 10);
        EXPECT_EQ(1, rect.min().x());
        EXPECT_EQ(2, rect.min().y());
        EXPECT_EQ(5, rect.width());
        EXPECT_EQ(10, rect.height());

        EXPECT_TRUE(rect.isValid());
    }
}