From 3d3f3b62aa53069b9dba71b0129e326c3df57b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Fri, 7 Oct 2022 15:52:25 +0200 Subject: [PATCH] Added Diamond class (#1) --- PeyrSharp.Core/Maths/Geometry/Diamond.cs | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 PeyrSharp.Core/Maths/Geometry/Diamond.cs diff --git a/PeyrSharp.Core/Maths/Geometry/Diamond.cs b/PeyrSharp.Core/Maths/Geometry/Diamond.cs new file mode 100644 index 0000000..8df49c9 --- /dev/null +++ b/PeyrSharp.Core/Maths/Geometry/Diamond.cs @@ -0,0 +1,75 @@ +/* +MIT License + +Copyright (c) Léo Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +using System; + +namespace PeyrSharp.Core.Maths.Geometry +{ + /// + /// A class that represents a Diamond. + /// + public class Diamond + { + /// + /// The length of the side of the . + /// + public double Side { get; init; } + + /// + /// The perimeter of the . + /// + public double Perimeter => 4 * Side; + + /// + /// An array containing the values of the diagonals of the if initialized with the corresponding constructor. + /// + public double[] Diagonals { get; init; } + + /// + /// The area of the . + /// + public double Area => Diagonals[0] * (Diagonals[1] / 2); + + /// + /// Initializes a from the length of its side. + /// + /// The length of the side. + public Diamond(double side) + { + if (side <= 0) throw new DivideByZeroException("Please provide a value higher than 0."); + Side = side; + } + + /// + /// Initializes a from its diagonals. + /// + /// The length of the first diagonal. + /// The length of the second diagonal. + public Diamond(double diagonal1, double diagonal2) + { + if (diagonal1 <= 0 || diagonal2 <= 0) throw new DivideByZeroException("Please provide a value higher than 0."); + Diagonals = new double[2] { diagonal1, diagonal2 }; + } + } +}