Click or drag to resize

Scalar Class

A scalar, representing a real valued, time varying function.
Inheritance Hierarchy

Namespace:  AGI.Foundation.Geometry
Assembly:  AGI.Foundation.Core (in AGI.Foundation.Core.dll) Version: 24.3.420.0 (24.3.420.0)
Syntax
public abstract class Scalar : DefinitionalObject

The Scalar type exposes the following members.

Constructors
  NameDescription
Protected methodScalar
Initializes a new instance.
Protected methodScalar(Scalar, CopyContext)
Initializes a new instance as a copy of an existing instance.
Top
Properties
  NameDescription
Public propertyIsFrozen
Gets a value indicating whether this object is frozen. A frozen object cannot be modified and an ObjectFrozenException will be thrown if an attempt is made to do so.
(Inherited from DefinitionalObject.)
Top
Methods
  NameDescription
Public methodAdd(Double)
Adds a fixed scalar to this one.
Public methodAdd(Scalar)
Adds another scalar to this one.
Protected methodCheckForSameDefinition(DefinitionalObject)
Checks to determine if another instance has the same definition as this instance and returns if it does. Derived classes MUST override this method and check all new fields introduced by the derived class for definitional equivalence. It is NOT necessary to check base class fields because the base class will already have done that. When overriding this method, you should NOT call the base implementation because it will return for all derived-class instances. Derived classes should check the type of other to preserve the symmetric nature of IsSameDefinition(Object).
(Overrides DefinitionalObjectCheckForSameDefinition(DefinitionalObject).)
Protected methodCheckForSameDefinition(Scalar)
Checks to determine if another instance has the same definition as this instance and returns if it does. Derived classes MUST override this method and check all new fields introduced by the derived class for definitional equivalence. It is NOT necessary to check base class fields because the base class will already have done that. When overriding this method, you should NOT call the base implementation because it will return for all derived-class instances. Derived classes should check the type of other to preserve the symmetric nature of IsSameDefinition(Object).
Public methodClone
Clones this object using the specified context.
(Inherited from DefinitionalObject.)
Protected methodComputeCurrentDefinitionHashCode
Computes a hash code based on the current properties of this object. Derived classes MUST override this method and compute a hash code that combines: a unique hash code seed, the base implementation result, and the hash codes of all new fields introduced by the derived class which are used in the CheckForSameDefinition(DefinitionalObject) method.
(Overrides DefinitionalObjectComputeCurrentDefinitionHashCode.)
Public methodCreateScalarDerivative
Constructs a scalar which represents a derivative of this scalar.
Public methodDivide(Double)
Divides this scalar (numerator) by a fixed value (denominator).
Public methodDivide(Scalar)
Divides this scalar (numerator) by another one (denominator).
Public methodEnumerateDependencies
Enumerates the dependencies of this object by calling EnumerateT(T) for each object that this object directly depends upon. Derived classes which contain additional dependencies MUST override this method, call the base implementation, and enumerate dependencies introduced by the derived class.
(Inherited from DefinitionalObject.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFreeze
Freezes this object. Further attempts to modify it will result in an ObjectFrozenException.
(Inherited from DefinitionalObject.)
Protected methodFreezeAggregatedObjects
Called by Freeze to also freeze any objects that are considered to be a part of this object. Derived classes which contain additional aggregated objects MUST override this method, call the base implementation, and freeze aggregated objects introduced by the derived class. The objects that need to be frozen in this method are frequently created in this object's constructor and are not settable via properties.
(Inherited from DefinitionalObject.)
Public methodGetDefinitionHashCode
Gets a hash code representing the definition of this object.
(Inherited from DefinitionalObject.)
Public methodGetEvaluator
Gets an evaluator that can be used to find the value of this scalar function at a given JulianDate.
Public methodGetEvaluator(EvaluatorGroup)
Gets an evaluator that can be used to find the value of this scalar function at a given JulianDate. Adds the evaluator to the EvaluatorGroup.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsSameDefinition
Determines if this object has the same definition as another object.
(Inherited from DefinitionalObject.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMultiply(Double)
Multiplies this scalar with a fixed value.
Public methodMultiply(Scalar)
Multiplies another scalar with this one.
Public methodPower
Raises this scalar to the given fixed exponent.
Public methodSubtract(Double)
Subtracts a fixed scalar from this one.
Public methodSubtract(Scalar)
Subtracts another scalar from this one.
Protected methodThrowIfFrozen
Throws ObjectFrozenException if this object IsFrozen. This method should be called from any method or property that modifies this object.
(Inherited from DefinitionalObject.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Operators
  NameDescription
Public operatorStatic memberAddition(Double, Scalar)
Adds two scalars together.
Public operatorStatic memberAddition(Scalar, Scalar)
Adds two scalars together.
Public operatorStatic memberAddition(Scalar, Double)
Adds two scalars together.
Public operatorStatic memberDivision(Double, Scalar)
Divides one scalar from another (left/right).
Public operatorStatic memberDivision(Scalar, Scalar)
Divides one scalar from another (left/right).
Public operatorStatic memberDivision(Scalar, Double)
Divides one scalar from another (left/right).
Public operatorStatic member(Double to Scalar)
Converts a constant double value to a Scalar.
Public operatorStatic memberMultiply(Double, Scalar)
Multiplies two scalars together.
Public operatorStatic memberMultiply(Scalar, Scalar)
Multiplies two scalars together.
Public operatorStatic memberMultiply(Scalar, Double)
Multiplies two scalars together.
Public operatorStatic memberSubtraction(Double, Scalar)
Subtracts one scalar from another.
Public operatorStatic memberSubtraction(Scalar, Scalar)
Subtracts one scalar from another.
Public operatorStatic memberSubtraction(Scalar, Double)
Subtracts one scalar from another.
Top
Examples

This example shows how to create a new Scalar subclass:

C#
// Create a new type derived from Scalar. This type will represent the square root of
// another scalar.
public class SquareRootScalar : Scalar
{
    public SquareRootScalar()
    {
    }

    public SquareRootScalar(Scalar scalarToTakeSquareRootOf)
    {
        m_scalar = scalarToTakeSquareRootOf;
    }

    // The copy constructor, used to make a copy of the object.  Copy all of the
    // fields of the 'existingInstance' to the new object.  Reference types should
    // be passed through a call to UpdateReference so that the depth of the copy
    // can be controlled by the user.  See the documentation of the ICloneWithContext
    // interface for more information.
    protected SquareRootScalar(SquareRootScalar existingInstance, CopyContext context)
        : base(existingInstance, context)
    {
        m_scalar = context.UpdateReference(existingInstance.m_scalar);
    }

    // This is called to make a copy of the object, which it does by calling the
    // copy constructor above.
    public override object Clone(CopyContext context)
    {
        return new SquareRootScalar(this, context);
    }

    // This method is only called by the IsSameDefinition method in the base class to
    // determine if two scalars are equivalent. Derived classes MUST override this method and
    // check all new fields introduced by the derived class for definitional equivalence. It
    // is NOT necessary to check base class fields because the base class will already have
    // done that.
    protected sealed override bool CheckForSameDefinition(Scalar other)
    {
        SquareRootScalar o = other as SquareRootScalar;
        return o != null &&
               AreSameDefinition(m_scalar, o.m_scalar);
    }

    // Called to determine a hash code for the current configuration of this object.
    // Derived classes MUST override this method and compute a hash code that combines: 
    // a unique hash code seed, the base implementation result, and the 
    // hash codes of all new fields introduced by the derived class which are used 
    // in the CheckForSameDefinition method.
    protected override int ComputeCurrentDefinitionHashCode()
    {
        return HashCode.Combine(typeof(SquareRootScalar).GetHashCode(),
                                base.ComputeCurrentDefinitionHashCode(),
                                GetDefinitionHashCode(m_scalar));
    }

    // Called to enumerate all of the other objects on which this object depends. This
    // allows clients to navigate the graph of objects related to a computation.
    public override void EnumerateDependencies(DependencyEnumerator enumerator)
    {
        base.EnumerateDependencies(enumerator);
        enumerator.Enumerate(m_scalar);
    }

    // The scalar that this scalar is the square root of.
    public Scalar ScalarToTakeSquareRootOf
    {
        get { return m_scalar; }
        set { m_scalar = value; }
    }

    // This method is responsible for returning an instance of the private
    // Evaluator class. It should ensure that the properties are not null or
    // in an invalid state, and then use the evaluator group when it constructs
    // and returns an instance of the Evaluator.
    public override ScalarEvaluator GetEvaluator(EvaluatorGroup group)
    {
        if (group == null)
            throw new ArgumentNullException("group");

        // Ensure that the properties are not null.
        if (ScalarToTakeSquareRootOf == null)
            throw new PropertyInvalidException("ScalarToTakeSquareRootOf", PropertyInvalidException.PropertyCannotBeNull);

        return group.CreateEvaluator<ScalarEvaluator>(CreateEvaluator);
    }

    // This method, which is passed to the evaluator group in the method above as a delegate,
    // will only be called by the delegate if the evaluator does not yet exist in the group
    // and needs to be created.
    private ScalarEvaluator CreateEvaluator(EvaluatorGroup group)
    {
        // In order to take the square root of the scalar, we must first evaluate it.
        // Get the evaluator that will allow us to do so.
        // Notice that we create this evaluator in the same EvaluatorGroup.
        var scalarEvaluator = ScalarToTakeSquareRootOf.GetEvaluator(group);

        return new Evaluator(group, scalarEvaluator);
    }

    private Scalar m_scalar;

    // This is the definition of the Evaluator that is used to actually evaluate this Scalar.
    // Because it is a private, nested class, it is not visible outside of the SquareRootScalar class.
    // This is ok, though, because once it is created users only interact with it via a reference
    // to its base class: ScalarEvaluator.
    private sealed class Evaluator : ScalarEvaluator
    {
        // An evaluator should not store any data that the user will be able to change
        // after creating the evaluator.  This sometimes requires that data required by the
        // evaluator be copied or frozen using the IFreezable interface.
        public Evaluator(EvaluatorGroup group, ScalarEvaluator scalarEvaluator)
            : base(group)
        {
            m_scalarEvaluator = scalarEvaluator;
        }

        // The Evaluator's copy constructor will be called from the Clone method.
        // Don't forget to call the base class implementation!
        private Evaluator(Evaluator existingInstance, CopyContext context)
            : base(existingInstance, context)
        {
            // For non-evaluator reference types, we would use context.UpdateReference to
            // allow the context to update the references we hold.
            // This evaluator does not have any non-evaluator reference fields.

            // For evaluators, just assign the reference directly - we'll call UpdateReference later.
            m_scalarEvaluator = existingInstance.m_scalarEvaluator;

            // Always call UpdateEvaluatorReferences at the end of the copy constructor.
            // This is where references to evaluators will be updated.
            UpdateEvaluatorReferences(context);
        }

        // This method is used by the EvaluatorGroup system to avoid redundant evaluations. The
        // EvaluatorGroup may call it on your evaluator in order to replace your evaluator's
        // reference to another evaluator with a reference to a version that caches its last
        // result.
        public override void UpdateEvaluatorReferences(CopyContext context)
        {
            m_scalarEvaluator = context.UpdateReference(m_scalarEvaluator);
        }

        // The Clone method should call the copy constructor.
        public override object Clone(CopyContext context)
        {
            return new Evaluator(this, context);
        }

        // This method determines if there is data available from this Evaluator at
        // the specified date.
        public override bool IsAvailable(JulianDate date)
        {
            // This evaluator is available whenever the nested evaluator is available.
            return m_scalarEvaluator.IsAvailable(date);
        }

        // This method returns a collection of time intervals when data is
        // available from this Evaluator.
        public override TimeIntervalCollection GetAvailabilityIntervals(TimeIntervalCollection consideredIntervals)
        {
            // This evaluator is available whenever the nested evaluator is available.
            return m_scalarEvaluator.GetAvailabilityIntervals(consideredIntervals);
        }

        // This property determines if this Evaluator can safely be used from multiple threads
        // simultaneously. If the evaluator stores data during the Evaluate call, it is not thread
        // safe. Otherwise, it generally is thread safe as long as any nested evaluators it uses
        // are thread safe.
        public override bool IsThreadSafe
        {
            get
            {
                // This evaluator is thread safe as long as the nested evaluator is thread safe.
                return m_scalarEvaluator.IsThreadSafe;
            }
        }

        // This property determines if this Evaluator result changes depending on the time at which it is evaluated.
        public override bool IsTimeVarying
        {
            get { return m_scalarEvaluator.IsTimeVarying; }
        }

        // This is where we do the actual evaluation when only the value of the scalar (not additional derivatives)
        // is required.
        public override double Evaluate(JulianDate date)
        {
            double value = m_scalarEvaluator.Evaluate(date);
            return Math.Sqrt(value);
        }

        // This is where we do the actual evaluation when additional derivatives of the scalar
        // are requested as well.
        public override Motion<double> Evaluate(JulianDate date, int order)
        {
            Motion<double> motion = m_scalarEvaluator.Evaluate(date, order);

            // Since only the second derivative is implemented here, constrain the array to 
            // only return up to that order.
            int size = Math.Min(motion.Order, 2);
            double[] result = new double[size + 1];

            result[0] = Math.Sqrt(motion[0]);

            // If the user did not request higher derivatives, do not spend time calculating them.
            if (order > 0)
            {
                // Compute the derivative using the chain rule.
                result[1] = 0.5 * Math.Pow(motion[0], -0.5) * motion[1];
            }
            if (order > 1)
            {
                // Compute the derivative using the product rule and the chain rule.
                result[2] = 0.5 * Math.Pow(motion[0], -0.5) * motion[2] - 0.25 * Math.Pow(motion[0], -1.5) * motion[1] * motion[1];
            }
            return new Motion<double>(result);
        }

        // Override the Dispose method to call the Dispose() method on any nested
        // evaluators or other disposable nested types.
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                m_scalarEvaluator.Dispose();
            }
        }

        private ScalarEvaluator m_scalarEvaluator;
    }
}
See Also
Inheritance Hierarchy
SystemObject
  AGI.Foundation.InfrastructureDefinitionalObject
    AGI.Foundation.GeometryScalar
      AGI.Foundation.CelestialScalarAtmosphericDensity
      AGI.Foundation.CelestialScalarOccultation
      AGI.Foundation.CelestialScalarVariableArea
      AGI.Foundation.GeometryCommunicationLinkScalar
      AGI.Foundation.GeometryCommunicationObjectScalar
      AGI.Foundation.GeometryParameterizedOnStateScalar
      AGI.Foundation.GeometryParameterizedScalar
      AGI.Foundation.GeometryScalarAbsoluteValue
      AGI.Foundation.GeometryScalarAngleBetweenVectors
      AGI.Foundation.GeometryScalarAngleInRange
      AGI.Foundation.GeometryScalarAngleSmallSpan
      AGI.Foundation.GeometryScalarCartographicElement
      AGI.Foundation.GeometryScalarCosine
      AGI.Foundation.GeometryScalarDelaunayElement
      AGI.Foundation.GeometryScalarDelayedByLink
      AGI.Foundation.GeometryScalarDeltaSphericalElement
      AGI.Foundation.GeometryScalarDerivative
      AGI.Foundation.GeometryScalarDihedralAngle
      AGI.Foundation.GeometryScalarDopplerConeAngle
      AGI.Foundation.GeometryScalarDotProduct
      AGI.Foundation.GeometryScalarEquinoctialElement
      AGI.Foundation.GeometryScalarExponent
      AGI.Foundation.GeometryScalarFixed
      AGI.Foundation.GeometryScalarFixedAtJulianDate
      AGI.Foundation.GeometryScalarGrazingAltitudeBetweenTwoPoints
      AGI.Foundation.GeometryScalarInterpolator
      AGI.Foundation.GeometryScalarInverseTangent
      AGI.Foundation.GeometryScalarKozaiIzsakMeanElement
      AGI.Foundation.GeometryScalarMaximumValue
      AGI.Foundation.GeometryScalarMinimumValue
      AGI.Foundation.GeometryScalarModifiedKeplerianElement
      AGI.Foundation.GeometryScalarPointElement
      AGI.Foundation.GeometryScalarProduct
      AGI.Foundation.GeometryScalarRouteHeading
      AGI.Foundation.GeometryScalarRouteHeight
      AGI.Foundation.GeometryScalarRouteSurfaceSpeed
      AGI.Foundation.GeometryScalarRouteTotalSpeed
      AGI.Foundation.GeometryScalarSine
      AGI.Foundation.GeometryScalarSphericalElement
      AGI.Foundation.GeometryScalarSquintAngle
      AGI.Foundation.GeometryScalarSum
      AGI.Foundation.GeometryScalarVectorElement
      AGI.Foundation.GeometryVectorMagnitude
      AGI.Foundation.Navigation.ModelsScalarSaastamoinenTroposphericCorrection
      AGI.Foundation.Navigation.ModelsScalarSingleFrequencyIonosphericCorrection
      AGI.Foundation.RadarSingleTargetRadarLinkScalar