Commit f36d965e authored by Mathieu Faverge's avatar Mathieu Faverge

fix(zooming): Make sure the zomm stays inside the box, and cleanup spaces

parent 8353717f
......@@ -3,17 +3,17 @@
#include "../Helper.hpp"
Zooming::Zooming(symbol_matrix_t* matrix)
: m_matrix(matrix)
: m_matrix(matrix)
{
// Fill correct colors
move(0.f, 1.f, 0.f, 1.f);
// Fill correct colors
move(0.f, 1.f, 0.f, 1.f);
}
Zooming::~Zooming()
{
// Destroy quadtree
symbol_matrix_deinit(m_matrix);
delete m_matrix;
// Destroy quadtree
symbol_matrix_deinit(m_matrix);
delete m_matrix;
}
GLfloat Zooming::getColor(int x, int y)
......@@ -21,88 +21,111 @@ GLfloat Zooming::getColor(int x, int y)
return m_colors[x][y];
}
void Zooming::clean_move( double *xbeg, double *xend,
double *ybeg, double *yend )
{
double tmp;
// Cleanup postions
if ( *xbeg > *xend ) {
double tmp = *xend;
*xbeg = *xend;
*xend = tmp;
}
if ( *ybeg > *yend ) {
double tmp = *yend;
*ybeg = *yend;
*yend = tmp;
}
*xbeg = ( *xbeg < 0. ) ? 0. : *xbeg;
*xend = ( *xend > 1. ) ? 1. : *xend;
*ybeg = ( *ybeg < 0. ) ? 0. : *ybeg;
*yend = ( *yend > 1. ) ? 1. : *yend;
}
void Zooming::move(double xStart, double xEnd, double yStart, double yEnd)
{
int i, j, m, n;
int startCol = xStart * m_matrix->m_colsnbr;
int endCol = xEnd * m_matrix->m_colsnbr;
int diffCols = endCol - startCol;
// Find first cblk
int startCblk = 0;
int endCblk = 0;
for (i = 0; i < m_matrix->m_cblknbr; ++i)
{
symbol_cblk_t* cblk = &(m_matrix->m_cblktab[i]);
if (cblk->m_fcolumn <= startCol && cblk->m_lcolnum >= startCol)
startCblk = i;
if (cblk->m_fcolumn <= endCol && cblk->m_lcolnum >= endCol)
endCblk = i;
}
int diffCblk = endCblk - startCblk;
int startRow = yStart * m_matrix->m_rowsnbr;
int endRow = yEnd * m_matrix->m_rowsnbr;
int diffRow = endRow - startRow;
symbol_cblk_t* cblks = m_matrix->m_cblktab;
symbol_blok_t* bloks = m_matrix->m_bloktab;
for (i = 0; i < DEFAULT_LEVEL_POWER_2; ++i)
{
for (j = 0; j < DEFAULT_LEVEL_POWER_2; ++j)
{
m_colors[i][j] = 0.f;
}
}
float xCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)diffCols + 1);
float yCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)diffRow + 1);
for (i = startCblk; i <= endCblk; ++i)
{
int firstBlokNum = cblks[i].m_bloknum;
int nextBlokNum = (i + 1 != m_matrix->m_cblknbr ? cblks[i + 1].m_bloknum : m_matrix->m_bloknbr);
// Get first block size in col from x to xEnd
symbol_cblk_t* cblk = &(cblks[i]);
int startingCol = (cblk->m_fcolumn < startCol ? startCol : cblk->m_fcolumn);
int endingCol = (cblk->m_lcolnum > endCol ? endCol + 1 : cblk->m_lcolnum);
int x = (startingCol - startCol) * xCoeff;
int xEnd = (endingCol - startCol) * xCoeff;
for (j = firstBlokNum; j < nextBlokNum; ++j)
{
symbol_blok_t* blok = &(bloks[j]);
if (blok->m_frownum >= startRow && blok->m_frownum <= endRow)
{
// Get first block size in row from y to yEnd
int startingRow = (blok->m_frownum < startRow ? startRow : blok->m_frownum);
int endingRow = (blok->m_lrownum > endRow ? endRow + 1 : blok->m_lrownum);
int y = (startingRow - startRow) * yCoeff;
int yEnd = (endingRow - startRow) * yCoeff;
m = x;
do
{
n = y;
do
{
m_colors[m][n] = 1.0f;
n++;
} while (n < yEnd);
m++;
} while (m < xEnd);
}
}
}
}
\ No newline at end of file
int i, j, m, n;
clean_move( &xStart, &xEnd, &yStart, &yEnd );
int startCol = xStart * m_matrix->m_colsnbr;
int endCol = xEnd * m_matrix->m_colsnbr;
int startRow = yStart * m_matrix->m_rowsnbr;
int endRow = yEnd * m_matrix->m_rowsnbr;
int diffCols = endCol - startCol;
int diffRow = endRow - startRow;
// Find first cblk
int startCblk = 0;
int endCblk = 0;
for (i = 0; i < m_matrix->m_cblknbr; ++i)
{
symbol_cblk_t* cblk = &(m_matrix->m_cblktab[i]);
if (cblk->m_fcolumn <= startCol && cblk->m_lcolnum >= startCol)
startCblk = i;
if (cblk->m_fcolumn <= endCol && cblk->m_lcolnum >= endCol)
endCblk = i;
}
int diffCblk = endCblk - startCblk;
symbol_cblk_t* cblks = m_matrix->m_cblktab;
symbol_blok_t* bloks = m_matrix->m_bloktab;
for (i = 0; i < DEFAULT_LEVEL_POWER_2; ++i)
{
for (j = 0; j < DEFAULT_LEVEL_POWER_2; ++j)
{
m_colors[i][j] = 0.f;
}
}
float xCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)diffCols + 1);
float yCoeff = (float)DEFAULT_LEVEL_POWER_2 / ((float)diffRow + 1);
for (i = startCblk; i <= endCblk; ++i)
{
int firstBlokNum = cblks[i].m_bloknum;
int nextBlokNum = (i + 1 != m_matrix->m_cblknbr ? cblks[i + 1].m_bloknum : m_matrix->m_bloknbr);
// Get first block size in col from x to xEnd
symbol_cblk_t* cblk = &(cblks[i]);
int startingCol = (cblk->m_fcolumn < startCol ? startCol : cblk->m_fcolumn);
int endingCol = (cblk->m_lcolnum > endCol ? endCol + 1 : cblk->m_lcolnum);
int x = (startingCol - startCol) * xCoeff;
int xEnd = (endingCol - startCol) * xCoeff;
for (j = firstBlokNum; j < nextBlokNum; ++j)
{
symbol_blok_t* blok = &(bloks[j]);
if (blok->m_frownum >= startRow && blok->m_frownum <= endRow)
{
// Get first block size in row from y to yEnd
int startingRow = (blok->m_frownum < startRow ? startRow : blok->m_frownum);
int endingRow = (blok->m_lrownum > endRow ? endRow + 1 : blok->m_lrownum);
int y = (startingRow - startRow) * yCoeff;
int yEnd = (endingRow - startRow) * yCoeff;
m = x;
do
{
n = y;
do
{
m_colors[m][n] = 1.0f;
n++;
} while (n < yEnd);
m++;
} while (m < xEnd);
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment