Skip to content

Commit

Permalink
Review with the help of ChatGPT
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Oct 20, 2023
1 parent 98ead27 commit 5c9cb3f
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 80 deletions.
125 changes: 83 additions & 42 deletions src/NetFabric.Numerics.Angle/README.md
Original file line number Diff line number Diff line change
@@ -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<Degrees, double>(45.0);
var radiansFloatAngle = new Angle<Radians, float>(1.57f);
var gradiansDecimalAngle = new Angle<Gradians, decimal>(200.0m);
var revolutionsHalfAngle = new Angle<Revolutions, Half>((Half)0.25);
```

// Constants
var zeroDegreesDoubleAngle = Angle<Degrees, double>.Zero; // 0.0 degrees
var rightDegreesFloatAngle = Angle<Degrees, float>.Right; // 90.0f degrees
var straightRadiansDecimalAngle = Angle<Radians, decimal>.Straight; // π radians
var fullRevolutionsHalfAngle = Angle<Revolutions, Half>.Full; // 1 revolution
### Essential Constants

// Perform angle operations
Easily access essential angle constants:

```csharp
var zeroDegreesDoubleAngle = Angle<Degrees, double>.Zero;
var rightDegreesFloatAngle = Angle<Degrees, float>.Right;
var straightRadiansDecimalAngle = Angle<Radians, decimal>.Straight;
var fullRevolutionsHalfAngle = Angle<Revolutions, Half>.Full;
```

### Angle Operations

Perform various angle operations with precision:

```csharp
var sum = degreesDoubleAngle + Angle<Degrees, double>.Right;
var difference = gradiansDecimalAngle - Angle<Gradians, decimal>.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<Gradians, double>.Right);
var isGreater = gradiansDecimalAngle > Angle<Gradians, decimal>.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<Degrees, float>.CreateChecked(degreesDoubleAngle); // throws if value is out of range
var convertToFloatSaturating = Angle<Degrees, float>.CreateSaturating(degreesDoubleAngle); // saturates if value is out of range
var convertToFloatTruncating = Angle<Degrees, float>.CreateTruncating(degreesDoubleAngle); // truncates if value is out of range
var convertToFloatChecked = Angle<Degrees, float>.CreateChecked(degreesDoubleAngle);
var convertToFloatSaturating = Angle<Degrees, float>.CreateSaturating(degreesDoubleAngle);
var convertToFloatTruncating = Angle<Degrees, float>.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<Degrees, double>.Right, Angle<Degrees, double>.Straight };
var collectionSum = angleCollection.Sum();
var collectionAverage = angleCollection.Average();
Expand Down Expand Up @@ -87,38 +143,23 @@ 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<TUnits, T** represents an angle using a value of type **T** within the chosen **TUnits** unit. The **T** type can encompass various data types, such as **Half**, **float**, **double**, **decimal**, or any other implementation of **IFloatingPoint<TSelf>**.
- **AngleReduced<TUnits, T** represents an angle with a value of type **T** within the same **TUnits** unit but reduced to the range **[TUnits.Zero, TUnits.Full[**.

### Range Considerations

- **Angle<TUnits, T** has the capacity to represent any angle value within the range of **[T.MinValue, T.MaxValue]** within the specified **TUnits** unit. However, certain operations may necessitate reducing the angle to the range of **[TUnits.Zero, TUnits.Full[**. To optimize performance in such scenarios, consider employing **AngleReduced<TUnits, T**, which guarantees that the angle is already in a reduced form.

### Unit Conversion

To facilitate the versatile usage of angle values in different units, you can utilize methods like **ToDegrees()**, **ToGradians()**, **ToRadians()**, and **ToRevolutions()**. These methods offer a convenient way to convert angles from one unit to another, enabling you to adapt angle values to the specific requirements of your calculations.

### Data Type Conversion

Additionally, the angle library provides methods like **CreateChecked()**, **CreateSaturating()**, and **CreateTruncating()** to manage data type conversion. These methods cater to diverse scenarios, allowing you to choose between checked, saturating, or truncating conversions based on your specific requirements for data type conversion.

In conclusion, the choice between **Angle** and **AngleReduced** depends on the nature of your angle-related computations. Be mindful of their distinctions and use the one that best aligns with your specific needs for representing and comparing angles, managing units, handling data type conversions, and reducing the frequency of angle reduction operations.

## Angle classification
## Angle Classification

**NetFabric.Numerics.Angle** provides a large number of methods to classify an angle: `IsZero`, `IsAcute`, `IsRight`, `IsObtuse`, `IsStraight`, `IsReflex`, `IsOblique`, `AreComplementary`, `AreSupplementary`

These methods are only available for `AngleReduced<TUnits, T>`. When classifying a `Angle<TUnits, T>`, reduce it first by using `Angle.Reduce()`.

## 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`.

Expand Down
29 changes: 22 additions & 7 deletions src/NetFabric.Numerics.Geography/README.md
Original file line number Diff line number Diff line change
@@ -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<WGS84, Degrees, double>(new(0.0), new(0.0)); // LatLon point using WGS84 datum
var wgs1972Point = new Point<WGS1972, Degrees, double>(new(0.0), new(0.0)); // LatLon point using WGS1972 datum
var nad83Point = new Point<NAD83, Degrees, double>(new(0.0), new(0.0)); // LatLon point using NAD83 datum
Expand All @@ -18,12 +29,16 @@ var doublePrecisionPoint = new Point<WGS84, Degrees, double>(new(0.0), new(0.0))
var singlePrecisionPoint = new Point<WGS84, Degrees, float>(new(0.0f), new(0.0f)); // LatLon point with single precision
var minutesPoint = new Point<WGS84, Degrees, double>(Angle.ToDegrees<double>(0, 0.0), Angle.ToDegrees<double>(0, 0.0)); // LatLon point using degrees and minutes
var minutesSecondsPoint = new Point<WGS84, Degrees, double>(Angle.ToDegrees<double>(0, 0, 0.0), Angle.ToDegrees<double>(0, 0, 0.0)); // LatLon point using degrees, minutes and seconds
var minutesSecondsPoint = new Point<WGS84, Degrees, double>(Angle.ToDegrees<double>(0, 0, 0.0), Angle.ToDegrees<double>(0, 0, 0.0)); // LatLon point using degrees, minutes, and seconds
var (degreesLatitude, minutesLatitude) = Angle.ToDegreesMinutes<double, int, double>(wgs84Point.Latitude); // Convert latitude to degrees and minutes
var (degreesLatitude2, minutesLatitude2, secondsLatitude) = Angle.ToDegreesMinutesSeconds<double, int, int, double>(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:
Expand Down
79 changes: 48 additions & 31 deletions src/NetFabric.Numerics/README.md
Original file line number Diff line number Diff line change
@@ -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<int>(10, 20);
var point2DFloat = new Cartesian2.Point<float>(10.0f, 20.0f);
var point2DDouble = new Cartesian2.Point<double>(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<Degrees, float, float>(
Angle<Degrees, float>.Right, // 90 degrees azimuth
10.0f); // radius
var pointPolarRadiansDouble = new Polar.Point<Radians, double, double>(
new Angle<Radians, double>(double.Pi), // 180 degrees azimuth
10.0f); // radius
### Strongly-Typed Coordinates

var point3DInteger = new Cartesian3.Point<int>(10, 20, 30);
var point3DFloat = new Cartesian3.Point<float>(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<int>(10, 20);
var point2DFloat = new Cartesian2.Point<float>(10.0f, 20.0f);
var point3DDouble = new Cartesian3.Point<double>(10.0, 20.0, 30.0);

var pointPolarDegreesFloat = new Polar.Point<Degrees, float, float>(Angle<Degrees, float>.Right, 10.0f);
var pointPolarRadiansDouble = new Polar.Point<Radians, double, double>(new Angle<Radians, double>(Math.PI), 10.0f);

var pointSphericalDegreesFloat = new Spherical.Point<Degrees, float, float>(
Angle<Degrees, float>.Zero, // 0 degrees azimuth
Angle<Degrees, float>.Right, // 90 degrees zenith
10.0f); // radius
Angle<Degrees, float>.Zero, // Azimuth: 0 degrees
Angle<Degrees, float>.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<float>(1.0f, 2.0f, 3.0f, 4.0f);
var quaternionDouble = Cartesian3.Quaternion.FromYawPitchRoll<double>(
Angle<Radians, double>.Zero, // 0 degrees yaw
Angle<Radians, double>.Zero, // 0 degrees pitch
Angle<Radians, double>.Right); // 90 degrees roll
var quaternionDouble = Cartesian3.Quaternion.FromYawPitchRoll<double>(Angle<Radians, double>.Zero, Angle<Radians, double>.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<double>(1.0, 1.0, 1.0);
var point3DTransformed = point3DDouble + vector3DDouble;
```

### Simple Conversions

// Conversions
var convertToFloatChecked = Cartesian3.Point<float>.CreateChecked(point3DDouble); // throws if value is out of range
var convertToFloatSaturated = Cartesian3.Point<float>.CreateSaturating(point3DDouble); // saturate if value is out of range
var convertToFloatTruncated = Cartesian3.Point<float>.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<float>.CreateChecked(point3DDouble);
var convertToFloatSaturated = Cartesian3.Point<float>.CreateSaturating(point3DDouble);
var convertToFloatTruncated = Cartesian3.Point<float>.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:
Expand Down

0 comments on commit 5c9cb3f

Please sign in to comment.