From 419633c3745dcb093ee26afb593895608417d73e Mon Sep 17 00:00:00 2001 From: Anuj Verma Date: Mon, 27 Jul 2020 17:04:33 +0530 Subject: [PATCH] * 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. --- [GSoC]ChangeLog | 9 ++++ src/sdf/ftbsdf.c | 109 +++++++++++++---------------------------------- 2 files changed, 38 insertions(+), 80 deletions(-) diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog index 798b61495..85d7f794a 100644 --- a/[GSoC]ChangeLog +++ b/[GSoC]ChangeLog @@ -1,3 +1,12 @@ +2020-07-27 Anuj Verma + + * 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 [sdf -> bsdf] Fix edge detection bug. diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c index a42c4d4a4..69504342a 100644 --- a/src/sdf/ftbsdf.c +++ b/src/sdf/ftbsdf.c @@ -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: @@ -115,108 +133,39 @@ goto Done; /* up */ - if ( y > 0 ) - { - num_neighbour++; - to_check = s - w; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( 0, -1 ); /* down */ - if ( y < r - 2 ) - { - num_neighbour++; - to_check = s + w; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( 0, 1 ); /* left */ - if ( x > 0 ) - { - num_neighbour++; - to_check = s - 1; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( -1, 0 ); /* right */ - if ( x < w - 2 ) - { - num_neighbour++; - to_check = s + 1; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( 1, 0 ); /* up left */ - if ( y > 0 && x > 0 ) - { - num_neighbour++; - to_check = s - w - 1; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( -1, -1 ); /* up right */ - if ( y > 0 && x < w - 2 ) - { - num_neighbour++; - to_check = s - w + 1; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( 1, -1 ); /* down left */ - if ( y < r - 2 && x > 0 ) - { - num_neighbour++; - to_check = s + w - 1; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( -1, 1 ); /* down right */ - if ( y < r - 2 && x < w - 2 ) - { - num_neighbour++; - to_check = s + w + 1; - if ( *to_check == 0 ) - { - is_edge = 1; - goto Done; - } - } + CHECK_NEIGHBOR( 1, 1 ); if ( num_neighbour != 8 ) is_edge = 1; Done: return is_edge; + } + #undef CHECK_NEIGHBOR + /************************************************************************** * * @Function: