                     let magnitude = sqrt(x * x + y * y)
                     let phase = atan2(y, x)
                     
-                    _destination.pointee = FloatColorPixel(hue: phase * 0.5 / .pi, saturation: magnitude, brightness: magnitude * intensity)
-                    
-                    horizontal += 1
-                    vertical += 1
-                    _destination += 1
+                    destination.pointee = FloatColorPixel(hue: phase * 0.5 / .pi, saturation: magnitude, brightness: magnitude * intensity)
+                    
+                    destination += 1
+                    
+                    if i == r0.first {
+                        
+                        s01 += 1
+                        s02 += 1
+                        s12 += 1
+                        s21 += 1
+                        s22 += 1
+                        
+                    } else if i == r0.last {
+                        
+                        s00 += 1
+                        s01 += 1
+                        s10 += 1
+                        s20 += 1
+                        s21 += 1
+                        
+                    } else {
+                        
+                        s00 += 1
+                        s01 += 1
+                        s02 += 1
+                        s10 += 1
+                        s12 += 1
+                        s20 += 1
+                        s21 += 1
+                        s22 += 1
+                    }
+                }
+                
+                if j == r1.first {
+                    
+                    s1 += width
+                    s2 += width
+                    
+                } else if j == r1.last {
+                    
+                    s0 += width
+                    s1 += width
+                    
+                } else {
+                    
+                    s0 += width
+                    s1 += width
+                    s2 += width
                 }
             }
         }
     }
     
-    return edges
+    return result
 }

    
    let intensity = Double(intensity)
    
    var edges = Image<FloatColorPixel<RGBColorModel>>(width: width + 2, height: height + 2, colorSpace: .default)
    
    guard width > 0 && height > 0 else { return edges }
    
    let horizontal = ImageConvolution(image, horizontal: [1, 0, -1], vertical: [0.25, 0.5, 0.25])
    let vertical = ImageConvolution(image, horizontal: [0.25, 0.5, 0.25], vertical: [1, 0, -1])
    
    horizontal.withUnsafeBufferPointer { horizontal in
        
        guard var horizontal = horizontal.baseAddress else { return }
        
        vertical.withUnsafeBufferPointer { vertical in
            
            guard var vertical = vertical.baseAddress else { return }
            
            edges.withUnsafeMutableBufferPointer { destination in
                
                guard var _destination = destination.baseAddress else { return }
                
                for _ in 0..<destination.count {
                    
                    let c0 = horizontal.pointee
                    let c1 = vertical.pointee
                    
                    let x_max = max(c0.opacity, c0.color.max())
                    let x_min = min(c0.opacity, c0.color.min())

                    let magnitude = sqrt(x * x + y * y)
                    let phase = atan2(y, x)
                    
                    destination.pointee = ColorPixel(hue: phase * 0.5 / .pi, saturation: magnitude, brightness: magnitude * intensity)
                    
                    destination += 1
                    
                    if i == r0.first {
                        
                        s01 += 1
                        s02 += 1
                        s12 += 1
                        s21 += 1
                        s22 += 1
                        
                    } else if i == r0.last {
                        
                        s00 += 1
                        s01 += 1
                        s10 += 1
                        s20 += 1
                        s21 += 1
                        
                    } else {
                        
                        s00 += 1
                        s01 += 1
                        s02 += 1
                        s10 += 1
                        s12 += 1
                        s20 += 1
                        s21 += 1
                        s22 += 1
                    }
                }
                
                if j == r1.first {
                    
                    s1 += width
                    s2 += width
                    
                } else if j == r1.last {
                    
                    s0 += width
                    s1 += width
                    
                } else {
                    
                    s0 += width
                    s1 += width
                    s2 += width
                }
            }
        }
    }
    
    return result
}

@inlinable
