From e565c5b0fe6521ed0472fe30696c075cdff72a78 Mon Sep 17 00:00:00 2001
From: stefan meyer <stefan.meyer@student.tugraz.at>
Date: Tue, 29 Aug 2017 21:13:04 +0200
Subject: [PATCH] change SI refactoring

---
 VectoCommon/VectoCommon/Utils/SIUtils.cs | 56 +++++++++++++++---------
 VectoCore/VectoCoreTest/Utils/SITest.cs  | 20 +++++++++
 2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/VectoCommon/VectoCommon/Utils/SIUtils.cs b/VectoCommon/VectoCommon/Utils/SIUtils.cs
index 47bdc67b65..00fd693f72 100644
--- a/VectoCommon/VectoCommon/Utils/SIUtils.cs
+++ b/VectoCommon/VectoCommon/Utils/SIUtils.cs
@@ -127,8 +127,8 @@ namespace TUGraz.VectoCommon.Utils
                 units[0] += 1 * reciproc * exponent;
 
                 factorValue /= Math.Pow(1000, exponent * reciproc);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
-                //return this; // not work
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this; // not work
             }
         }
         public UnitInstance Cubic
@@ -136,7 +136,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 exponent = 3;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Hour
@@ -147,7 +148,8 @@ namespace TUGraz.VectoCommon.Utils
                 units[2] += 1 * ReciprocAndExponent;
 
                 factorValue *= Math.Pow(3600, ReciprocAndExponent);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Kilo
@@ -164,7 +166,8 @@ namespace TUGraz.VectoCommon.Utils
                 }
 
                 factorValue *= Math.Pow(1000, exponent * reciproc);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Linear
@@ -172,7 +175,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 exponent = 1;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Meter
@@ -180,7 +184,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 units[1] += 1 * reciproc * exponent;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Milli
@@ -189,7 +194,8 @@ namespace TUGraz.VectoCommon.Utils
             {
 
                 factorValue /= Math.Pow(1000, exponent * reciproc);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Centi
@@ -197,7 +203,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 factorValue /= Math.Pow(100, exponent * reciproc);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Dezi
@@ -205,7 +212,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 factorValue /= Math.Pow(10, exponent * reciproc);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Minute
@@ -216,7 +224,8 @@ namespace TUGraz.VectoCommon.Utils
                 units[2] += 1 * ReciprocAndExponent;
 
                 factorValue *= Math.Pow(60, ReciprocAndExponent);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Newton
@@ -227,7 +236,8 @@ namespace TUGraz.VectoCommon.Utils
                 units[0] += 1 * ReciprocAndExponent;
                 units[1] += 1 * ReciprocAndExponent;
                 units[2] -= 2 * ReciprocAndExponent;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Per
@@ -237,15 +247,16 @@ namespace TUGraz.VectoCommon.Utils
                 exponent = 1;
                 reciproc = reciproc * (-1);
 
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
-                //return this;
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Radian
         {
             get
             {
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Rounds
@@ -253,7 +264,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 factorValue *= Math.Pow(2 * Math.PI, exponent * reciproc);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Second
@@ -261,7 +273,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 units[2] += 1 * reciproc * exponent;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Square
@@ -269,7 +282,8 @@ namespace TUGraz.VectoCommon.Utils
             get
             {
                 exponent = 2 * reciproc;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Ton
@@ -279,7 +293,8 @@ namespace TUGraz.VectoCommon.Utils
                 int ReciprocAndExponent = reciproc * exponent;
                 units[0] += 1 * ReciprocAndExponent;
                 factorValue *= Math.Pow(1000, ReciprocAndExponent);
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
         public UnitInstance Watt
@@ -290,7 +305,8 @@ namespace TUGraz.VectoCommon.Utils
                 units[0] += 1 * ReciprocAndExponent;
                 units[1] += 2 * ReciprocAndExponent;
                 units[2] -= 3 * ReciprocAndExponent;
-                return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                //return new UnitInstance(units, factorValue, exponent, reciproc, grammMode);
+                return this;
             }
         }
 
diff --git a/VectoCore/VectoCoreTest/Utils/SITest.cs b/VectoCore/VectoCoreTest/Utils/SITest.cs
index 3b24ad01f9..472bc24db4 100644
--- a/VectoCore/VectoCoreTest/Utils/SITest.cs
+++ b/VectoCore/VectoCoreTest/Utils/SITest.cs
@@ -602,9 +602,29 @@ namespace TUGraz.VectoCore.Tests.Utils
             NewtonMeter newtonMeter = 5.SI<NewtonMeter>();
             AssertHelper.AreRelativeEqual(5.SI(Unit.SI.Newton.Meter), newtonMeter);
             AssertHelper.AreRelativeEqual(5.SI(Unit.SI.Meter.Newton), newtonMeter);
+        }
 
+        [TestMethod]
+        public void SI_ConstructorPerformance_OtherSIInterface()
+        {
+            for (var i = 0; i < 5e5; i++)
+                //for (var i = 0; i < 0.05e5; i++)
+            {
+                var si = i.SI();
+                var meter = i.SI<Meter>();
+                var watt = i.SI<Watt>();
+                var perSecond = i.SI<PerSecond>();
+                var meterPerSecond = i.SI<MeterPerSecond>();
+                var second = i.SI<Second>();
+                var newton = i.SI<Newton>();
+                var kilogram = i.SI<Kilogram>();
+                var squareMeter = i.SI<SquareMeter>();
+                var scalar = i.SI<Scalar>();
+                var compound = i.SI(Unit.SI.Kilo.Gramm.Square.Meter.Per.Cubic.Second).Cast<Watt>();
+            }
 
         }
+
     }
 
 }
\ No newline at end of file
-- 
GitLab