From 972b198a281cc59d2fbb1dc91964d8cba4aabfed Mon Sep 17 00:00:00 2001 From: Mateusz Szewczyk Date: Sun, 14 Apr 2024 13:29:25 +0200 Subject: [PATCH] Added documentation comments + code formatted --- GeometryCalculator/GeometryCalculator.fsproj | 4 +- GeometryCalculator/Library.fs | 71 +++++++++++++------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/GeometryCalculator/GeometryCalculator.fsproj b/GeometryCalculator/GeometryCalculator.fsproj index 138f4d9..4bcc86b 100644 --- a/GeometryCalculator/GeometryCalculator.fsproj +++ b/GeometryCalculator/GeometryCalculator.fsproj @@ -11,7 +11,9 @@ Mateusz Szewczyk <MAtt5816> https://github.com/MAtt5816/geometry-calculator/blob/1.0.0/LICENSE https://github.com/MAtt5816/geometry-calculator - calculator;solids;figures;figures-calculator + calculator;solids;figures;figures-calculator;ellipsoid;sphere + 1.0.1 + GeometryCalculator diff --git a/GeometryCalculator/Library.fs b/GeometryCalculator/Library.fs index 4c7ad95..6d351b4 100644 --- a/GeometryCalculator/Library.fs +++ b/GeometryCalculator/Library.fs @@ -5,48 +5,72 @@ module Ellipsoid = module private Area = module Rotational = - let e a c = - sqrt(1. - a**2. / c**2.) - module General = + let e a c = sqrt (1. - a ** 2. / c ** 2.) + + module General = open FSharp.Stats.Integration let f psi k = - let integral x = 1. / sqrt(1. - k**2. * sin(x)**2.) - integral |> NumericalIntegration.definiteIntegral(LeftEndpoint, 0., psi, 100) - let e psi k = - let integral x = sqrt(1. - k**2. * sin(x)**2.) - integral |> NumericalIntegration.definiteIntegral(LeftEndpoint, 0., psi, 100) + let integral x = + 1. / sqrt (1. - k ** 2. * sin (x) ** 2.) + + integral |> NumericalIntegration.definiteIntegral (LeftEndpoint, 0., psi, 100) + + let e psi k = + let integral x = sqrt (1. - k ** 2. * sin (x) ** 2.) + integral |> NumericalIntegration.definiteIntegral (LeftEndpoint, 0., psi, 100) let m a b c = - a**2. * (b**2. - c**2.) / (b**2. * (a**2. - c**2.)) + a ** 2. * (b ** 2. - c ** 2.) / (b ** 2. * (a ** 2. - c ** 2.)) - let private epsilon a c = - sqrt(1. - (c**2. / a**2.)) - let tau a c = - asin(epsilon a c) + let private epsilon a c = sqrt (1. - (c ** 2. / a ** 2.)) + let tau a c = asin (epsilon a c) - let sphere r = 4. * Math.PI * r**2. + let sphere r = 4. * Math.PI * r ** 2. - let rotationalEllipsoid c a = + let rotationalEllipsoid c a = if c < a then let eValue = Rotational.e c a - 2. * Math.PI * a**2. + Math.PI * c**2. / eValue * log((1. + eValue) / (1. - eValue)) + + 2. * Math.PI * a ** 2. + + Math.PI * c ** 2. / eValue * log ((1. + eValue) / (1. - eValue)) else let eValue = Rotational.e a c - 2. * Math.PI * a**2. * (1. + c / (a * eValue) * asin(eValue)) + 2. * Math.PI * a ** 2. * (1. + c / (a * eValue) * asin (eValue)) - let generalEllipsoid a b c = + let generalEllipsoid a b c = let tauValue = General.tau a c let mValue = General.m a b c - 2. * Math.PI * (c**2. + (b * c**2.) / sqrt(a**2. - c**2.) * (General.f tauValue mValue) + b * sqrt(a**2. - c**2.) * (General.e tauValue mValue)) + 2. * Math.PI + * (c ** 2. + + (b * c ** 2.) / sqrt (a ** 2. - c ** 2.) * (General.f tauValue mValue) + + b * sqrt (a ** 2. - c ** 2.) * (General.e tauValue mValue)) + /// + /// Function for ellipsoid volume calculation. + /// + /// + /// Non-negative double or double.NaN in case at least one negative parameter + /// + /// a parameter >= 0 + /// b parameter >= 0 + /// c parameter >= 0 let volume a b c = if a > 0. && b > 0. && c > 0. then 4. / 3. * Math.PI * a * b * c else nan + /// + /// Function for ellipsoid area calculation. + /// + /// + /// Non-negative double if >= >= , else double.NaN + /// + /// a parameter >= 0 + /// b parameter >= 0 + /// c parameter >= 0 let area a b c = if a > 0. && b > 0. && c > 0. then if a = b && b = c then @@ -56,10 +80,9 @@ module Ellipsoid = Area.rotationalEllipsoid c a else Area.rotationalEllipsoid a b + else if a > b && b > c then + Area.generalEllipsoid a b c else - if a > b && b > c then - Area.generalEllipsoid a b c - else - nan + nan else - nan \ No newline at end of file + nan