コード例 #1
0
 /// <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);
 }
コード例 #2
0
 /// <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));
 }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 /// <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));
 }
コード例 #5
0
        /// <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));
        }
コード例 #6
0
        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))
            {
            }
        }
コード例 #7
0
        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))
            {
            }
        }
コード例 #8
0
        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))
            {
            }
        }
コード例 #9
0
        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))
            {
            }
        }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
        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);
        }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
 /// <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;
 }
コード例 #16
0
        /// <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);
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
        /// <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);
        }
コード例 #19
0
        /// <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;
        }
コード例 #20
0
        /// <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;
        }
コード例 #21
0
        /// <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;
        }
コード例 #22
0
        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;
        }
コード例 #23
0
 /// <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);
 }
コード例 #24
0
        /// <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;
        }
コード例 #25
0
 /// <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);
 }
コード例 #26
0
 /// <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));
 }
コード例 #27
0
        /// <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;
        }
コード例 #28
0
        /// <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;
        }