Starlink-AST
view release on metacpan or search on metacpan
ast/src/frameset.c view on Meta::CPAN
* angle (in radians) between the positive direction of the second
* axis and the continuation of the geodesic curve at the requested
* end point. Positive rotation is in the sense of rotation from
* the positive direction of axis 2 to the positive direction of axis 1.
* Notes:
* - The geodesic curve used by this function is the path of
* shortest distance between two points, as defined by the
* astDistance function.
* - An error will be reported if the Frame is not 2-dimensional.
* - This function will return "bad" coordinate values (AST__BAD)
* if any of the input coordinates has this value.
*/
/* Local Variables: */
AstFrame *fr; /* Pointer to current Frame */
AstFrameSet *this; /* Pointer to the FrameSet structure */
double result; /* Value to return */
/* Check the global error status. */
if ( !astOK ) return AST__BAD;
/* Obtain a pointer to the FrameSet structure. */
this = (AstFrameSet *) this_frame;
/* Obtain a pointer to the FrameSet's current Frame and invoke the
astOffset2 method for this Frame. Annul the Frame pointer afterwards. */
fr = astGetFrame( this, AST__CURRENT );
result = astOffset2( fr, point1, angle, offset, point2 );
fr = astAnnul( fr );
/* If an error occurred, clear the result value. */
if ( !astOK ) result = AST__BAD;
/* Return the result. */
return result;
}
static void Overlay( AstFrame *template_frame, const int *template_axes,
AstFrame *result, int *status ) {
/*
* Name:
* Overlay
* Purpose:
* Overlay the attributes of a template FrameSet on to another Frame.
* Type:
* Private function.
* Synopsis:
* #include "frameset.h"
* void Overlay( AstFrame *template, const int *template_axes,
* AstFrame *result, int *status )
* Class Membership:
* FrameSet member function (over-rides the protected astOverlay
* method inherited from the Frame class).
* Description:
* This function overlays attributes from the current Frame of a
* FrameSet on to another Frame, so as to over-ride selected
* attributes of that second Frame. Normally only those attributes
* which have been specifically set in the template will be
* transferred. This implements a form of defaulting, in which a
* Frame acquires attributes from the template, but retains its
* original attributes (as the default) if new values have not
* previously been explicitly set in the template.
* Parameters:
* template
* Pointer to the template FrameSet, for whose current Frame
* values should have been explicitly set for any attribute
* which is to be transferred.
* template_axes
* Pointer to an array of int, with one element for each axis of
* the "result" Frame (see below). For each axis in the result
* frame, the corresponding element of this array should contain
* the (zero-based) index of the axis in the current Frame of
* the template FrameSet to which it corresponds. This array is
* used to establish from which template Frame axis any
* axis-dependent attributes should be obtained.
*
* If any axis in the result Frame is not associated with a
* template Frame axis, the corresponding element of this array
* should be set to -1.
*
* If a NULL pointer is supplied, the template and result axis
* indices are assumed to be identical.
* result
* Pointer to the Frame which is to receive the new attribute values.
* status
* Pointer to the inherited status variable.
*/
/* Local Variables: */
AstFrame *fr; /* Pointer to current Frame */
AstFrameSet *template; /* Pointer to the FrameSet structure */
/* Check the global error status. */
if ( !astOK ) return;
/* Obtain a pointer to the FrameSet structure. */
template = (AstFrameSet *) template_frame;
/* Obtain a pointer to the current Frame and invoke its astOverlay
method to overlay its attributes. Annul the Frame pointer
afterwards. */
fr = astGetFrame( template, AST__CURRENT );
astOverlay( fr, template_axes, result );
fr = astAnnul( fr );
}
static void PermAxes( AstFrame *this_frame, const int perm[], int *status ) {
/*
* Name:
* PermAxes
* Purpose:
* Permute the order of a FrameSet's axes.
* Type:
* Private function.
* Synopsis:
* #include "frameset.h"
* void PermAxes( AstFrame *this, const int perm[], int *status )
* Class Membership:
* FrameSet member function (over-rides the astPermAxes method
* inherited from the Frame class).
* Description:
* This function permutes the order in which the axes in the
* current Frame of a FrameSet occur.
* Parameters:
* this
* Pointer to the FrameSet.
* perm
* An array of int (with one element for each axis of the
* FrameSet's current Frame) which lists the axes in their new
* order. Each element of this array should be a (zero-based)
* axis index identifying the axes according to their old
* (un-permuted) order.
* status
* Pointer to the inherited status variable.
* Notes:
* - Only genuine permutations of the axis order are permitted, so
* each axis must be referenced exactly once in the "perm" array.
* - If more than one axis permutation is applied to the same Frame
* in a FrameSet, the effects are cumulative.
*/
/* Local Variables: */
AstFrame *fr; /* Pointer to current Frame */
AstFrameSet *this; /* Pointer to the FrameSet structure */
AstPermMap *map; /* Pointer to axis permutation Mapping */
int *invperm; /* Pointer to inverse permutation array */
int axis; /* Loop counter for axes */
int naxes; /* Number of FrameSet axes */
/* Check the global error status. */
if ( !astOK ) return;
/* Obtain a pointer to the FrameSet structure. */
ast/src/frameset.c view on Meta::CPAN
this. */
invert = this->invert[ ( fwd ? inode : inode1 ) - 1 ];
if ( invert != astGetInvert( map[ nextra ] ) ) {
forward[ nextra ] = !forward[ nextra ];
}
/* If inode1 is associated with a non-unit Frame Mapping, add the Frame
Mapping in as the first Mapping in the returned list. The "forward" value
is irrelevant since the forward and inverse transformations of Frames
are the same. */
if( nextra ) {
result++;
*map = (AstMapping *) frame;
*forward = 1;
if( frm ) *frm = NULL;
}
/* Quit searching once a path has been found. */
break;
}
}
}
}
}
/* Return the result, which is one more than the number of mappings
found (i.e. steps in the path), or zero if no path was found (this
should only occur when invoked recursively to explore an
unsuccessful sub-path). */
return result;
}
static int SubFrame( AstFrame *this_frame, AstFrame *template,
int result_naxes,
const int *target_axes, const int *template_axes,
AstMapping **map, AstFrame **result, int *status ) {
/*
* Name:
* SubFrame
* Purpose:
* Select axes from a FrameSet and convert to the new coordinate system.
* Type:
* Private function.
* Synopsis:
* #include "frameset.h"
* int SubFrame( AstFrame *target, AstFrame *template, int result_naxes,
* const int *target_axes, const int *template_axes,
* AstMapping **map, AstFrame **result, int *status )
* Class Membership:
* FrameSet member function (over-rides the protected astSubFrame
* method inherited from the Frame class).
* Description:
* This function selects a requested sub-set (or super-set) of the
* axes from the current Frame of a "target" FrameSet and creates a
* new Frame with copies of the selected axes assembled in the
* requested order. It then optionally overlays the attributes of a
* "template" Frame on to the result. It returns both the resulting
* Frame and a Mapping that describes how to convert between the
* coordinate systems described by the current Frame of the target
* FrameSet and the result Frame. If necessary, this Mapping takes
* account of any differences in the Frames' attributes due to the
* influence of the template.
* Parameters:
* target
* Pointer to the target FrameSet, from whose current Frame the
* axes are to be selected.
* template
* Pointer to the template Frame, from which new attributes for
* the result Frame are to be obtained. Optionally, this may be
* NULL, in which case no overlaying of template attributes will
* be performed.
* result_naxes
* Number of axes to be selected from the target FrameSet. This
* number may be greater than or less than the number of axes in
* the FrameSet's current Frame (or equal).
* target_axes
* Pointer to an array of int with result_naxes elements, giving
* a list of the (zero-based) axis indices of the axes to be
* selected from the current Frame of the target FrameSet. The
* order in which these are given determines the order in which
* the axes appear in the result Frame. If any of the values in
* this array is set to -1, the corresponding result axis will
* not be derived from the target FrameSet, but will be assigned
* default attributes instead.
* template_axes
* Pointer to an array of int with result_naxes elements. This
* should contain a list of the template axes (given as
* zero-based axis indices) with which the axes of the result
* Frame are to be associated. This array determines which axes
* are used when overlaying axis-dependent attributes of the
* template on to the result. If any element of this array is
* set to -1, the corresponding result axis will not receive any
* template attributes.
*
* If the template argument is given as NULL, this array is not
* used and a NULL pointer may also be supplied here.
* map
* Address of a location to receive a pointer to the returned
* Mapping. The forward transformation of this Mapping will
* describe how to convert coordinates from the coordinate
* system described by the current Frame of the target FrameSet
* to that described by the result Frame. The inverse
* transformation will convert in the opposite direction.
* result
* Address of a location to receive a pointer to the result Frame.
* status
* Pointer to the inherited status variable.
* Returned Value:
* A non-zero value is returned if coordinate conversion is
* possible between the current Frame of the target FrameSet and
* the result Frame. Otherwise zero is returned and *map and
* *result are returned as NULL (but this will not in itself result
* in an error condition). In general, coordinate conversion should
* always be possible if no template Frame is supplied but may not
* always be possible otherwise.
* Notes:
* - A value of zero will be returned if this function is invoked
* with the global error status set, or if it should fail for any
* reason.
*/
/* Local Variables: */
AstFrame *fr; /* Pointer to FrameSet's current Frame */
AstFrameSet *this; /* Pointer to the FrameSet structure */
int match; /* Result to be returned */
/* Initialise. */
*map = NULL;
*result = NULL;
match = 0;
/* Check the global error status. */
if ( !astOK ) return match;
/* Obtain a pointer to the FrameSet structure. */
this = (AstFrameSet *) this_frame;
/* Obtain a pointer to the FrameSet's current Frame. */
fr = astGetFrame( this, AST__CURRENT );
/* Invoke the astSubFrame method for this Frame. */
match = astSubFrame( fr, template, result_naxes, target_axes, template_axes,
map, result );
/* Annul the Frame pointer. */
fr = astAnnul( fr );
/* If an error occurred, clean up by annulling any returned objects and clear
( run in 0.984 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )