Private
Public Access
Made Rectangle work properly
This commit is contained in:
1 parent
29f384a3b4
commit
6f961f908b
2 files changed
+32
-50
No files matched your search
+30
-42
@@ -4,6 +4,7 @@ using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// <summary>
|
||||
@@ -16,71 +17,58 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
Verb verb;
|
||||
|
||||
Drawer drawer;
|
||||
List<Point> points;
|
||||
bool correctForOrigin;
|
||||
PointF[] points;
|
||||
|
||||
double width;
|
||||
double height;
|
||||
|
||||
/// <summary>
|
||||
/// Create a rectangle instance
|
||||
/// Create a rectangle instance. Makes sure that
|
||||
/// </summary>
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="width">rectangle width</param>
|
||||
/// <param name="height">rectangle height</param>
|
||||
/// <param name="center">weather to center the rectangle on the pen</param>
|
||||
public Rectangle(Drawer drawer, double width, double height, bool center = true) {
|
||||
this.drawer = drawer;
|
||||
correctForOrigin = true;
|
||||
|
||||
PointF[] points = new PointF[]
|
||||
{
|
||||
new PointF((float) -width, (float) -height),
|
||||
new PointF((float) width, (float) -height),
|
||||
new PointF((float) width, (float) height),
|
||||
new PointF((float) -width, (float) height)
|
||||
};
|
||||
|
||||
this.points = new List<Point>();
|
||||
foreach (PointF pointF in points) this.points.Add(new Point((int)Math.Round(pointF.X), (int)Math.Round(pointF.Y)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a rectangle instance
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Unlike the above, this instance creates points based on widths and heights of the two points
|
||||
/// </remarks>
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="point1">point spawn</param>
|
||||
/// <param name="point2">point spawn</param>
|
||||
public Rectangle(Drawer drawer, Point point1, Point point2) {
|
||||
public Rectangle(Drawer drawer, double width, double height) {
|
||||
this.drawer = drawer;
|
||||
|
||||
PointF[] points = new PointF[]
|
||||
float root2 = (float) Math.Sqrt(2) / 2;
|
||||
|
||||
points = new PointF[]
|
||||
{
|
||||
new PointF((float) point1.X, (float) point1.Y),
|
||||
new PointF((float) point1.X, (float) point2.Y),
|
||||
new PointF((float) point2.X, (float) point2.Y),
|
||||
new PointF((float) point2.X, (float) point1.Y)
|
||||
new PointF((float) -width * root2, (float) -height * root2),
|
||||
new PointF((float) width * root2, (float) -height * root2),
|
||||
new PointF((float) width * root2, (float) height * root2),
|
||||
new PointF((float) -width * root2, (float) height * root2)
|
||||
};
|
||||
|
||||
this.points = new List<Point>();
|
||||
foreach (PointF pointF in points) this.points.Add(new Point((int)Math.Round(pointF.X), (int)Math.Round(pointF.Y)));
|
||||
|
||||
correctForOrigin = false;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description from the rectangle
|
||||
/// </summary>
|
||||
/// <returns>Describes the rectangle</returns>
|
||||
public string GetDescription() {
|
||||
return "";
|
||||
return "Draws a rectangle with the width of" + width + " and the height of " + height + " with the pen in the center";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the rectangle
|
||||
/// </summary>
|
||||
public void ExecuteVerb() => drawer.DrawLines(points.ToArray());
|
||||
public void ExecuteVerb() {
|
||||
//adjust for current pen position
|
||||
Point position = drawer.GetPenPosition();
|
||||
|
||||
List<Point> morePoints = new List<Point>();
|
||||
|
||||
foreach (PointF point in points) {
|
||||
morePoints.Add(new Point((int)(point.X + position.X), (int)(point.Y + position.Y)));
|
||||
}
|
||||
|
||||
drawer.DrawLines(morePoints.ToArray());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Windows.Forms;
|
||||
@@ -41,7 +40,7 @@ namespace Advanced_Software_Engineering {
|
||||
Value.ConvertToInt(parameters[0]),
|
||||
Value.ConvertToInt(parameters[1]));
|
||||
|
||||
} else throw new Exception("Command has an incorrect number of parameters");
|
||||
} else throw new Exception(command + " has an incorrect number of parameters");
|
||||
|
||||
case "drawto":
|
||||
case "line":
|
||||
@@ -95,7 +94,7 @@ namespace Advanced_Software_Engineering {
|
||||
case "rectangle":
|
||||
//Check parameters
|
||||
if (parameters.Length == 2) {
|
||||
return new Advanced_Software_Engineering.Verbs.DrawingVerbs.Rectangle(drawer,
|
||||
return new Rectangle(drawer,
|
||||
Value.ConvertToDouble(parameters[0]),
|
||||
Value.ConvertToDouble(parameters[1])
|
||||
);
|
||||
@@ -106,11 +105,6 @@ namespace Advanced_Software_Engineering {
|
||||
Value.ConvertToPoint(parameters[4], parameters[5]),
|
||||
Value.ConvertToPoint(parameters[6], parameters[7])
|
||||
);
|
||||
} else if (parameters.Length == 4) {
|
||||
return new Advanced_Software_Engineering.Verbs.DrawingVerbs.Rectangle(drawer,
|
||||
Value.ConvertToPoint(parameters[0], parameters[1]),
|
||||
Value.ConvertToPoint(parameters[2], parameters[3])
|
||||
);
|
||||
} else throw new Exception("Command has an incorrect number of parameters");
|
||||
case "circle":
|
||||
//Check parameters
|
||||
|
||||
Reference in new issue
Block a user