Esempio n. 1
0
bool wxBlockDoubleSelection::DoMinimize(wxArrayBlockDouble &blocks)
{
    int n;
    for (n=0; n<1000; n++) // should probably just take < 10 at most
    {
        if (!DoDoMinimize(blocks)) break;
    }

#ifdef CHECK_BLOCK_OVERLAP
    for (size_t a=0; a<blocks.GetCount(); a++)
    {
        printf("Checking wxBlockDoubleSelection::DoMinimize %d =", a); PRINT_BLOCK("", blocks[a])
        for (size_t b=a+1; b<blocks.GetCount(); b++)
        {
            if (blocks[a].Intersects(blocks[b]))
            {
                printf("Intersecting blocks in wxBlockDoubleSelection::DoMinimize\n"); fflush(stdout);
                PRINT_BLOCK("",blocks[a])
                PRINT_BLOCK("",blocks[b])
                wxBell();
            }
        }
    }
#endif

    return n != 0;
}
Esempio n. 2
0
bool wxSheetSelection::DoMinimize(wxArraySheetBlock &blocks) const
{
    int n, count = GetCount() > 0 ? 1000 : 0;
    for (n=0; n<count; n++) // usually just takes a few
    {
        if (!DoDoMinimize(blocks)) break;
    }

    // sanity check - this shouldn't and hasn't happened
    wxCHECK_MSG(!count || (n <= count), true, wxT("Unable to minimize wxSheetSelection"));
    
#ifdef CHECK_BLOCK_OVERLAP
    for (size_t a=0; a<blocks.GetCount(); a++)
    {
        for (size_t b=a+1; b<blocks.GetCount(); b++)
        {
            if (blocks[a].Intersects(blocks[b]))
            {
                wxPrintf(wxT("Intersecting blocks in wxBlockIntSelection::DoMinimize\n")); fflush(stdout);
                PRINT_BLOCK(wxT("First  block "), blocks[a]);
                PRINT_BLOCK(wxT("Second block "), blocks[b]);
                wxBell();
            }
        }
    }
#endif    
    
    return n != 0;    
}
Esempio n. 3
0
int
test_S()
{
	unsigned char vals[5][16] = {
		{ 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
		  0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00 },
		{ 0xb6, 0x6c, 0xd8, 0x88, 0x7d, 0x38, 0xe8, 0xd7,
		  0x77, 0x65, 0xae, 0xea, 0x0c, 0x9a, 0x7e, 0xfc },
		{ 0x55, 0x9d, 0x8d, 0xd7, 0xbd, 0x06, 0xcb, 0xfe,
		  0x7e, 0x7b, 0x26, 0x25, 0x23, 0x28, 0x0d, 0x39 },
		{ 0x0c, 0x33, 0x22, 0xfe, 0xd5, 0x31, 0xe4, 0x63,
		  0x0d, 0x80, 0xef, 0x5c, 0x5a, 0x81, 0xc5, 0x0b },
		{ 0x23, 0xae, 0x65, 0x63, 0x3f, 0x84, 0x2d, 0x29,
		  0xc5, 0xdf, 0x52, 0x9c, 0x13, 0xf5, 0xac, 0xda }
	};

	unsigned char buf[16];
	int i, ret;

	memcpy(buf, vals[0], 16);

	for (i = 0; i < 4; i++) {
		S_func(buf);
		ret = memcmp(buf, vals[i + 1], 16);
		if (ret != 0) {
			printf("S_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i + 1]);
			return 1;
		}
	}

	for (i = 4; i > 0; i--) {
		Sinv_func(buf);
		ret = memcmp(buf, vals[i - 1], 16);
		if (ret != 0) {
			printf("Sinv_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i - 1]);
			return 1;
		}
	}

	return 0;
}
Esempio n. 4
0
int
test_L(struct kuzn_ctx *ctx)
{
	uint8_t vals[5][16] = {
		{ 0x64, 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00,
		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
		{ 0xd4, 0x56, 0x58, 0x4d, 0xd0, 0xe3, 0xe8, 0x4c,
		  0xc3, 0x16, 0x6e, 0x4b, 0x7f, 0xa2, 0x89, 0x0d },
		{ 0x79, 0xd2, 0x62, 0x21, 0xb8, 0x7b, 0x58, 0x4c,
		  0xd4, 0x2f, 0xbc, 0x4f, 0xfe, 0xa5, 0xde, 0x9a },
		{ 0x0e, 0x93, 0x69, 0x1a, 0x0c, 0xfc, 0x60, 0x40,
		  0x8b, 0x7b, 0x68, 0xf6, 0x6b, 0x51, 0x3c, 0x13 },
		{ 0xe6, 0xa8, 0x09, 0x4f, 0xee, 0x0a, 0xa2, 0x04,
		  0xfd, 0x97, 0xbc, 0xb0, 0xb4, 0x4b, 0x85, 0x80 }
	};
	unsigned char buf[16];
	int i, ret;

	memcpy(buf, vals[0], 16);

	for (i = 0; i < 4; i++) {
		L_func(buf, buf, ctx);
		ret = memcmp(buf, vals[i + 1], 16);
		if (ret != 0) {
			printf("L_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i + 1]);
			return 1;
		}
	}

	for (i = 4; i > 0; i--) {
		Linv_func(buf, buf, ctx);
		ret = memcmp(buf, vals[i - 1], 16);
		if (ret != 0) {
			printf("Linv_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i - 1]);
			return 1;
		}
	}

	return 0;
}
Esempio n. 5
0
int
test_R(struct kuzn_ctx *ctx)
{
	uint8_t vals[5][16] = {
		{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 },
		{ 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
		{ 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
		{ 0x64, 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00,
		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
		{ 0x0d, 0x64, 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00,
		  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
	};
	unsigned char buf[16];
	int i, ret;

	memcpy(buf, vals[0], 16);

	for (i = 0; i < 4; i++) {
		R_func(buf, buf, ctx);
		ret = memcmp(buf, vals[i + 1], 16);
		if (ret != 0) {
			printf("R_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i + 1]);
			return 1;
		}
	}

	for (i = 4; i > 0; i--) {
		Rinv_func(buf, buf, ctx);
		ret = memcmp(buf, vals[i - 1], 16);
		if (ret != 0) {
			printf("Rinv_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i - 1]);
			return 1;
		}
	}

	return 0;
}
Esempio n. 6
0
void TestBlocks()
{
    printf("Start Testing blocks -----------------------------------------\n");
    wxBlockInt b1(1,1,4,4);
    wxBlockInt b2(5,4,10,11);
    PRINT_BLOCK("b1", b1)
    PRINT_BLOCK("b2", b2)

    wxBlockInt iB;
    iB.Intersect(b1, b2, &iB);
    PRINT_BLOCK("Intersect b1 b2", iB)

    wxBlockInt uB;
    uB.Union(b1, b2, &uB);
    PRINT_BLOCK("Union b1 b2", uB)

    printf("Touches b1 b2 %d %d\n", b1.Touches(b2), b2.Touches(b1));

    b1 = wxBlockInt(2,3,7,9);
    b2 = wxBlockInt(8,3,8,3);
    printf("Touches b1 b2 %d %d\n", b1.Touches(b2), b2.Touches(b1));

    b1 = wxBlockInt(2,3,7,9);
    b2 = wxBlockInt(1,3,1,3);
    printf("Touches b1 b2 %d %d\n", b1.Touches(b2), b2.Touches(b1));
    iB.Intersect(b1, b2, &iB);
    PRINT_BLOCK("Intersect b1 b2", iB)

    b1 = wxBlockInt(2,3,7,9);
    b2 = wxBlockInt(2,2,2,2);
    printf("Touches b1 b2 %d %d\n", b1.Touches(b2), b2.Touches(b1));

    b1 = wxBlockInt(2,3,7,9);
    b2 = wxBlockInt(7,10,7,10);
    printf("Touches b1 b2 %d %d\n", b1.Touches(b2), b2.Touches(b1));

    printf("End Testing blocks -----------------------------------------\n");
    fflush(stdout);
}
Esempio n. 7
0
bool wxSheetSelection::SelectBlock( const wxSheetBlock &block, bool combineNow, 
                                    wxArraySheetBlock *addedBlocks )
{
    if (block.IsEmpty())
        return false;    

    wxArraySheetBlock extraBlocks;
    wxArraySheetBlock *extra = &extraBlocks;
    if (addedBlocks)
    {
        extra = addedBlocks;
        extra->Clear();
    }

    extra->Add(block);
    int extra_count = 1;

    int n, k, count = m_blocks.GetCount();
    if (((m_options & wxSHEET_SELECTION_MULTIPLE_SEL) == 0) && (count > 0) && 
        m_bounds.Intersects(block))
    {
        const int bottom_row = block.GetBottom();
        wxSheetBlock top, bottom, left, right;   

        // interate though blocks breaking up input block if it's already selected
        for (n=FindTopRow(bottom_row); n<count; n++)
        {
            if (bottom_row < m_blocks[n].GetTop())
                break;

            for (k=0; k<extra_count; k++)
            {
                const int combined = m_blocks[n].Combine(extra->Item(k), top, bottom, left, right);
                if (combined != wxSHEET_BLOCK_NONE)
                {
                    extra->RemoveAt(k);
                    extra_count--;
                    k--;

                    if (combined != wxSHEET_BLOCK_ALL)
                    {
                        if ((combined & wxSHEET_BLOCK_TOP)    != 0) 
                            { extra->Add(top);    extra_count++; }
                        if ((combined & wxSHEET_BLOCK_BOTTOM) != 0) 
                            { extra->Add(bottom); extra_count++; }
                        if ((combined & wxSHEET_BLOCK_LEFT)   != 0)   
                            { extra->Add(left);   extra_count++; }
                        if ((combined & wxSHEET_BLOCK_RIGHT)  != 0)  
                            { extra->Add(right);  extra_count++; }
                    }

                    if (extra_count == 0)
                    {
                        n = count;
                        break;
                    }
                }
            }
        }
    }
    
#ifdef CHECK_BLOCK_SORTING
    for (int m=1; m<m_blocks.GetCount(); m++)
        if (m_blocks[m] < m_blocks[m-1]) PRINT_BLOCK("Not sorted", m_blocks[m]);
#endif // CHECK_BLOCK_SORTING    
    
    if (extra_count != 0)
    {
        m_minimized = false;
        for (n=0; n<extra_count; n++)
            InsertBlock(extra->Item(n));
        if (combineNow)
            Minimize();
        
        return true;
    }
    
    return false;
}