Skip to content

Commit

Permalink
Extracted method IsPerfectRectangle in EllipseEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehonti Ramos committed Aug 9, 2023
1 parent cb92af1 commit 6ede8c0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 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 @@ -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.
Expand Down

0 comments on commit 6ede8c0

Please sign in to comment.