/ MapServer Public
Fix orientation of "vertex" geomtransform (#5213)
dmorissette authored and tbonfort committed Feb 24, 2016
Showing 1 changed file with 24 additions and 6 deletions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
@@ -83,12 +83,30 @@ double calcOrientation(pointObj *p1, pointObj *p2)

double calcMidAngle(pointObj *p1, pointObj *p2, pointObj *p3)
{
double theta1,theta2;
theta1 = atan2(p1->x-p2->x,p1->y-p2->y);
if(theta1<0) theta1 += MS_2PI;
theta2 = atan2(p3->x-p2->x,p3->y-p2->y);
if(theta2<0) theta2 += MS_2PI;
pointObj p1n;
double dx12, dy12, dx23, dy23, l12, l23;

/* We treat both segments as vector 1-2 and vector 2-3 and
* compute their dx,dy and length
*/
dx12 = p2->x - p1->x;
dy12 = p2->y - p1->y;
l12 = sqrt(dx12*dx12 + dy12*dy12);
dx23 = p3->x - p2->x;
dy23 = p3->y - p2->y;
l23 = sqrt(dx23*dx23 + dy23*dy23);

/* Normalize length of vector 1-2 to same as length of vector 2-3 */
if (l12 > 0.0)
{
p1n.x = p2->x - dx12*(l23/l12);
p1n.y = p2->y - dy12*(l23/l12);
}
else
p1n = *p2; /* segment 1-2 is 0-length, use segment 2-3 for orientation */

/* Return the orientation defined by the sum of the normalized vectors */
return calcOrientation(&p1n, p3);
}

/*