From 5c9cb3ff512e1f450fd9042b3066b510c4372f7b Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 20 Oct 2023 12:02:10 +0100 Subject: [PATCH] Review with the help of ChatGPT --- src/NetFabric.Numerics.Angle/README.md | 125 ++++++++++++++------- src/NetFabric.Numerics.Geography/README.md | 29 +++-- src/NetFabric.Numerics/README.md | 79 ++++++++----- 3 files changed, 153 insertions(+), 80 deletions(-) diff --git a/src/NetFabric.Numerics.Angle/README.md b/src/NetFabric.Numerics.Angle/README.md index e7b700b..9bb2de2 100644 --- a/src/NetFabric.Numerics.Angle/README.md +++ b/src/NetFabric.Numerics.Angle/README.md @@ -1,64 +1,120 @@ -# NetFabric.Numerics.Angle: Strongly-Typed Angle Implementation +Certainly, let's restructure the README.md for **NetFabric.Numerics.Angle** following the same structure as the previous READMEs: -**NetFabric.Numerics.Angle** offers a robust, strongly-typed angle implementation. +--- -> **Important:** -> Please be aware that **NetFabric.Numerics.Angle** leverages [generic math](https://learn.microsoft.com/en-us/dotnet/standard/generics/math) capabilities, which are exclusive to .NET 7 and C# 11. Ensure that you are using a compatible version of the framework before integrating this library. If you're working with older versions of .NET, consider using [NetFabric.Angle](https://github.com/NetFabric/NetFabric.Angle) instead. +# NetFabric.Numerics.Angle -``` csharp -using NetFabric.Numerics.Angle; +A Strongly-Typed Angle Implementation in C#. -// Create angles +## Key Features + +- **Strongly-typed** angle implementation. +- Compatibility with **.NET 7** and **C# 11**. +- Comprehensive angular representations with **Angle** and **AngleReduced**. + +## Introduction + +Welcome to **NetFabric.Numerics.Angle** – a robust C# library that simplifies angle calculations with a strong typing approach. + +## Getting Started + +Ensure that you are working in a .NET 7 or higher environment to fully leverage the capabilities of **NetFabric.Numerics.Angle**. Once you're set up, explore the world of strongly-typed angles. + +### Strongly-Typed Angle Creation + +**NetFabric.Numerics.Angle** provides robust angle creation with strong typing: + +```csharp var degreesDoubleAngle = new Angle(45.0); var radiansFloatAngle = new Angle(1.57f); var gradiansDecimalAngle = new Angle(200.0m); var revolutionsHalfAngle = new Angle((Half)0.25); +``` -// Constants -var zeroDegreesDoubleAngle = Angle.Zero; // 0.0 degrees -var rightDegreesFloatAngle = Angle.Right; // 90.0f degrees -var straightRadiansDecimalAngle = Angle.Straight; // π radians -var fullRevolutionsHalfAngle = Angle.Full; // 1 revolution +### Essential Constants -// Perform angle operations +Easily access essential angle constants: + +```csharp +var zeroDegreesDoubleAngle = Angle.Zero; +var rightDegreesFloatAngle = Angle.Right; +var straightRadiansDecimalAngle = Angle.Straight; +var fullRevolutionsHalfAngle = Angle.Full; +``` + +### Angle Operations + +Perform various angle operations with precision: + +```csharp var sum = degreesDoubleAngle + Angle.Right; var difference = gradiansDecimalAngle - Angle.Right; var product = 2.0 * degreesDoubleAngle; var quotient = gradiansDecimalAngle / 100.0m; var remainder = degreesDoubleAngle % 180.0; +``` + +### Angle Comparison -// Compare angles +Easily compare angles for your calculations: + +```csharp var areEqual = degreesDoubleAngle.Equals(Angle.Right); var isGreater = gradiansDecimalAngle > Angle.Right; +``` + +### Angle Conversion -// Convert angles +Convert angles to different units and data types: + +```csharp var convertedToRadians = Angle.ToRadians(degreesDoubleAngle); var convertedToDegrees = Angle.ToDegrees(radiansFloatAngle); var convertedToRevolution = Angle.ToRevolutions(degreesDoubleAngle); -var convertToFloatChecked = Angle.CreateChecked(degreesDoubleAngle); // throws if value is out of range -var convertToFloatSaturating = Angle.CreateSaturating(degreesDoubleAngle); // saturates if value is out of range -var convertToFloatTruncating = Angle.CreateTruncating(degreesDoubleAngle); // truncates if value is out of range +var convertToFloatChecked = Angle.CreateChecked(degreesDoubleAngle); +var convertToFloatSaturating = Angle.CreateSaturating(degreesDoubleAngle); +var convertToFloatTruncating = Angle.CreateTruncating(degreesDoubleAngle); +``` -// Perform trigonometric calculations +### Trigonometric Calculations + +Leverage trigonometric functions for your angle calculations: + +```csharp var sineValue = Angle.Sin(radiansFloatAngle); var cosineValue = Angle.Cos(Angle.ToRadians(degreesDoubleAngle)); var tangentValue = Angle.Tan(radiansFloatAngle); var arcSineRadiansAngle = Angle.Asin(sineValue); +``` + +### Angle Reduction + +Understand the significance of angle reduction in your calculations: -// Reduce angles +```csharp var reducedAngle = Angle.Reduce(degreesDoubleAngle); var quadrant = Angle.GetQuadrant(reducedAngle); var reference = Angle.GetReference(reducedAngle); +``` + +### Classifying Angles + +Classify angles with methods like `IsZero`, `IsAcute`, `IsRight`, `IsObtuse`, `IsStraight`, and more: -// Classify angles +```csharp var isZeroAngle = Angle.IsZero(reducedAngle); var isAcuteAngle = Angle.IsAcute(reducedAngle); var isRightAngle = Angle.IsRight(reducedAngle); var isObtuseAngle = Angle.IsObtuse(reducedAngle); var isStraightAngle = Angle.IsStraight(reducedAngle); +``` + +### Collection Support -// Calculate collection operations +Optimized operations on collections of angles: + +```csharp var angleCollection = new[] { degreesDoubleAngle, Angle.Right, Angle.Straight }; var collectionSum = angleCollection.Sum(); var collectionAverage = angleCollection.Average(); @@ -87,26 +143,9 @@ A prominent benefit of **AngleReduced** is its ability to reduce the frequency o When comparing angles, it's essential to choose the appropriate angle representation, whether **Angle** or **AngleReduced**, depending on the specific requirements of your calculations. -### Key Distinctions: - -- **Angle**. -- **AngleReduced`. When classifying ## Trigonometry -**NetFabric.Numerics.Angle** provides a large number of trigonometric methods: `Sin`, `Cos`, `Tan`, `Sec`, `Csc`, `Cot`, `Sinh`, `Cosh`, `Tanh`, `Sech`, `Csch`, `Coth`, `Asin`, `Acos`, `Atan`, `Acot`, `Asec`, `Acsc` +**NetFabric.Numerics.Angle** provides a large number of trigonometric methods: `Sin`, + + `Cos`, `Tan`, `Sec`, `Csc`, `Cot`, `Sinh`, `Cosh`, `Tanh`, `Sech`, `Csch`, `Coth`, `Asin`, `Acos`, `Atan`, `Acot`, `Asec`, `Acsc` These methods are only available for angles in radians. When using an angle on any other unit, convert it first by using `Angle.ToRadians()`. -## Collections support +## Collections Support **NetFabric.Numerics.Angle** provides optimized operations on collections of angles: `Sum`, `Average`. diff --git a/src/NetFabric.Numerics.Geography/README.md b/src/NetFabric.Numerics.Geography/README.md index 5428a5a..48c93d7 100644 --- a/src/NetFabric.Numerics.Geography/README.md +++ b/src/NetFabric.Numerics.Geography/README.md @@ -1,14 +1,25 @@ # NetFabric.Numerics.Geography -**NetFabric.Numerics.Geography** provides a strongly-typed implementation of geography coordinates and calculations. +Your Strongly-Typed Solution for Geography Coordinates and Calculations in C#! -> WARNING: -> **NetFabric.Numerics.Geography** makes use of [generic math](https://learn.microsoft.com/en-us/dotnet/standard/generics/math) features only available in .NET 7 and C# 11. -> Make sure you are using a compatible version of the framework before using this library. +## Key Features -``` csharp -using NetFabric.Numerics.Geography.Geodetic2; +- **Strongly-typed** implementation of geography coordinates. +- Utilizes the latest [generic math](https://learn.microsoft.com/en-us/dotnet/standard/generics/math) features, compatible with .NET 7 and C# 11. +## Introduction + +Welcome to **NetFabric.Numerics.Geography** – a library tailored for precise geography calculations in C# with a focus on strong typing. + +## Getting Started + +To make the most of **NetFabric.Numerics.Geography**, ensure you're operating within a compatible .NET 7 or higher environment. Once ready, explore the world of geography with strong typing. + +### Strongly-Typed Geography Coordinates + +**NetFabric.Numerics.Geography** distinguishes itself with a **strongly-typed** approach to geography coordinates. It covers various datums, including WGS84, NAD83, and more, providing accuracy through strong typing: + +```csharp var wgs84Point = new Point(new(0.0), new(0.0)); // LatLon point using WGS84 datum var wgs1972Point = new Point(new(0.0), new(0.0)); // LatLon point using WGS1972 datum var nad83Point = new Point(new(0.0), new(0.0)); // LatLon point using NAD83 datum @@ -18,12 +29,16 @@ var doublePrecisionPoint = new Point(new(0.0), new(0.0)) var singlePrecisionPoint = new Point(new(0.0f), new(0.0f)); // LatLon point with single precision var minutesPoint = new Point(Angle.ToDegrees(0, 0.0), Angle.ToDegrees(0, 0.0)); // LatLon point using degrees and minutes -var minutesSecondsPoint = new Point(Angle.ToDegrees(0, 0, 0.0), Angle.ToDegrees(0, 0, 0.0)); // LatLon point using degrees, minutes and seconds +var minutesSecondsPoint = new Point(Angle.ToDegrees(0, 0, 0.0), Angle.ToDegrees(0, 0, 0.0)); // LatLon point using degrees, minutes, and seconds var (degreesLatitude, minutesLatitude) = Angle.ToDegreesMinutes(wgs84Point.Latitude); // Convert latitude to degrees and minutes var (degreesLatitude2, minutesLatitude2, secondsLatitude) = Angle.ToDegreesMinutesSeconds(wgs84Point.Latitude); // Convert latitude to degrees, minutes, and seconds ``` +### Geography with Strong Typing + +Explore how **NetFabric.Numerics.Geography** can enhance your geography calculations with strong typing. Discover the precision, safety, and versatility it brings to C# geography operations. + ## Credits The following open-source projects are used to build and test this project: diff --git a/src/NetFabric.Numerics/README.md b/src/NetFabric.Numerics/README.md index 6fe9830..81cba1e 100644 --- a/src/NetFabric.Numerics/README.md +++ b/src/NetFabric.Numerics/README.md @@ -1,52 +1,69 @@ # NetFabric.Numerics -**NetFabric.Numerics** provides strongly-typed implementations for cartesian and polar coordinates, and operations for 2D and 3D vectors and quaternions. +Your Comprehensive Strongly-Typed Toolkit for Numeric and Geometric Operations in C#! -> WARNING: -> **NetFabric.Numerics** makes use of [generic math](https://learn.microsoft.com/en-us/dotnet/standard/generics/math) features only available in .NET 7 and C# 11. -> Make sure you are using a compatible version of the framework before using this library. +## Key Features -``` csharp -using NetFabric.Numerics; +- **Strongly-typed** implementations for cartesian, polar, and spherical coordinates. +- Seamless operations on 2D and 3D vectors and quaternions. +- Leveraging the latest [generic math](https://learn.microsoft.com/en-us/dotnet/standard/generics/math) features, available in .NET 7 and C# 11. -// Create points -var point2DInteger = new Cartesian2.Point(10, 20); -var point2DFloat = new Cartesian2.Point(10.0f, 20.0f); -var point2DDouble = new Cartesian2.Point(10.0, 20.0); +## Introduction + +Welcome to **NetFabric.Numerics** – a versatile library designed to simplify numeric and geometric calculations in C#. + +## Getting Started + +To harness the full capabilities of **NetFabric.Numerics**, ensure you have a compatible .NET 7 or higher environment. Once you're set up, you can unlock the potential of various coordinate systems and efficient operations. -var pointPolarDegreesFloat = new Polar.Point( - Angle.Right, // 90 degrees azimuth - 10.0f); // radius -var pointPolarRadiansDouble = new Polar.Point( - new Angle(double.Pi), // 180 degrees azimuth - 10.0f); // radius +### Strongly-Typed Coordinates -var point3DInteger = new Cartesian3.Point(10, 20, 30); -var point3DFloat = new Cartesian3.Point(10.0f, 20.0f, 30.0f); +**NetFabric.Numerics** shines with its **strongly-typed** approach to coordinate systems. Whether you're dealing with 2D, 3D, polar, or spherical coordinates, our library offers precision with strong typing: + +```csharp +var point2DInteger = new Cartesian2.Point(10, 20); +var point2DFloat = new Cartesian2.Point(10.0f, 20.0f); var point3DDouble = new Cartesian3.Point(10.0, 20.0, 30.0); +var pointPolarDegreesFloat = new Polar.Point(Angle.Right, 10.0f); +var pointPolarRadiansDouble = new Polar.Point(new Angle(Math.PI), 10.0f); + var pointSphericalDegreesFloat = new Spherical.Point( - Angle.Zero, // 0 degrees azimuth - Angle.Right, // 90 degrees zenith - 10.0f); // radius + Angle.Zero, // Azimuth: 0 degrees + Angle.Right, // Zenith: 90 degrees + 10.0f); // Radius +``` -// Create quaternions +### Quaternions Made Easy + +Quaternions are crucial for orientation and rotation. With **NetFabric.Numerics**, you can create them with strong typing and ease: + +```csharp var quaternionFloat = new Cartesian3.Quaternion(1.0f, 2.0f, 3.0f, 4.0f); -var quaternionDouble = Cartesian3.Quaternion.FromYawPitchRoll( - Angle.Zero, // 0 degrees yaw - Angle.Zero, // 0 degrees pitch - Angle.Right); // 90 degrees roll +var quaternionDouble = Cartesian3.Quaternion.FromYawPitchRoll(Angle.Zero, Angle.Right); +``` + +### Efficient Math Operations + +Elevate your numeric operations with our library. Enjoy simple, efficient, and accurate calculations with strong typing: -// Perform math operations +```csharp var vector3DDouble = point3DDouble - new Cartesian3.Point(1.0, 1.0, 1.0); var point3DTransformed = point3DDouble + vector3DDouble; +``` + +### Simple Conversions -// Conversions -var convertToFloatChecked = Cartesian3.Point.CreateChecked(point3DDouble); // throws if value is out of range -var convertToFloatSaturated = Cartesian3.Point.CreateSaturating(point3DDouble); // saturate if value is out of range -var convertToFloatTruncated = Cartesian3.Point.CreateTruncating(point3DDouble); // truncate if value is out of range +**NetFabric.Numerics** simplifies converting between different numeric types while preserving strong typing. You choose how to handle out-of-range values: + +```csharp +var convertToFloatChecked = Cartesian3.Point.CreateChecked(point3DDouble); +var convertToFloatSaturated = Cartesian3.Point.CreateSaturating(point3DDouble); +var convertToFloatTruncated = Cartesian3.Point.CreateTruncating(point3DDouble); ``` +Discover how **NetFabric.Numerics** can simplify your numeric and geometric challenges today. + ## Credits The following open-source projects are used to build and test this project: