/// <summary> /// Returns the calculated Area given the <paramref name="qty"/>. /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> public IQuantity CalculateArea(IQuantity qty, CircularCalculationType type = CircularCalculationType.Diameter) { return VerifyDimensions( CalculateAreaFromRadius(qty, type) ?? CalculateAreaFromDiameter(qty, type), A.SquareMeter); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> public IQuantity CalculateCircumference(IQuantity qty, CircularCalculationType type = CircularCalculationType.Diameter) { return(VerifyDimensions( CalculateCircumferenceFromRadius(qty, type) ?? CalculateCircumferenceFromDiameter(qty, type), L.Meter)); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> public IQuantity CalculateCircumference(IQuantity qty, CircularCalculationType type = CircularCalculationType.Diameter) { return VerifyDimensions( CalculateCircumferenceFromRadius(qty, type) ?? CalculateCircumferenceFromDiameter(qty, type), L.Meter); }
/// <summary> /// Returns the calculated Area given the <paramref name="qty"/>. /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> public IQuantity CalculateArea(IQuantity qty, CircularCalculationType type = CircularCalculationType.Diameter) { return(VerifyDimensions( CalculateAreaFromRadius(qty, type) ?? CalculateAreaFromDiameter(qty, type), A.SquareMeter)); }
/// <summary> /// Returns the diameter calculated from a area. /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateDiameterFromArea(IQuantity qty, CircularCalculationType type) { var radiusQty = CalculateRadiusFromArea(qty, type); return(ReferenceEquals(null, radiusQty) ? null : CalculateDiameterFromRadius(radiusQty, CircularCalculationType.Radius)); }
public void Verify_from_circumference([LengthValues] IQuantity qty) { const CircularCalculationType type = CircularCalculationType.Circumference; using (new CircularCalculatorFixture(qty, x => x / (2d * Math.PI), c => c.CalculateRadius, type, L.Meter)) { } }
public void Verify_from_area([AreaValues] IQuantity qty) { const CircularCalculationType type = CircularCalculationType.Area; using (new CircularCalculatorFixture(qty, x => Math.Sqrt(x / Math.PI), c => c.CalculateRadius, type, L.Meter)) { } }
public void Verify_from_diameter([LengthValues] IQuantity qty) { const CircularCalculationType type = CircularCalculationType.Diameter; using (new CircularCalculatorFixture(qty, x => x / 2d, c => c.CalculateRadius, type, L.Meter)) { } }
public void Verify_from_radius([LengthValues] IQuantity qty) { const CircularCalculationType type = CircularCalculationType.Radius; using (new CircularCalculatorFixture(qty, x => 2d * x, c => c.CalculateDiameter, type, L.Meter)) { } }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateCircumferenceFromRadius(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Radius)) { return(null); } var resultQty = (Quantity)qty * 2d * Math.PI; return(resultQty); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="expected"></param> /// <param name="actual"></param> /// <param name="type"></param> /// <param name="dimensions"></param> public CircularCalculatorFixture( IQuantity qty, Func <double, double> expected, Func <CircularCalculator, Func <IQuantity, CircularCalculationType, IQuantity> > actual, CircularCalculationType type, params IDimension[] dimensions) : base(dimensions) { _type = type; _qty = qty; _actual = actual; _expected = expected; }
private static IQuantity CalculateDiameterFromRadius(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Radius)) { return(null); } qty.VerifyDimensions(L.Meter); var resultQty = (Quantity)qty * 2d; return(resultQty); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateCircumferenceFromDiameter(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Diameter)) { return(null); } /* Results will be in terms of base units. Which is still 2 PI r, but * notice the 2 is understood by the Diameter being 2 r to begin with. */ var resultQty = (Quantity)qty * Math.PI; return(resultQty); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateRadiusFromDiameter(IQuantity qty, CircularCalculationType type) { if (!type.HasMask(CircularCalculationType.Diameter)) { return(null); } // The dimension should be consistently Length, although the unit itself may be different. qty.VerifyDimensions(L.Meter); var resultQty = (Quantity)qty / 2d; return(resultQty); }
/// <summary> /// /// </summary> /// <param name="aQty"></param> /// <param name="bQty"></param> /// <param name="expected"></param> /// <param name="actual"></param> /// <param name="type"></param> /// <param name="dimensions"></param> public EllipticalCalculatorFixture( IQuantity aQty, IQuantity bQty, Func <double, double, double> expected, Func <CircularCalculator, Func <IQuantity, IQuantity, IQuantity> > actual, CircularCalculationType type, params IDimension[] dimensions) : base(dimensions) { _aQty = aQty; _bQty = bQty; _expected = expected; _actual = actual; _type = type; }
/// <summary> /// Returns the Radius calculated from the given <see cref="IArea"/> expressed through /// <paramref name="qty"/>. The resulting units will be in alignment with said Qty. /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> /// <a href="!:http://en.wikipedia.org/wiki/Arc_%28geometry%29" >Area (geometry)</a> private static IQuantity CalculateRadiusFromArea(IQuantity qty, CircularCalculationType type) { if (!type.HasMask(CircularCalculationType.Area)) { return(null); } // Dimensions should be Length Squared. Does not matter the unit at this moment. qty.VerifyDimensions(L.Meter.Squared()); var resultQty = ((Quantity)qty / Math.PI).SquareRoot(); return(resultQty); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateAreaFromRadius(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Radius)) { return(null); } // The dimension should be consistently Length, although the unit itself may be different. qty.VerifyDimensions(L.Meter); var resultQty = (Quantity)qty.Squared() * Math.PI; return(resultQty); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> /// <a href="!:http://en.wikipedia.org/wiki/Circumference" >Circumference</a> /// <a href="!:http://en.wikipedia.org/wiki/Pi" >Pi</a> private static IQuantity CalculateRadiusFromCircumference(IQuantity qty, CircularCalculationType type) { if (!type.HasMask(CircularCalculationType.Circumference)) { return(null); } //TODO: for these types of calculations, it might make sense to capture a "derived" unit of "circumference", based on "length", but for first class treatment... qty.VerifyDimensions(L.Meter); var resultQty = (Quantity)qty / (2d * Math.PI); return(resultQty); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateRadiusFromDiameter(IQuantity qty, CircularCalculationType type) { if (!type.HasMask(CircularCalculationType.Diameter)) return null; // The dimension should be consistently Length, although the unit itself may be different. qty.VerifyDimensions(L.Meter); var resultQty = (Quantity) qty/2d; return resultQty; }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> /// <a href="!:http://en.wikipedia.org/wiki/Circumference" >Circumference</a> /// <a href="!:http://en.wikipedia.org/wiki/Pi" >Pi</a> private static IQuantity CalculateRadiusFromCircumference(IQuantity qty, CircularCalculationType type) { if (!type.HasMask(CircularCalculationType.Circumference)) return null; //TODO: for these types of calculations, it might make sense to capture a "derived" unit of "circumference", based on "length", but for first class treatment... qty.VerifyDimensions(L.Meter); var resultQty = (Quantity) qty/(2d*Math.PI); return resultQty; }
/// <summary> /// Returns the Radius calculated from the given <see cref="IArea"/> expressed through /// <paramref name="qty"/>. The resulting units will be in alignment with said Qty. /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> /// <a href="!:http://en.wikipedia.org/wiki/Arc_%28geometry%29" >Area (geometry)</a> private static IQuantity CalculateRadiusFromArea(IQuantity qty, CircularCalculationType type) { if (!type.HasMask(CircularCalculationType.Area)) return null; // Dimensions should be Length Squared. Does not matter the unit at this moment. qty.VerifyDimensions(L.Meter.Squared()); var resultQty = ((Quantity) qty/Math.PI).SquareRoot(); return resultQty; }
private static IQuantity CalculateDiameterFromRadius(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Radius)) return null; qty.VerifyDimensions(L.Meter); var resultQty = (Quantity) qty*2d; return resultQty; }
/// <summary> /// Returns the diameter calculated from a circumference. /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateDiameterFromCircumference(IQuantity qty, CircularCalculationType type) { var radiusQty = CalculateRadiusFromCircumference(qty, type); return ReferenceEquals(null, radiusQty) ? null : CalculateDiameterFromRadius(radiusQty, CircularCalculationType.Radius); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateCircumferenceFromDiameter(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Diameter)) return null; /* Results will be in terms of base units. Which is still 2 PI r, but * notice the 2 is understood by the Diameter being 2 r to begin with. */ var resultQty = (Quantity) qty*Math.PI; return resultQty; }
/// <summary> /// Returns whether <paramref name="value"/> Has the <paramref name="mask"/>. /// </summary> /// <param name="value"></param> /// <param name="mask"></param> /// <returns></returns> public static bool HasMask(this CircularCalculationType value, CircularCalculationType mask) { return ((long) value).HasMask((long) mask); }
/// <summary> /// Returns whether <paramref name="value"/> Has the <paramref name="mask"/>. /// </summary> /// <param name="value"></param> /// <param name="mask"></param> /// <returns></returns> public static bool HasMask(this CircularCalculationType value, CircularCalculationType mask) { return(((long)value).HasMask((long)mask)); }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateAreaFromDiameter(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Diameter)) return null; // The dimension should be consistently Length, although the unit itself may be different. qty.VerifyDimensions(L.Meter); var resultQty = (Quantity) ((Quantity) qty/2d).Squared()*Math.PI; return resultQty; }
/// <summary> /// /// </summary> /// <param name="qty"></param> /// <param name="type"></param> /// <returns></returns> private static IQuantity CalculateCircumferenceFromRadius(IQuantity qty, CircularCalculationType type) { if (!type.HasFlag(CircularCalculationType.Radius)) return null; var resultQty = (Quantity) qty*2d*Math.PI; return resultQty; }