/// <summary> /// Adds the specified constant expression. /// </summary> /// <param name="constantExpression">The constant expression.</param> /// <param name="exponent">The exponent.</param> public void Add(ConstantExpression constantExpression, double exponent) { var additionalConstant = Math.Pow(constantExpression.Constant, exponent); if (this.constantFlatIdentifierRepresentation == null) { this.constantFlatIdentifierRepresentation = new ConstantFlatIdentifierRepresentation(additionalConstant); this.additionalCount++; } else { this.constantFlatIdentifierRepresentation = new ConstantFlatIdentifierRepresentation( this.constantFlatIdentifierRepresentation.Constant * additionalConstant); } }
/// <summary> /// Builds a <see cref="FlatRepresentation"/> from this instance. /// </summary> /// <returns>A <see cref="FlatRepresentation"/>.</returns> public FlatRepresentation Build() { var flatPresentations = new Dictionary <string, IFlatIdentifierRepresentation>( this.unitFlatIdentifierRepresentations.Count + this.additionalCount); foreach (var pair in this.unitFlatIdentifierRepresentations) { if (!pair.Value.Exponent.Equals(0)) { flatPresentations.Add(pair.Key, pair.Value); } } this.unitFlatIdentifierRepresentations.Clear(); if (this.constantFlatIdentifierRepresentation != null) { flatPresentations.Add(Constant, this.constantFlatIdentifierRepresentation); this.constantFlatIdentifierRepresentation = null; } if (this.variableFlatIdentifierRepresentations != null) { foreach (var pair in this.variableFlatIdentifierRepresentations) { if (!pair.Value.Exponent.Equals(0)) { flatPresentations.Add(pair.Key, pair.Value); } } this.variableFlatIdentifierRepresentations.Clear(); } return(new FlatRepresentation(flatPresentations)); }