[Mapserver-dev] Label centroid alog

John Newton john_mapserver at hotmail.com
Mon May 5 17:06:26 EDT 2003


The labeling centroid algorithm has sometime given me incorrect results and
I believe I see the reason why.  The point1 and point2 pointers can
sometimes point to the same object, thereby rendering incorrect length
calculations (namely zero length).

Here is my suggested change to the code.  Basically I remove the use of
point1 and point2 for determining length and max_len, and get the length
using the diff in x, not length(), since the y values are equal.

-john


--- \mapserver\mapserver-3.7-dev\mapprimitive.c 2003-02-26
12:18:22.000000000 -0800
+++ mapprimitive.c      2003-05-05 13:41:44.000000000 -0700
@@ -950,16 +923,13 @@
        }
       }
     } while(wrong_order);
-
+
     /* Great, now find longest span */
-    point1->y = point2->y = y;
-    for(i=0; i < nfound; i += 2) {
-      point1->x = xintersect[i];
-      point2->x = xintersect[i+1];
-      len = length(*point1, *point2);
+    for(i=0; i < nfound; i +=2) {
+      len = fabs(xintersect[i] - xintersect[i+1]);
       if(len > max_len) {
        max_len = len;
-       lp->x = (point1->x + point2->x)/2;
+       lp->x = (xintersect[i] + xintersect[i+1])/2;
        lp->y = y;
       }
     }



More information about the mapserver-dev mailing list