Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CreateMeasurement.cs
6
8{
13 {
23 : base(Operand1, Operand2, Start, Length, Expression)
24 {
25 }
26
34 public override IElement EvaluateScalar(IElement Operand1, IElement Operand2, Variables Variables)
35 {
36 double Magnitude;
37 Unit Unit;
38 double Error;
39
40 if (Operand1.AssociatedObjectValue is IPhysicalQuantity PQ1)
41 {
43 Magnitude = Q1.Magnitude;
44 Unit = Q1.Unit;
45 }
46 else if (Operand1.AssociatedObjectValue is double D1)
47 {
48 Magnitude = D1;
49 Unit = Unit.Empty;
50 }
51 else
52 throw new ScriptRuntimeException("Expected Physical Quantity our numeric value.", this.LeftOperand);
53
54 if (Operand2.AssociatedObjectValue is IPhysicalQuantity PQ2)
55 {
57 if (Unit == Unit.Empty)
58 {
59 Error = Q2.Magnitude;
60 Unit = Q2.Unit;
61 }
62 else if (!Unit.TryConvert(Q2.Magnitude, Q2.Unit, Unit, out Error))
63 throw new ScriptRuntimeException("Incompatible error unit.", this);
64 }
65 else if (Operand2.AssociatedObjectValue is double D2)
66 Error = D2;
67 else
68 throw new ScriptRuntimeException("Expected Physical Quantity our numeric value.", this.RightOperand);
69
70 return new Measurement(Magnitude, Unit, Error);
71 }
72 }
73}
Class managing a script expression.
Definition: Expression.cs:39
ScriptNode RightOperand
Right operand.
ScriptNode LeftOperand
Left operand.
Base class for binary scalar operators.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
PhysicalQuantity ToPhysicalQuantity()
Converts underlying object to a physical quantity.
override IElement EvaluateScalar(IElement Operand1, IElement Operand2, Variables Variables)
Evaluates the operator on scalar operands.
CreateMeasurement(ScriptNode Operand1, ScriptNode Operand2, int Start, int Length, Expression Expression)
Creates a measurement.
Represents a unit.
Definition: Unit.cs:15
static bool TryConvert(double From, Unit FromUnit, Unit ToUnit, out double To)
Tries to convert a magnitude in one unit to a magnitude in another.
Definition: Unit.cs:1201
static readonly Unit Empty
Empty unit.
Definition: Unit.cs:436
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33
Interface for objects that can be represented as a physical quantity.