From daeb3dc28d467cb21b9e36db9322d4d79f00fde6 Mon Sep 17 00:00:00 2001 From: Stefan Gustavson Date: Tue, 23 Dec 2014 11:43:25 +0100 Subject: [PATCH] Corrected a long standing bug in the gradient computations. Not a fatal bug, but it improves the accuracy slightly. This stupid cut-and-paste bug has passed unnoticed for years, but it was found by one of my students. It's very nice to have such smart people actually check your code. After correcting it, I see that the results in my article from 2011 would have improved for a few cases where the error was still a bit too high for my liking. --- .../makedist/edtaa3func.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter 12 2D Shape Rendering by Distance Fields/makedist/edtaa3func.c b/Chapter 12 2D Shape Rendering by Distance Fields/makedist/edtaa3func.c index e6ca41f..9e217d5 100644 --- a/Chapter 12 2D Shape Rendering by Distance Fields/makedist/edtaa3func.c +++ b/Chapter 12 2D Shape Rendering by Distance Fields/makedist/edtaa3func.c @@ -74,7 +74,7 @@ void computegradient(double *img, int w, int h, double *gx, double *gy) k = i*w + j; if((img[k]>0.0) && (img[k]<1.0)) { // Compute gradient for edge pixels only gx[k] = -img[k-w-1] - SQRT2*img[k-1] - img[k+w-1] + img[k-w+1] + SQRT2*img[k+1] + img[k+w+1]; - gy[k] = -img[k-w-1] - SQRT2*img[k-w] - img[k+w-1] + img[k-w+1] + SQRT2*img[k+w] + img[k+w+1]; + gy[k] = -img[k-w-1] - SQRT2*img[k-w] - img[k-w-1] + img[k+w+1] + SQRT2*img[k+w] + img[k+w+1]; glength = gx[k]*gx[k] + gy[k]*gy[k]; if(glength > 0.0) { // Avoid division by zero glength = sqrt(glength);