Click or drag to resize

Evaluators And Evaluator Groups

DME Component Libraries makes extensive use of the "evaluator pattern" throughout the library. Almost any computation in DME Component Libraries makes use of the evaluator pattern. Evaluators generally represent a function of time, that is, a function that takes as input time, and produces as output a specific type of value.

Using Evaluators

Evaluators are created from definitional objects. A definitional object does not actually do any computations itself. Instead, it allows you to configure an object in the modeled world and then obtain an evaluator with which to do computations relating to that object.

As an example, AxesLinearRate is a definitional object that represents a set of axes that rotate with a linear (or constant) rate. We can construct an instance of this type that rotates with a constant rate relative to the J2000 axes:

C#
AxesLinearRate axes = new AxesLinearRate
{
    ReferenceAxes = CentralBodiesFacet.GetFromContext().Earth.J2000Frame.Axes,
    ReferenceEpoch = TimeConstants.J2000,
    InitialRotation = UnitQuaternion.Identity,
    InitialRotationalVelocity = 0.1,
    RotationalAcceleration = 0.0,
    SpinAxis = new UnitCartesian(1.0, 0.0, 0.0)
};

The axes object we have just created has a different orientation relative to J2000 at different times. In order to evaluate the rotation from J2000 to our axes at a given time, we first obtain an evaluator:

C#
AxesEvaluator evaluator = axes.GetEvaluator();

We can then evaluate the evaluator at different times:

C#
JulianDate date = new GregorianDate(2007, 11, 20, 12, 0, 0.0).ToJulianDate();
UnitQuaternion rotationFromJ2000 = evaluator.Evaluate(date);

As in this example, evaluators are always created by calling a method on a definitional object. For simple objects with only one thing to evaluate, as in the example above, this method is generally called GetEvaluator. More complicated objects, such as CentralBody, might have multiple methods that return different evaluators.

Once an evaluator has been created from a definitional object, changes to the definitional object will not affect the results computed by the evaluator. To obtain new results after changing properties of a definitional object, obtain a new evaluator. For example:

C#
AxesLinearRate axes = new AxesLinearRate
{
    ReferenceAxes = CentralBodiesFacet.GetFromContext().Earth.J2000Frame.Axes,
    ReferenceEpoch = TimeConstants.J2000,
    InitialRotation = UnitQuaternion.Identity,
    InitialRotationalVelocity = 0.1,
    RotationalAcceleration = 0.0,
    SpinAxis = new UnitCartesian(1.0, 0.0, 0.0)
};

AxesEvaluator evaluator = axes.GetEvaluator();

// Evaluate the rotation at a specific time.
JulianDate date = new GregorianDate(2007, 11, 20, 12, 0, 0.0).ToJulianDate();
UnitQuaternion rotationFromJ2000 = evaluator.Evaluate(date);

// Change the axes to spin around the Y-axis instead of the X-axis.
axes.SpinAxis = new UnitCartesian(0.0, 1.0, 0.0);

// Evaluate the rotation at the same time.
UnitQuaternion sameRotationFromJ2000 = evaluator.Evaluate(date);

// rotationFromJ2000 and sameRotationFromJ2000 are identical, even though
// the spin axis of the definition object has changed.  The evaluator has
// ignored the change.

// Reobtain the evaluator, and evaluate using the new evaluator.
evaluator = axes.GetEvaluator();
UnitQuaternion differentRotationFromJ2000 = evaluator.Evaluate(date);

// rotationFromJ2000 and differentRotationFromJ200 are different, reflecting
// the change in the spin axis.

All evaluators implement IThreadAware. In short, this means that an evaluator may or may not be safe to evaluate from multiple threads simultaneously. Check the IsThreadSafe property to determine if a particular evaluator is thread-safe. If it is not, then use CopyForAnotherThreadCopyT to make a copy of the evaluator for each thread in which it is to be used. See the Multithreading topic for more information on IThreadAware.

Using Evaluator Groups

EvaluatorGroups enable more efficient evaluation of evaluators by eliminating redundant computations.

Frequently, an evaluator uses one or more other evaluators to do its computation. For example, CentralBodyObserveCartographicPoint returns an evaluator that evaluates the longitude, latitude, and height of a given Point relative to the central body at a given time. In order to do so, it must find the position of the point in the central body's FixedFrame, then transform that Cartesian position to a Cartographic position. This requires evaluating a PointEvaluator, then, if the Point is not expressed in the FixedFrame already, it must calculate the transformation between the frames at the given time.

Often, these nested evaluators are shared between multiple top-level evaluators. For example, if you are observing the cartographic position of two SGP4-propagated satellites, the transformation from the SGP4 propagator's reference frame to the fixed frame must be done for both satellites. If both evaluators are evaluated at the same time, it would be inefficient to compute the reference frame transformation twice.

EvaluatorGroup provides an automatic mechanism for eliminating such redundant computations. By passing the same EvaluatorGroup to the CentralBodyObserveCartographicPoint method when requesting the evaluator for each satellite, the resulting evaluators will perform any common computations between the two evaluators just once for a given time.

C#
Point point1 = CreateSatellite1Point();
Point point2 = CreateSatellite2Point();

EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;

EvaluatorGroup group = new EvaluatorGroup();
MotionEvaluator<Cartographic> evaluator1 = earth.ObserveCartographicPoint(point1, group);
MotionEvaluator<Cartographic> evaluator2 = earth.ObserveCartographicPoint(point2, group);

// Update the reference to each evaluator using the evaluator group.
// This will optimize the evaluators by removing any redundancy.
evaluator1 = group.UpdateReference(evaluator1);
evaluator2 = group.UpdateReference(evaluator2);

// evaluator1 and evaluator2 will share redundant computations.

Note that this is only helpful if the two evaluators are frequently evaluated at the same JulianDate. Otherwise, putting both evaluators in the same EvaluatorGroup will offer no benefit and in fact may have a small performance cost.

Implementing Custom Evaluators

The following discussion details the various pieces and parts involved in implementing the Evaluator pattern successfully. It discusses the various abstract and virtual methods which you should implement, what they do, and what sort of things to watch out for in order to ensure good performance and thread safety. Code samples are provided which should allow you a complete picture of a typical evaluator. At the end, you should have all the code necessary to create custom implementations which can seamlessly integrate your algorithms into the rest of DME Component Libraries.

Evaluator Construction

Most definitional object classes in the library (e.g. Point, AccessConstraint, etc.) have an abstract method which is responsible for producing an Evaluator for the object. Along with acting as a 'factory method' for the corresponding Evaluator, the method is also responsible for handling EvaluatorGroups. EvaluatorGroups serve to eliminate redundant calculations when creating Evaluators within Evaluators, and can optimize performance by determining which Evaluators should cache their previous value.

In the example below, the GetEvaluator1 method calls CreateEvaluator on the EvaluatorGroup. If an Evaluator from 'this' object instance with the given parameters was already created in the group, the preexisting instance is returned and the CreateEvaluator1 instance method is never called. Otherwise, it calls the CreateEvaluator1 instance method to create the Evaluator. Note that the "inner evaluators" are all constructed inside the "CreateEvaluator" method. This is to avoid extra calls in the event that the evaluator already exists, since, by necessity, the inner evaluators already exist as well.

C#
public Evaluator<double> GetEvaluator1(EvaluatorGroup group, Point point, IList<Scalar> scalars)
{
    return group.CreateEvaluator<Evaluator<double>, Point, IList<Scalar>, double, IList<int>>(
        CreateEvaluator1, point, scalars, m_propertyOne, m_propertyList);
}

// Create all the inner evaluators in this method so that they are only called once.
// Make sure the parameters along with the surrounding class instance specify a unique key
// to identify the evaluator in the EvaluatorGroup.
private Evaluator<double> CreateEvaluator1(EvaluatorGroup group, Point point, IList<Scalar> scalars,
                                           double argumentOne, IList<int> argumentList)
{
    PointEvaluator pointEvaluator = point.GetEvaluator(group);
    List<MotionEvaluator<double>> scalarEvaluators = new List<MotionEvaluator<double>>(scalars.Count);
    foreach (Scalar scalar in scalars)
    {
        scalarEvaluators.Add(scalar.GetEvaluator(group));
    }

    Ellipsoid immutableEarth = CentralBodiesFacet.GetFromContext().Earth.Shape;
    // Make sure to copy any lists to ensure that they cannot be modified outside the evaluator
    argumentList = new List<int>(argumentList);
    return new SampleEvaluator(group, pointEvaluator, scalarEvaluators, argumentOne, immutableEarth, argumentList);
}

When constructing an Evaluator, make sure that all of the members stored in the Evaluator are either other Evaluator types, value types, or immutable reference types. An Evaluator should never be constructed with a reference type which could be altered externally to the Evaluator, affecting the calculation. Lists of immutable types are safe so long as there is no reference to the List outside of the Evaluator and the lists are handled in a thread-safe manner during evaluation.

C#
// Initialize a new instance based on the given inner evaluator.
// Note that the arguments must be guaranteed not to change behind the
// evaluator's back.  Otherwise, this evaluator will not behave correctly
// when used in EvaluatorGroups.
public SampleEvaluator(EvaluatorGroup group,
                       MotionEvaluator<Cartesian> innerEvaluatorOne,
                       IList<MotionEvaluator<double>> innerEvaluatorList,
                       double argumentOne,
                       Ellipsoid argumentTwo,
                       IList<int> argumentList)
    : base(group)
{
    m_innerEvaluatorOne = innerEvaluatorOne;
    m_innerEvaluatorList = innerEvaluatorList;
    m_argumentList = argumentList;
    m_argumentOne = argumentOne;
    m_immutableShape = argumentTwo;
}

private readonly double m_argumentOne;
private readonly Ellipsoid m_immutableShape;
private readonly IList<int> m_argumentList;
private MotionEvaluator<Cartesian> m_innerEvaluatorOne;
private readonly IList<MotionEvaluator<double>> m_innerEvaluatorList;
private bool m_isDisposed;
Reporting Thread Safety

Every Evaluator implements the IThreadAware interface. When spawning new computation threads, this is used to make sure Evaluators (and their data) are updated or copied correctly to ensure thread safety. If IsThreadSafe returns false, the Evaluator is copied, usually with an instance of CopyForAnotherThread. If IsThreadSafe is true, the existing instance is shared across the computation threads. Note that when implementing IsThreadSafe, you should check to make sure that any member objects which implement IThreadAware are thread-safe. Also, the UpdateEvaluatorReferences method will be used by the EvaluatorGroup when optimizing performance after all the Evaluators have been constructed.

In the copy constructor, the CopyContext is used to update the members of the evaluator. The context then can control whether each object will be copied or not, and maintain a mapping between the old and new object to ensure that objects are replaced consistently across an object graph. For example, CopyForAnotherThread will copy objects which are not thread-safe. The context is also used when optimizing Evaluators, to replace evaluators with caching versions. If you have a custom data structure being used as data in an Evaluator, you can implement ICloneWithContext for that data structure and follow the pattern explained in the documentation for that interface.

C#
// Copy constructor which updates the object references based on the given context
// This is important for copying evaluators when using multiple threads
private SampleEvaluator(SampleEvaluator existingInstance, CopyContext context)
    : base(existingInstance, context)
{
    m_argumentOne = existingInstance.m_argumentOne;
    m_immutableShape = context.UpdateReference(existingInstance.m_immutableShape);
    // If the evaluator modifies the list, copy it.
    // Otherwise, simply update the reference.
    m_argumentList = context.UpdateReference(existingInstance.m_argumentList);

    m_innerEvaluatorOne = existingInstance.m_innerEvaluatorOne;
    m_innerEvaluatorList = existingInstance.m_innerEvaluatorList;
    UpdateEvaluatorReferences(context);
}

// This method is used to update the references between evaluators when optimizing
// their dependencies with an EvaluatorGroup.  This makes sure that the each unique
// calculation is only performed once at a given time.
public override void UpdateEvaluatorReferences(CopyContext context)
{
    m_innerEvaluatorOne = context.UpdateReference(m_innerEvaluatorOne);
    EvaluatorHelper.UpdateCollectionReferences(m_innerEvaluatorList, context);
}

// Clone this evaluator
public override object Clone(CopyContext context)
{
    return new SampleEvaluator(this, context);
}

// This property indicates whether this evaluator includes any non-thread-safe operations.
// If there is any File I/O, shared collections, or if any of the inner evaluators are
// not thread-safe this evaluator needs to be copied before being used in another thread.
public override bool IsThreadSafe
{
    get
    {
        return m_innerEvaluatorOne.IsThreadSafe &&
               EvaluatorHelper.AllEvaluatorsAreThreadSafe(m_innerEvaluatorList);
    }
}
Availability of Data

Since most Evaluators are comprised of inner evaluators, it is important to understand over which time intervals an evaluator is valid. If an inner evaluator has an inner evaluator (etc., etc.) which has a limited set of data (e.g. an Evaluator created from an StkEphemerisFile), the top evaluator needs a way of reporting this to calling code. The IAvailability interface handles this.

C#
// This method checks whether this calculation can produce a valid value at the given
// time.  For example, if an evaluator has ephemeris data which spans over certain times,
// the evaluator is not "available" at times where there is no data.
public override bool IsAvailable(JulianDate date)
{
    return EvaluatorHelper.AllEvaluatorsAreAvailable(date, m_innerEvaluatorOne) &&
           EvaluatorHelper.AllEvaluatorsAreAvailable(date, m_innerEvaluatorList);
}

// This method produces the time intervals when this evaluator can produce a valid value.
public override TimeIntervalCollection GetAvailabilityIntervals(TimeIntervalCollection consideredIntervals)
{
    consideredIntervals = EvaluatorHelper.GetAvailabilityIntervals(consideredIntervals, m_innerEvaluatorOne);
    consideredIntervals = EvaluatorHelper.GetAvailabilityIntervals(consideredIntervals, m_innerEvaluatorList);
    return consideredIntervals;
}
What if the Evaluator Represents a Constant?

Since some Evaluators always return a single value, the IIsTimeVarying interface checks to see whether it is possible to optimize performance by eliminating extra calls. Care should be taken when setting this value to false. Even if all the inner evaluators return false, if the current evaluation uses time at all, IsTimeVarying should return true. The only time that an evaluator can explicitly return false is if it does not use the time parameter at all, including feeding the time to inner evaluators. If unsure, it's always safe to return true, since you are guaranteed correct results at the cost of performance.

C#
// This property indicates whether the value produced by this evaluator is
// independent of time, in which case a constant value is recorded rather
// than continuously reevaluating
public override bool IsTimeVarying
{
    // If the "Evaluate" method does not use the "date" in its
    // calculation, except to pass it to an inner evaluator,
    // then simply return: m_innerEvaluatorOne.IsTimeVarying
    // Otherwise return: true
    get { return true; }
}
Dispose Pattern

Most Evaluators include the 'dispose pattern' in order to make sure that any references to system resources are disposed in a timely manner. Make sure to dispose of any local resources and call dispose on any inner evaluators.

C#
// When this evaluator is no longer used, it calls dispose on any inner evaluators
// to make sure that any resources are released in a timely manner.
protected override void Dispose(bool disposing)
{
    if (m_isDisposed || !disposing)
        return;

    m_isDisposed = true;

    m_innerEvaluatorOne.Dispose();
    EvaluatorHelper.Dispose(m_innerEvaluatorList);
}
Performance Enhancement

In order to allow Evaluators to be created in a flexible manner, Evaluators are typically composed together into hierarchies of computation. In many cases, computations can be shared (e.g. Earth Fixed to Earth Inertial transformations). Evaluator caching allows these complex computations to remain efficient despite their complexity. If an Evaluator is shared between two or more other Evaluators, an EvaluatorGroup will call the following method to create a caching wrapper, then replace the existing Evaluator with the caching evaluator in all other Evaluators which use it. In most cases, the base class provides an implementation, but if other evaluators require a derived evaluator type (e.g. SampleEvaluator) instead of an instance of the base class, you will need to implement a caching wrapper of the correct type to prevent a casting exception. Generally, this is only necessary if the public "GetEvaluator" methods return instances of a derived evaluator type.

C#
// When an EvaluatorGroup determines that this evaluator is used by two or more
// evaluators, the result of the 'Evaluate' method is cached so that the calculation
// is only performed once for each time.
// If you don't want any other evaluators to cache this evaluator's value,
// simply return this instance instead of using the caching wrapper.
public override IEvaluator GetCachingWrapper()
{
    return new CachingEvaluator<double>(this);
}

If you want to ensure that no caching occurs for a particular Evaluator, you can overload this method to simply return the existing instance.

The Algorithm Itself

Lastly, the core of the evaluator implementation is the Evaluate call which contains the algorithm to compute. Provided that the rest of the Evaluator is implemented carefully and IsThreadSafe returns the correct value, it is not necessary to perform any locking to ensure thread safety. However, because of performance improvements involving caching, the value returned for a given JulianDate should never change. Otherwise, the caching will not reflect changes in the value.

C#
// This is where the evaluator performs its calculation.
// There are a few things to note for the implementation:
// + The result should always be the same when fed in the same 'date'.
// + Avoid any calls to non-immutable objects.
// + Thread safety is handled for the user unless the user adds any
//   specifically un-thread-safe operations.  In which case, the user
//   should modify the "IsThreadSafe" property to return 'false'.
public override double Evaluate(JulianDate date)
{
    double maximum = 0;
    for (int i = 0; i < m_innerEvaluatorList.Count; i++)
    {
        // MotionEvaluators allow you to obtain derivatives...
        Motion<double> scalarResult = m_innerEvaluatorList[i].Evaluate(date, 1);
        // ...but it is not guaranteed to return the requested order, so make sure to check
        if (scalarResult.Order > 0 && scalarResult.FirstDerivative > maximum)
        {
            maximum = scalarResult.Value;
        }
    }

    Cartographic position = m_immutableShape.CartesianToCartographic(m_innerEvaluatorOne.Evaluate(date));
    return position.Height * Math.Min(maximum, m_argumentOne);
}
Presenting a Sample Evaluator

Here is what the complete code looks like:

C#
private sealed class SampleEvaluator : Evaluator<double>
{

    // Initialize a new instance based on the given inner evaluator.
    // Note that the arguments must be guaranteed not to change behind the
    // evaluator's back.  Otherwise, this evaluator will not behave correctly
    // when used in EvaluatorGroups.
    public SampleEvaluator(EvaluatorGroup group,
                           MotionEvaluator<Cartesian> innerEvaluatorOne,
                           IList<MotionEvaluator<double>> innerEvaluatorList,
                           double argumentOne,
                           Ellipsoid argumentTwo,
                           IList<int> argumentList)
        : base(group)
    {
        m_innerEvaluatorOne = innerEvaluatorOne;
        m_innerEvaluatorList = innerEvaluatorList;
        m_argumentList = argumentList;
        m_argumentOne = argumentOne;
        m_immutableShape = argumentTwo;
    }

    private readonly double m_argumentOne;
    private readonly Ellipsoid m_immutableShape;
    private readonly IList<int> m_argumentList;
    private MotionEvaluator<Cartesian> m_innerEvaluatorOne;
    private readonly IList<MotionEvaluator<double>> m_innerEvaluatorList;
    private bool m_isDisposed;



    // Copy constructor which updates the object references based on the given context
    // This is important for copying evaluators when using multiple threads
    private SampleEvaluator(SampleEvaluator existingInstance, CopyContext context)
        : base(existingInstance, context)
    {
        m_argumentOne = existingInstance.m_argumentOne;
        m_immutableShape = context.UpdateReference(existingInstance.m_immutableShape);
        // If the evaluator modifies the list, copy it.
        // Otherwise, simply update the reference.
        m_argumentList = context.UpdateReference(existingInstance.m_argumentList);

        m_innerEvaluatorOne = existingInstance.m_innerEvaluatorOne;
        m_innerEvaluatorList = existingInstance.m_innerEvaluatorList;
        UpdateEvaluatorReferences(context);
    }

    // This method is used to update the references between evaluators when optimizing
    // their dependencies with an EvaluatorGroup.  This makes sure that the each unique
    // calculation is only performed once at a given time.
    public override void UpdateEvaluatorReferences(CopyContext context)
    {
        m_innerEvaluatorOne = context.UpdateReference(m_innerEvaluatorOne);
        EvaluatorHelper.UpdateCollectionReferences(m_innerEvaluatorList, context);
    }

    // Clone this evaluator
    public override object Clone(CopyContext context)
    {
        return new SampleEvaluator(this, context);
    }

    // This property indicates whether this evaluator includes any non-thread-safe operations.
    // If there is any File I/O, shared collections, or if any of the inner evaluators are
    // not thread-safe this evaluator needs to be copied before being used in another thread.
    public override bool IsThreadSafe
    {
        get
        {
            return m_innerEvaluatorOne.IsThreadSafe &&
                   EvaluatorHelper.AllEvaluatorsAreThreadSafe(m_innerEvaluatorList);
        }
    }



    // This is where the evaluator performs its calculation.
    // There are a few things to note for the implementation:
    // + The result should always be the same when fed in the same 'date'.
    // + Avoid any calls to non-immutable objects.
    // + Thread safety is handled for the user unless the user adds any
    //   specifically un-thread-safe operations.  In which case, the user
    //   should modify the "IsThreadSafe" property to return 'false'.
    public override double Evaluate(JulianDate date)
    {
        double maximum = 0;
        for (int i = 0; i < m_innerEvaluatorList.Count; i++)
        {
            // MotionEvaluators allow you to obtain derivatives...
            Motion<double> scalarResult = m_innerEvaluatorList[i].Evaluate(date, 1);
            // ...but it is not guaranteed to return the requested order, so make sure to check
            if (scalarResult.Order > 0 && scalarResult.FirstDerivative > maximum)
            {
                maximum = scalarResult.Value;
            }
        }

        Cartographic position = m_immutableShape.CartesianToCartographic(m_innerEvaluatorOne.Evaluate(date));
        return position.Height * Math.Min(maximum, m_argumentOne);
    }



    // This method checks whether this calculation can produce a valid value at the given
    // time.  For example, if an evaluator has ephemeris data which spans over certain times,
    // the evaluator is not "available" at times where there is no data.
    public override bool IsAvailable(JulianDate date)
    {
        return EvaluatorHelper.AllEvaluatorsAreAvailable(date, m_innerEvaluatorOne) &&
               EvaluatorHelper.AllEvaluatorsAreAvailable(date, m_innerEvaluatorList);
    }

    // This method produces the time intervals when this evaluator can produce a valid value.
    public override TimeIntervalCollection GetAvailabilityIntervals(TimeIntervalCollection consideredIntervals)
    {
        consideredIntervals = EvaluatorHelper.GetAvailabilityIntervals(consideredIntervals, m_innerEvaluatorOne);
        consideredIntervals = EvaluatorHelper.GetAvailabilityIntervals(consideredIntervals, m_innerEvaluatorList);
        return consideredIntervals;
    }



    // This property indicates whether the value produced by this evaluator is
    // independent of time, in which case a constant value is recorded rather
    // than continuously reevaluating
    public override bool IsTimeVarying
    {
        // If the "Evaluate" method does not use the "date" in its
        // calculation, except to pass it to an inner evaluator,
        // then simply return: m_innerEvaluatorOne.IsTimeVarying
        // Otherwise return: true
        get { return true; }
    }



    // When this evaluator is no longer used, it calls dispose on any inner evaluators
    // to make sure that any resources are released in a timely manner.
    protected override void Dispose(bool disposing)
    {
        if (m_isDisposed || !disposing)
            return;

        m_isDisposed = true;

        m_innerEvaluatorOne.Dispose();
        EvaluatorHelper.Dispose(m_innerEvaluatorList);
    }



    // When an EvaluatorGroup determines that this evaluator is used by two or more
    // evaluators, the result of the 'Evaluate' method is cached so that the calculation
    // is only performed once for each time.
    // If you don't want any other evaluators to cache this evaluator's value,
    // simply return this instance instead of using the caching wrapper.
    public override IEvaluator GetCachingWrapper()
    {
        return new CachingEvaluator<double>(this);
    }

}
Variations on the Evaluator Theme

There are a few Evaluators which provide slightly different functionality in DME Component Libraries.

MotionEvaluator<T> adds a way to optionally change the sampling strategy used in Access and other calculations. It also takes an "order" parameter to its MotionEvaluatorTEvaluate method. This serves as an optional recommendation for the number of derivatives to calculate. Though the Evaluator is not required to compute results up to the requested order, specifying an order less than the available implementation lets the Evaluator know not to perform extraneous computation. An AccessConstraintEvaluator is a good example of a type-specific implementation of a MotionEvaluator<T>.

C#
// Optional override
public override JulianDate GetNextSampleSuggestion(JulianDate date)
{
    return date.AddSeconds(m_stepsize);
}

// Optional override
public override double Evaluate(JulianDate date)
{
    return Evaluate(date, 0).Value;
}

// Required override
public override Motion<double> Evaluate(JulianDate date, int order)
{
    Motion<Cartesian> state = m_innerEvaluator.Evaluate(date, order + 1);
    double[] result = new double[state.Order - 1];
    for (int i = 0; i < state.Order - 1; i++)
    {
        result[i] = state[i].Magnitude * m_argumentOne;
    }

    return new Motion<double>(result);
}

The geometry types add an additional property which specifies how the raw data is defined. For instance, PointEvaluator adds a property to specify which ReferenceFrame the point is defined in over which times. Thus, it is possible to change the definition of a point from one frame to another without having to recreate the point. This can be useful for things like cis-lunar navigation, formation flying, or for representing a trajectory comprised of multiple different ephemeris sources.

C#
// Required override
public override TimeIntervalCollection<ReferenceFrame> DefinedInIntervals
{
    get { return CreateConstantDefinedIn(m_definedInFrame); }
}

Similarly, AxesEvaluator has a similar property which specifies which Axes the given axes are defined in at different times. Note that any angular rates returned from an AxesEvaluator should be expressed in the "defined-in" Axes.