Exemplo n.º 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());
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
bool OverlayScalarMapperLegend::pick(int oglXCoord, int oglYCoord, const Vec2i& position, const Vec2ui& size)
{
    Recti oglRect(position, size.x(), size.y());

    OverlayColorLegendLayoutInfo layoutInViewPortCoords(oglRect.min(), Vec2ui(oglRect.width(), oglRect.height()));
    layoutInfo(&layoutInViewPortCoords);

    Vec2i legendBarOrigin = oglRect.min();
    legendBarOrigin.x() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().x());
    legendBarOrigin.y() += static_cast<uint>(layoutInViewPortCoords.legendRect.min().y());

    Recti legendBarRect = Recti(legendBarOrigin, static_cast<uint>(layoutInViewPortCoords.legendRect.width()), static_cast<uint>(layoutInViewPortCoords.legendRect.height()));

    if ((oglXCoord > legendBarRect.min().x()) && (oglXCoord < legendBarRect.max().x()) &&
        (oglYCoord > legendBarRect.min().y()) && (oglYCoord < legendBarRect.max().y()))
    {
        return true;
    }

    return false;
}