Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit d34c7bf9 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge pull request #189 in VECTO/vecto-sim from ~EMKRISPMI/vecto-sim:develop to develop

* commit 'f78c7200':
  performance shortcut for IsInside Triangle method
  added SI Prototype for 0-Instances
  faster IsPositive Method
  updated test for 1hz
parents 4b0b0ff1 f78c7200
No related branches found
No related tags found
No related merge requests found
......@@ -139,7 +139,7 @@ namespace TUGraz.VectoCommon.Utils
/// <returns></returns>
public static bool IsPositive(this double self, double tolerance = Tolerance)
{
return self.IsGreaterOrEqual(0.0, tolerance);
return self >= -tolerance;
}
/// <summary>
......
......@@ -259,7 +259,6 @@ namespace TUGraz.VectoCommon.Utils
// private Gram(double val) : base(val, NumeratorDefault) {}
//}
//public class GramPerSecond : SIBase<GramPerSecond>
//{
// private static readonly Unit[] NumeratorDefault = { Unit.g };
......@@ -323,7 +322,6 @@ namespace TUGraz.VectoCommon.Utils
}
}
public class Liter : SIBase<Liter>
{
private static readonly Unit[] NumeratorDefault = { Unit.liter };
......@@ -583,7 +581,6 @@ namespace TUGraz.VectoCommon.Utils
}
}
/// <summary>
/// SI Class for one per second [1/s].
/// </summary>
......@@ -782,6 +779,8 @@ namespace TUGraz.VectoCommon.Utils
/// <typeparam name="T"></typeparam>
public abstract class SIBase<T> : SI where T : SIBase<T>
{
static T _zeroPrototype;
static SIBase()
{
var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
......@@ -789,6 +788,7 @@ namespace TUGraz.VectoCommon.Utils
var parameter = Expression.Parameter(typeof(double));
var lambda = Expression.Lambda<Func<double, T>>(Expression.New(constructorInfo, parameter), parameter);
Constructor = lambda.Compile();
_zeroPrototype = Constructor(0);
}
/// <summary>
......@@ -802,6 +802,9 @@ namespace TUGraz.VectoCommon.Utils
/// <param name="val">The value of the SI object.</param>
public static T Create(double val)
{
if (val == 0)
return _zeroPrototype;
return Constructor(val);
}
......
......@@ -434,6 +434,12 @@ namespace TUGraz.VectoCore.Utils
/// <returns></returns>
public bool IsInside(double x, double y, bool exact)
{
if ((P1.Y < y && P2.Y < y && P3.Y < y)
|| (P1.X < x && P2.X < x && P3.X < x)
|| (P1.X > x && P2.X > x && P3.X > x)
|| (P1.Y > y && P2.Y > y && P3.Y > y))
return false;
var v0X = P3.X - P1.X;
var v0Y = P3.Y - P1.Y;
var v1X = P2.X - P1.X;
......
......@@ -224,11 +224,12 @@ namespace TUGraz.VectoCore.Tests.Integration
var modFile1Hz = VectoCSVFile.Read(modFileName1Hz);
// test if line count matches the second count
var maxSeconds =
(int)Math.Ceiling(modFile.Rows.Cast<DataRow>().Last().ParseDouble(ModalResultField.time.GetShortCaption()));
var maxSeconds = modFile.Rows.Cast<DataRow>().Last().ParseDouble(ModalResultField.time.GetShortCaption());
var lineCount1Hz = modFile1Hz.Rows.Count;
Assert.IsTrue(lineCount1Hz == maxSeconds);
AssertHelper.AreRelativeEqual(lineCount1Hz, maxSeconds,
string.Format("LineCount must equal max seconds. Lines={0}, MaxSeconds={1}", lineCount1Hz,
maxSeconds), 1);
// test max distance
var maxDistance = modFile.Rows.Cast<DataRow>().Last().ParseDouble(ModalResultField.dist.GetShortCaption());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment