Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracted method IsPerfectRectangle in EllipseEngine #326

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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