From d3517a86fb72b811615aa6f0abc3f042d875983e Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Thu, 16 Nov 2023 15:48:44 +0300 Subject: Add comments --- MindBox.Lib/Triangle.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'MindBox.Lib/Triangle.cs') diff --git a/MindBox.Lib/Triangle.cs b/MindBox.Lib/Triangle.cs index 54e8a85..58cdb91 100644 --- a/MindBox.Lib/Triangle.cs +++ b/MindBox.Lib/Triangle.cs @@ -2,6 +2,7 @@ namespace MindBox.Lib; public class Triangle : FlatShape { + // Может потребоваться хранить разные стороны в разных полях, но для нашей задачи это избыточно private readonly double[] _sides; public Triangle(double a, double b, double c) @@ -16,6 +17,9 @@ public class Triangle : FlatShape throw new ArgumentException($"Sides lengths are not valid: {a}, {b}, {c}"); } } + /// + /// Вычисление площади реугольника по формуле Герона + /// public override double GetArea() { if (_area != null) @@ -31,14 +35,16 @@ public class Triangle : FlatShape (semiPerimeter - _sides[2])); return _area.Value; } - } + } public bool IsRight() { var sorted = _sides.OrderByDescending(x => x); + // Самая длинная сторона: гипотенуза double hypotenuse = sorted.First(); + // Две другие - катеты var catheti = sorted.Skip(1); return hypotenuse * hypotenuse == catheti.Sum(x => x * x); - } + } } -- cgit v1.2.3