init
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
Math.Nhtsa.ChannelIntegration.cs
|
||||
|
||||
$Log: Math.Nhtsa.ChannelIntegration.cs,v $
|
||||
Revision 1.4 2007/10/04 04:57:45 Paul Hrissikopoulos
|
||||
Added new integration object.
|
||||
|
||||
Revision 1.3 2007/08/24 23:31:08 Paul Hrissikopoulos
|
||||
Fixed comment typos.
|
||||
|
||||
Revision 1.2 2007/03/28 15:58:02 Paul Hrissikopoulos
|
||||
Fixed error in integration calculation; fixed erroenous error check in SampleRate accessor.
|
||||
|
||||
Revision 1.1 2007/02/05 17:17:08 Paul Hrissikopoulos
|
||||
Finished installing generic channel math framework + basic calculus operations.
|
||||
|
||||
Copyright © 2007
|
||||
Diversified Technical Systems, Inc.
|
||||
All Rights Reserved
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DTS.Common.Utilities.DotNetProgrammingConstructs;
|
||||
|
||||
namespace DTS.Common.Utilities.Math.Nhtsa
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Representation of NHTSA-based integration channel operation.
|
||||
/// </summary>
|
||||
public class Integration : DoubleListOperation
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get/set the <see cref="double"/> sample rate for this data to be integrated.
|
||||
/// </summary>
|
||||
public double SampleRate
|
||||
{
|
||||
get => _SampleRate.Value;
|
||||
set => _SampleRate.Value = value;
|
||||
}
|
||||
private Property<double> _SampleRate
|
||||
= new Property<double>(
|
||||
typeof(Integration).FullName + ".SampleRate",
|
||||
0.0,
|
||||
false
|
||||
);
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Initialize an instance of the Integration class.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="domain">
|
||||
/// The System.Collections.Generic.IList of <see cref="double"/>s
|
||||
/// domain for this operation.
|
||||
/// </param>
|
||||
///
|
||||
public Integration(IList<double> domain)
|
||||
: base(domain)
|
||||
{ //
|
||||
// I'd prefer to do this statically, but I don't know of any C# way to place a constraint
|
||||
// on a generic type that's already been determined by some ancestor we're inheriting from,
|
||||
// so for now we'll have to dynamically check it on object instantiation.
|
||||
//
|
||||
if (!(domain is ICloneable))
|
||||
throw new InvalidCastException("the domain type for " + typeof(Integration).FullName + " must be ICloneable");
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Initialize an instance of the Iso.ChannelIntegration class.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="domain">
|
||||
/// The System.Collections.Generic.IList of <see cref="double"/>s
|
||||
/// domain for this operation.
|
||||
/// </param>
|
||||
///
|
||||
/// <param name="sampleRate">
|
||||
/// The <see cref="int"/> sample rate of the channel to be integrated.
|
||||
/// </param>
|
||||
///
|
||||
public Integration(IList<double> domain, int sampleRate)
|
||||
: this(domain)
|
||||
{
|
||||
try { SampleRate = sampleRate; }
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem constructing " + GetType().FullName, ex);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the System.Collections.Generic.IList of <see cref="double"/>s result of
|
||||
/// the operation on the channel.
|
||||
/// </summary>
|
||||
public override IList<double> Range
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if (null == Domain)
|
||||
throw new ArgumentNullException("attempted to integrate null channel reference");
|
||||
|
||||
else if (0.0 >= SampleRate)
|
||||
throw new ArgumentOutOfRangeException("SampleRate must be greater than zero");
|
||||
|
||||
else if (!(Domain is ICloneable))
|
||||
throw new InvalidCastException("the domain type for " + typeof(Integration).FullName + " must be ICloneable");
|
||||
|
||||
else
|
||||
{
|
||||
var IndexOfLastSample = Domain.Count - 1;
|
||||
var de = 1 / (SampleRate * 2.0);
|
||||
var range = ((ICloneable)Domain).Clone() as IList<double>;
|
||||
|
||||
range[0] = Domain[0] * de;
|
||||
for (var t = 1; t < IndexOfLastSample; t++)
|
||||
range[t] = range[t - 1] + 2 * Domain[t] * de;
|
||||
range[IndexOfLastSample] = range[IndexOfLastSample - 1] + Domain[IndexOfLastSample] * de;
|
||||
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw new Exception("encountered problem doing " + GetType().FullName + " operation", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
Reference in New Issue
Block a user