From 346c336a2dd8b38082fd3864bbb9df01c9a3b0b5 Mon Sep 17 00:00:00 2001 From: David Berry Date: Wed, 9 Sep 2020 09:35:14 +0100 Subject: [PATCH] polygon: Fix problem with polygons that have lots of vertices If the distance between vertices is very short compared to the overall size of the polygon, then the method used for finding an inside point was failing. --- src/polygon.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/polygon.c b/src/polygon.c index e8e55adb..04dddc7b 100644 --- a/src/polygon.c +++ b/src/polygon.c @@ -112,6 +112,14 @@ f - AST_OUTLINE: Create a Polygon outlining values in a pixel array * rounding errors in subsequent code may push the vertices into * neighbouring pixels, which may have bad WCS coords (e.g. * vertices on the boundary of a polar cusp in an HPX map). +* 7-SEP-2020 (DSB): +* - In RegBaseMesh, normalise the each vertex position before using it. +* - In Polywidth, ensure the perpendicular probing line is of infinite +* extent to that it will always reach the other side of the polygon. This +* was a problem for polygons with many vertices separated by very short +* distances (compared to the width of the polygon), as 10 times the length +* of a side (the previous length of the probing line) may not reach all +* the way across the polygon. *class-- */ @@ -4073,6 +4081,7 @@ static double Polywidth( AstFrame *frm, AstLineDef **edges, int i, int nv, /* Create a description of the required line. */ line = astLineDef( frm, start, end ); + line->infinite = 1; /* Loop round every edge, except for the supplied edge. */ for( j = 0; j < nv; j++ ) { @@ -4407,7 +4416,9 @@ static AstPointSet *RegBaseMesh( AstRegion *this_region, int *status ){ end[ 1 ] = vptr[ 1 ][ iv ]; if( lens[ iv ] != AST__BAD ) { -/* Add the position of the starting vertex to the returned mesh. */ +/* Normalise the position of the starting vertex and add it to the returned + mesh (astOffset used below returns normalised positions). */ + astNorm( frm, start ); rptr[ 0 ][ next ] = start[ 0 ]; rptr[ 1 ][ next ] = start[ 1 ]; next++; @@ -4444,6 +4455,7 @@ static AstPointSet *RegBaseMesh( AstRegion *this_region, int *status ){ end[ 0 ] = vptr[ 0 ][ 0 ]; end[ 1 ] = vptr[ 1 ][ 0 ]; if( lens[ 0 ] != AST__BAD ) { + astNorm( frm, start ); rptr[ 0 ][ next ] = start[ 0 ]; rptr[ 1 ][ next ] = start[ 1 ]; next++;