Esempio n. 1
0
        public CustomAreaCalculator(Func <IReadOnlyList <double>, double> formula, double[] arguments)
        {
            CheckArgument.NotNull(formula, nameof(formula));
            CheckArgument.NotNull(arguments, nameof(arguments));

            this.arguments = new double[arguments.Length];
            Array.Copy(arguments, this.arguments, arguments.Length);
            Formula = formula;
        }
Esempio n. 2
0
        public static bool IsRectangular(this TriangleByThreeSides triangle)
        {
            CheckArgument.NotNull(triangle, nameof(triangle));

            var squares =
                new[] { triangle.A, triangle.B, triangle.C }
            .Select(i => Math.Pow(i, 2))
            .ToArray();

            return(Enumerable.Range(0, squares.Length).Any(index => IsHypotenuse(index)));

            bool IsHypotenuse(int index) =>
            Math.Abs(squares[index] - squares.SkipAt(index).Sum()) < Tolerance.Epsilon;
        }
Esempio n. 3
0
        public TriangleByThreeSides(double a, double b, double c)
        {
            CheckArgument.GreaterThanZero(a, nameof(a));
            CheckArgument.GreaterThanZero(b, nameof(b));
            CheckArgument.GreaterThanZero(c, nameof(c));

            if (!IsTriangle(a, b, c))
            {
                throw new ArgumentException("The sum of the lengths of any two sides of a triangle is greater than the length of the third side.");
            }

            A = a;
            B = b;
            C = c;
        }
Esempio n. 4
0
        public static IEnumerable <T> SkipAt <T>(this IEnumerable <T> collection, int index)
        {
            CheckArgument.NotNull(collection, nameof(collection));

            return(collection.SkipAtImpl(index));
        }
Esempio n. 5
0
 public CircleByRadius(double radius)
 {
     CheckArgument.GreaterThanZero(radius, nameof(radius));
     Radius = radius;
 }