| 57 | } |
| 58 | |
| 59 | std::optional<float> DistanceMap::getInterpolated( float x, float y ) const |
| 60 | { |
| 61 | if ( x < 0.f ) |
| 62 | { |
| 63 | return std::nullopt; |
| 64 | } |
| 65 | else if ( x < 0.5f ) |
| 66 | { |
| 67 | x = 0.f; |
| 68 | } |
| 69 | else if ( x > float( resX() ) ) |
| 70 | { |
| 71 | return std::nullopt; |
| 72 | } |
| 73 | else if( x > float( resX() ) - 0.5f ) |
| 74 | { |
| 75 | x = float( resX() ) - 1.f; |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | x -= 0.5f; |
| 80 | } |
| 81 | |
| 82 | if ( y < 0.f ) |
| 83 | { |
| 84 | return std::nullopt; |
| 85 | } |
| 86 | else if ( y < 0.5f ) |
| 87 | { |
| 88 | y = 0.f; |
| 89 | } |
| 90 | else if ( y > float( resY() ) ) |
| 91 | { |
| 92 | return std::nullopt; |
| 93 | } |
| 94 | else if ( y > float( resY() ) - 0.5f ) |
| 95 | { |
| 96 | y = float( resY() ) - 1.f; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | y -= 0.5f; |
| 101 | } |
| 102 | |
| 103 | const float xlowf = std::floor( x ); |
| 104 | const float ylowf = std::floor( y ); |
| 105 | const int xlow = int( xlowf ); |
| 106 | const int ylow = int( ylowf ); |
| 107 | assert( 0 <= xlow && xlow < dims_.x ); |
| 108 | assert( 0 <= ylow && ylow < dims_.y ); |
| 109 | |
| 110 | const auto idx = toIndex( { xlow, ylow } ); |
| 111 | const auto lowlow = get( idx ); |
| 112 | const auto lowhigh = ( ylow + 1 < dims_.y ) ? get( idx + dims_.x ) : 0.0f; |
| 113 | const auto highlow = ( xlow + 1 < dims_.x ) ? get( idx + 1 ) : 0.0f; |
| 114 | const auto highhigh = ( ylow + 1 < dims_.y ) && ( xlow + 1 < dims_.x ) ? get( idx + dims_.x + 1 ) : 0.0f; |
| 115 | if ( lowlow && lowhigh && highlow && highhigh ) |
| 116 | { |