From 1ba18e178d458914570adf53c16326b0f9f3ed4b Mon Sep 17 00:00:00 2001 From: David Berry Date: Thu, 28 Oct 2021 18:11:51 +0100 Subject: [PATCH] region: Use astNormPoints to avoid longitude jumps in region meshes --- ast.news | 4 ++++ src/frame.c | 4 ++-- src/region.c | 20 ++++++++++++++++++++ sun_master.tex | 4 ++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ast.news b/ast.news index cbb8c568..72400036 100644 --- a/ast.news +++ b/ast.news @@ -26,6 +26,10 @@ system. The most common usage will be to modify vectors of sky position in such a way as to avoid sudden jumps of 360 degrees in longitude within groups of points that span the longitude origin. +- The mesh of points returned by astGetRegionMesh and astShowMesh are now +normalised to avoid discontinuities in celestial longitude. This uses the +new astNormPoints methid described in the previous item. + - A bug has been fixed in the KeyMap class that caused astMapGet1 functions to return a vector length of 1 for KeyMap entries with an undefined value. A vector length of zero is now returned in such cases. diff --git a/src/frame.c b/src/frame.c index 22f7489c..a2310c63 100644 --- a/src/frame.c +++ b/src/frame.c @@ -8204,7 +8204,7 @@ static AstPointSet *NormalPoints( AstFrame *this, AstPointSet *in, int contig, for ( point = 0; point < npoint; point++ ) { /* Copy the axis values at the current point into the buffer. */ - for ( coord = 0; coord < ncoord_in; coord++ ) { + for ( coord = 0; coord < naxes; coord++ ) { buf[ coord ] = ptr_in[ coord ][ point ]; } @@ -8212,7 +8212,7 @@ static AstPointSet *NormalPoints( AstFrame *this, AstPointSet *in, int contig, astNorm( this, buf ); /* Copy the normalised values to the output pointset. */ - for ( coord = 0; coord < ncoord_out; coord++ ) { + for ( coord = 0; coord < naxes; coord++ ) { ptr_out[ coord ][ point ] = buf[ coord ]; } } diff --git a/src/region.c b/src/region.c index 5eabf743..5586041f 100644 --- a/src/region.c +++ b/src/region.c @@ -267,6 +267,9 @@ f - AST_SHOWMESH: Display a mesh of points on the surface of a Region * is cleared in the copy. This means that if a component Region within * a CmpRegion is copied, a dump of the resulting copy will include the * FrameSet. +* 28-OCT-2021 (DSB): +* Modified astGetRegionMesh so that meshes for SkyFrame regions that cross +* zero longitude do not include jumps of 2.PI in logitude. *class-- * Implementation Notes: @@ -9317,12 +9320,17 @@ f The global status. * original to new coordinate system is non-linear, the shape within * the new coordinate system may be distorted, and so may not match * that implied by the name of the Region subclass (Circle, Box, etc). +* - If the Region defines an area within a SkyFrame that traverses +* zero longitude, the returned positions will be normalised to avoid +* jumps of 2.PI radians in longitude (i.e. it will include longitude +* values less than zero or greater than 2.PI). *-- */ /* Local Variables: */ AstPointSet *pset; /* PointSet holding mesh/grid axis values */ + AstPointSet *temp; /* PointSet holding normalised mesh/grid axis values */ double **ptr; /* Pointer to mesh/grid axes values */ double *p; /* Pointer to next input axis value */ double *q; /* Pointer to next output axis value */ @@ -9351,12 +9359,18 @@ f The global status. } else { pset = astRegBaseGrid( this ); } + } else { if( surface ) { pset = astRegMesh( this ); } else { pset = astRegGrid( this ); } + +/* Normalise the points to avoid discontinuities (e.g. at zero longitude). */ + temp = astNormalPoints( this, pset, 1, NULL ); + pset = astAnnul( pset ); + pset = temp; } /* Return the number of points in the mesh or grid. */ @@ -10947,6 +10961,7 @@ f The global status. /* Local Variables: */ AstPointSet *ps; /* PointSet holding mesh */ + AstPointSet *temp; /* PointSet holding normalised mesh */ char *buffer = NULL; /* Buffer for line output text */ char buf[ 40 ]; /* Buffer for floating poitn value */ double **ptr; /* Pointers to the mesh data */ @@ -10963,6 +10978,11 @@ f The global status. ps = astRegMesh( this ); if( ps ) { +/* Normalise it to avoid discontinuities in longitude etc */ + temp = astNormalPoints( this, ps, 1, NULL ); + ps = astAnnul( ps ); + ps = temp; + /* Get the number of axis values per position, and the number of positions. */ nax = astGetNcoord( ps ); np = astGetNpoint( ps ); diff --git a/sun_master.tex b/sun_master.tex index 5925f503..ad78d528 100644 --- a/sun_master.tex +++ b/sun_master.tex @@ -22472,6 +22472,10 @@ \subsection{\xlabel{changes}\xlabel{list_of_most_recent_changes}Changes in such a way as to avoid sudden jumps of 360 degrees in longitude within groups of points that span the longitude origin. +- The mesh of points returned by astGetRegionMesh and astShowMesh are now +normalised to avoid discontinuities in celestial longitude. This uses the +new astNormPoints methid described in the previous item. + \item A bug has been fixed in the KeyMap class that caused astMapGet1 functions to return a vector length of 1 for KeyMap entries with an undefined value. A vector length of zero is now returned in such cases.