Skip to content

Commit

Permalink
inlined calls to distance_transform_impl_linf_or_l1 and removed unnec…
Browse files Browse the repository at this point in the history
…essary comments
  • Loading branch information
morgane.baizeau committed Apr 28, 2024
1 parent 9878239 commit 9fa21cb
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/distance_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ pub(crate) enum DistanceFrom {

pub(crate) fn distance_transform_impl(image: &mut GrayImage, norm: Norm, from: DistanceFrom) {
match norm {
Norm::LInf => distance_transform_impl_linf(image, from),
Norm::L1 => distance_transform_impl_l1(image, from),
Norm::LInf => distance_transform_impl_linf_or_l1::<true>(image, from),
Norm::L1 => distance_transform_impl_linf_or_l1::<false>(image, from),
Norm::L2 => {
match from {
DistanceFrom::Foreground => (),
Expand All @@ -133,21 +133,6 @@ pub(crate) fn distance_transform_impl(image: &mut GrayImage, norm: Norm, from: D
}
}

#[inline(always)]
fn distance_transform_impl_linf(image: &mut GrayImage, from: DistanceFrom) {
// the boolean generic parameter "IS_LINF" allows
// for there to be one compiled fuction per norm,
// reducing the number of if statements evaluated at runtime
distance_transform_impl_linf_or_l1::<true>(image, from)
}
#[inline(always)]
fn distance_transform_impl_l1(image: &mut GrayImage, from: DistanceFrom) {
// the boolean generic parameter "IS_LINF" allows
// for there to be one compiled fuction per norm,
// reducing the number of if statements evaluated at runtime
distance_transform_impl_linf_or_l1::<false>(image, from)
}

fn distance_transform_impl_linf_or_l1<const IS_LINF: bool>(
image: &mut GrayImage,
from: DistanceFrom,
Expand Down Expand Up @@ -184,7 +169,6 @@ fn distance_transform_impl_linf_or_l1<const IS_LINF: bool>(
check(image, x, y, x, y - 1);

if IS_LINF {
// this 'if' statement will be compiled away because IS_LINF is a const
if x > 0 {
check(image, x, y, x - 1, y - 1);
}
Expand All @@ -207,7 +191,6 @@ fn distance_transform_impl_linf_or_l1<const IS_LINF: bool>(
check(image, x, y, x, y + 1);

if IS_LINF {
// this 'if' statement will be compiled away because IS_LINF is a const
if x < image.width() - 1 {
check(image, x, y, x + 1, y + 1);
}
Expand Down

0 comments on commit 9fa21cb

Please sign in to comment.