From 6ede8c04ff49dca0c84d86ad356c1f967a91b3f6 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos Date: Wed, 9 Aug 2023 23:06:57 +0200 Subject: [PATCH 1/2] Extracted method `IsPerfectRectangle` in `EllipseEngine` --- Pinta.Tools/Editable/Shapes/EllipseEngine.cs | 26 +++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Pinta.Tools/Editable/Shapes/EllipseEngine.cs b/Pinta.Tools/Editable/Shapes/EllipseEngine.cs index c17c5ced0..18fe5f191 100644 --- a/Pinta.Tools/Editable/Shapes/EllipseEngine.cs +++ b/Pinta.Tools/Editable/Shapes/EllipseEngine.cs @@ -60,6 +60,20 @@ public override ShapeEngine Clone () return new EllipseEngine (this); } + private static bool IsPerfectRectangle (PointD cp0, PointD cp1, PointD cp2, PointD cp3) + { + if (cp0.X == cp1.X) { + if (cp0.Y == cp3.Y && cp1.Y == cp2.Y && cp2.X == cp3.X) { + return true; + } + } else if (cp0.Y == cp1.Y) { + if (cp0.X == cp3.X && cp1.X == cp2.X && cp2.Y == cp3.Y) { + return true; + } + } + return false; + } + /// /// Generate each point in an elliptic shape and store the result in GeneratedPoints. /// The width of the brush that will be used to draw the shape. @@ -77,17 +91,7 @@ public override void GeneratePoints (int brush_width) //An ellipse also requires that all 4 control points compose a perfect rectangle parallel/perpendicular to the window. //So, confirm that it is indeed a perfect rectangle. - bool perfectRectangle = false; - - if (cp0.X == cp1.X) { - if (cp0.Y == cp3.Y && cp1.Y == cp2.Y && cp2.X == cp3.X) { - perfectRectangle = true; - } - } else if (cp0.Y == cp1.Y) { - if (cp0.X == cp3.X && cp1.X == cp2.X && cp2.Y == cp3.Y) { - perfectRectangle = true; - } - } + bool perfectRectangle = IsPerfectRectangle (cp0, cp1, cp2, cp3); if (perfectRectangle) { //It is expected that the 4 control points always form a perfect rectangle parallel/perpendicular to the window. From dd8ae4263f51d4eccd98bdf7d1d6221069009272 Mon Sep 17 00:00:00 2001 From: Lehonti Ramos Date: Wed, 9 Aug 2023 23:09:56 +0200 Subject: [PATCH 2/2] Removed blank line that could make the code confusing to read --- Pinta.Tools/Editable/Shapes/EllipseEngine.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Pinta.Tools/Editable/Shapes/EllipseEngine.cs b/Pinta.Tools/Editable/Shapes/EllipseEngine.cs index 18fe5f191..8d47e7823 100644 --- a/Pinta.Tools/Editable/Shapes/EllipseEngine.cs +++ b/Pinta.Tools/Editable/Shapes/EllipseEngine.cs @@ -90,7 +90,6 @@ public override void GeneratePoints (int brush_width) //An ellipse also requires that all 4 control points compose a perfect rectangle parallel/perpendicular to the window. //So, confirm that it is indeed a perfect rectangle. - bool perfectRectangle = IsPerfectRectangle (cp0, cp1, cp2, cp3); if (perfectRectangle) {