Skip to content

Commit

Permalink
Extracted method IsPerfectRectangle in EllipseEngine (#326)
Browse files Browse the repository at this point in the history
* Extracted method `IsPerfectRectangle` in `EllipseEngine`

* Removed blank line that could make the code confusing to read

---------

Co-authored-by: Lehonti Ramos <john@doe>
  • Loading branch information
Lehonti and Lehonti Ramos authored Aug 10, 2023
1 parent 5081289 commit 92095bd
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Pinta.Tools/Editable/Shapes/EllipseEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// Generate each point in an elliptic shape and store the result in GeneratedPoints.
/// <param name="brush_width">The width of the brush that will be used to draw the shape.</param>
Expand All @@ -76,18 +90,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.
Expand Down

0 comments on commit 92095bd

Please sign in to comment.