* src/sdf/ftbsdf.c (bsdf_is_edge): Use macros to make it look cleaner.

Use `CHECK_NEIGHBOR' macro to check neighbors while
finding edges. Make the code more readable and look
cleaner.
This commit is contained in:
Anuj Verma 2020-07-27 17:04:33 +05:30 committed by anujverma
parent 262e9649f3
commit 419633c374
2 changed files with 38 additions and 80 deletions

View File

@ -1,3 +1,12 @@
2020-07-27 Anuj Verma <anujv@iitbhilai.ac.in>
* src/sdf/ftbsdf.c (bsdf_is_edge): Use macros to
make it look cleaner.
Use `CHECK_NEIGHBOR' macro to check neighbors while
finding edges. Make the code more readable and look
cleaner.
2020-07-27 Anuj Verma <anujv@iitbhilai.ac.in> 2020-07-27 Anuj Verma <anujv@iitbhilai.ac.in>
[sdf -> bsdf] Fix edge detection bug. [sdf -> bsdf] Fix edge detection bug.

View File

@ -82,6 +82,24 @@
* *
*/ */
#ifdef CHECK_NEIGHBOR
#undef CHECK_NEIGHBOR
#endif
/* Use the macro only in `bsdf_is_edge' function. */
#define CHECK_NEIGHBOR( x_offset, y_offset ) \
if ( x + x_offset >= 0 && x + x_offset < w && \
y + y_offset >= 0 && y + y_offset < r ) \
{ \
num_neighbour++; \
to_check = s + y_offset * w + x_offset; \
if ( *to_check == 0 ) \
{ \
is_edge = 1; \
goto Done; \
} \
}
/************************************************************************** /**************************************************************************
* *
* @Function: * @Function:
@ -115,108 +133,39 @@
goto Done; goto Done;
/* up */ /* up */
if ( y > 0 ) CHECK_NEIGHBOR( 0, -1 );
{
num_neighbour++;
to_check = s - w;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* down */ /* down */
if ( y < r - 2 ) CHECK_NEIGHBOR( 0, 1 );
{
num_neighbour++;
to_check = s + w;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* left */ /* left */
if ( x > 0 ) CHECK_NEIGHBOR( -1, 0 );
{
num_neighbour++;
to_check = s - 1;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* right */ /* right */
if ( x < w - 2 ) CHECK_NEIGHBOR( 1, 0 );
{
num_neighbour++;
to_check = s + 1;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* up left */ /* up left */
if ( y > 0 && x > 0 ) CHECK_NEIGHBOR( -1, -1 );
{
num_neighbour++;
to_check = s - w - 1;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* up right */ /* up right */
if ( y > 0 && x < w - 2 ) CHECK_NEIGHBOR( 1, -1 );
{
num_neighbour++;
to_check = s - w + 1;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* down left */ /* down left */
if ( y < r - 2 && x > 0 ) CHECK_NEIGHBOR( -1, 1 );
{
num_neighbour++;
to_check = s + w - 1;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
/* down right */ /* down right */
if ( y < r - 2 && x < w - 2 ) CHECK_NEIGHBOR( 1, 1 );
{
num_neighbour++;
to_check = s + w + 1;
if ( *to_check == 0 )
{
is_edge = 1;
goto Done;
}
}
if ( num_neighbour != 8 ) if ( num_neighbour != 8 )
is_edge = 1; is_edge = 1;
Done: Done:
return is_edge; return is_edge;
} }
#undef CHECK_NEIGHBOR
/************************************************************************** /**************************************************************************
* *
* @Function: * @Function: