Add more shapes

This commit is contained in:
Stone_Red
2024-03-18 22:09:29 +01:00
parent 5269a8d56d
commit 80b5cc5109
4 changed files with 72 additions and 14 deletions
+12
View File
@@ -0,0 +1,12 @@
namespace CuteUtils.FluentMath.Shapes;
public class Circle(double radius)
{
public double Radius { get; set; } = radius;
public double Diameter => Radius * 2;
public double Circumference => 2 * Math.PI * Radius;
public double Area => Math.PI * Math.Pow(Radius, 2);
}
@@ -0,0 +1,12 @@
namespace CuteUtils.FluentMath.Shapes;
public class Ellipse(double majorAxis, double minorAxis)
{
public double MajorAxis { get; set; } = majorAxis;
public double MinorAxis { get; set; } = minorAxis;
public double Area => Math.PI * MajorAxis * MinorAxis;
public double Circumference => Math.PI * ((3 * (MajorAxis + MinorAxis)) - Math.Sqrt(((3 * MajorAxis) + MinorAxis) * (MajorAxis + (3 * MinorAxis))));
public bool IsCircle => MajorAxis == MinorAxis;
}
+13 -14
View File
@@ -3,17 +3,22 @@
/// <summary> /// <summary>
/// Represents a rectangle /// Represents a rectangle
/// </summary> /// </summary>
public class Rectangle /// <remarks>
/// Creates a new rectangle instance
/// </remarks>
/// <param name="length">The length of the rectangle</param>
/// <param name="width">The width of the rectangle</param>
public class Rectangle(double length, double width)
{ {
/// <summary> /// <summary>
/// The length of the <see cref="Rectangle"/> /// The length of the <see cref="Rectangle"/>
/// </summary> /// </summary>
public double Length { get; set; } public double Length { get; set; } = length;
/// <summary> /// <summary>
/// The width of the <see cref="Rectangle"/> /// The width of the <see cref="Rectangle"/>
/// </summary> /// </summary>
public double Width { get; set; } public double Width { get; set; } = width;
/// <summary> /// <summary>
/// The diagonal of the <see cref="Rectangle"/> /// The diagonal of the <see cref="Rectangle"/>
@@ -28,16 +33,10 @@ public class Rectangle
/// <summary> /// <summary>
/// The perimeter of the <see cref="Rectangle"/> /// The perimeter of the <see cref="Rectangle"/>
/// </summary> /// </summary>
public double Perimeter => Length * 2 + Width * 2; public double Perimeter => (Length * 2) + (Width * 2);
/// <summary> public bool IsSquare => Length == Width;
/// Creates a new rectangle instance public bool IsRectangle => !IsSquare;
/// </summary>
/// <param name="length">The length of the rectangle</param> public bool IsGolden => Length / Width == 1.61803398875;
/// <param name="width">The width of the rectangle</param>
public Rectangle(double length, double width)
{
Length = length;
Width = width;
}
} }
@@ -0,0 +1,35 @@
namespace CuteUtils.FluentMath.Shapes;
public class Triangle(double sideA, double sideB, double sideC)
{
public double SideA { get; set; } = sideA;
public double SideB { get; set; } = sideB;
public double SideC { get; set; } = sideC;
public double Area
{
get
{
double s = (SideA + SideB + SideC) / 2;
return Math.Sqrt(s * (s - SideA) * (s - SideB) * (s - SideC));
}
}
public double Perimeter => SideA + SideB + SideC;
public bool IsRightAngled
{
get
{
double[] sides = [SideA, SideB, SideC];
Array.Sort(sides);
return Math.Pow(sides[0], 2) + Math.Pow(sides[1], 2) == Math.Pow(sides[2], 2);
}
}
public bool IsEquilateral => SideA == SideB && SideB == SideC;
public bool IsIsosceles => SideA == SideB || SideB == SideC || SideA == SideC;
public bool IsScalene => !IsEquilateral && !IsIsosceles;
}