private AllOrNoneValueSet CheckCompatibility(IValueSet other) { if (this.Type.Equals(other.GetPrestoType())) { throw new ArgumentException($"Mismatched types: {this.Type} vs {other.GetPrestoType()}."); } if (!(other is AllOrNoneValueSet)) { throw new ArgumentException($"ValueSet is not a AllOrNoneValueSet: {other.GetType().Name}."); } return((AllOrNoneValueSet)other); }
private SortedRangeSet CheckCompatibility(IValueSet other) { if (!this.Type.Equals(other.GetPrestoType())) { throw new ArgumentException($"Mismatched types: {this.Type} vs {other.GetPrestoType()}."); } if (!(other is SortedRangeSet)) { throw new ArgumentException($"ValueSet is not a SortedRangeSet: {other.GetType()}."); } return((SortedRangeSet)other); }
/// <summary> /// Convert the units according the what is specified in the link /// </summary> /// <param name="values">The values</param> /// <returns>The unit converted values</returns> private IValueSet ConvertUnit(IValueSet values) { double aSource = link.SourceQuantity.Unit.ConversionFactorToSI; double bSource = link.SourceQuantity.Unit.OffSetToSI; double aTarget = link.TargetQuantity.Unit.ConversionFactorToSI; double bTarget = link.TargetQuantity.Unit.OffSetToSI; if (aSource != aTarget || bSource != bTarget) { if (values is IScalarSet) { double[] x = new double[values.Count]; for (int i = 0; i < values.Count; i++) { x[i] = (((IScalarSet)values).GetScalar(i) * aSource + bSource - bTarget) / aTarget; } return(new ScalarSet(x)); } else if (values is IVectorSet) { ArrayList vectors = new ArrayList(); for (int i = 0; i < values.Count; i++) { double x = (((IVectorSet)values).GetVector(i).XComponent *aSource + bSource - bTarget) / aTarget; double y = (((IVectorSet)values).GetVector(i).YComponent *aSource + bSource - bTarget) / aTarget; double z = (((IVectorSet)values).GetVector(i).ZComponent *aSource + bSource - bTarget) / aTarget; Vector newVector = new Vector(x, y, z); vectors.Add(newVector); } return(new VectorSet((Vector[])vectors.ToArray(typeof(Vector)))); } else { throw new Exception("Type " + values.GetType().FullName + " not suppported for unit conversion"); } } return(values); }
/// <summary> /// Convert the units according the what is specified in the link /// </summary> /// <param name="values">The values</param> /// <returns>The unit converted values</returns> private IValueSet ConvertUnit(IValueSet values) { double aSource = link.SourceQuantity.Unit.ConversionFactorToSI; double bSource = link.SourceQuantity.Unit.OffSetToSI; double aTarget = link.TargetQuantity.Unit.ConversionFactorToSI; double bTarget = link.TargetQuantity.Unit.OffSetToSI; if (aSource != aTarget || bSource != bTarget) { if (values is IScalarSet) { double[] x = new double[values.Count]; for (int i = 0; i < values.Count; i++) { x[i] = (((IScalarSet) values).GetScalar(i) * aSource + bSource - bTarget) / aTarget; } return new ScalarSet(x); } else if (values is IVectorSet) { ArrayList vectors = new ArrayList(); for (int i = 0; i < values.Count; i++) { double x = (((IVectorSet) values).GetVector(i).XComponent * aSource + bSource - bTarget) / aTarget; double y = (((IVectorSet) values).GetVector(i).YComponent * aSource + bSource - bTarget) / aTarget; double z = (((IVectorSet) values).GetVector(i).ZComponent * aSource + bSource - bTarget) / aTarget; Vector newVector = new Vector(x, y, z); vectors.Add (newVector); } return new VectorSet((Vector[]) vectors.ToArray(typeof(Vector))); } else { throw new Exception ("Type " + values.GetType().FullName + " not suppported for unit conversion"); } } return values; }