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.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms.VisualStyles;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -16,71 +17,58 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
|||||||
Verb verb;
|
Verb verb;
|
||||||
|
|
||||||
Drawer drawer;
|
Drawer drawer;
|
||||||
List<Point> points;
|
PointF[] points;
|
||||||
bool correctForOrigin;
|
|
||||||
|
double width;
|
||||||
|
double height;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a rectangle instance
|
/// Create a rectangle instance. Makes sure that
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="drawer">drawer</param>
|
/// <param name="drawer">drawer</param>
|
||||||
/// <param name="width">rectangle width</param>
|
/// <param name="width">rectangle width</param>
|
||||||
/// <param name="height">rectangle height</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) {
|
||||||
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) {
|
|
||||||
this.drawer = drawer;
|
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) -width * root2, (float) -height * root2),
|
||||||
new PointF((float) point1.X, (float) point2.Y),
|
new PointF((float) width * root2, (float) -height * root2),
|
||||||
new PointF((float) point2.X, (float) point2.Y),
|
new PointF((float) width * root2, (float) height * root2),
|
||||||
new PointF((float) point2.X, (float) point1.Y)
|
new PointF((float) -width * root2, (float) height * root2)
|
||||||
};
|
};
|
||||||
|
|
||||||
this.points = new List<Point>();
|
this.width = width;
|
||||||
foreach (PointF pointF in points) this.points.Add(new Point((int)Math.Round(pointF.X), (int)Math.Round(pointF.Y)));
|
this.height = height;
|
||||||
|
|
||||||
correctForOrigin = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the description from the rectangle
|
/// Gets the description from the rectangle
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Describes the rectangle</returns>
|
/// <returns>Describes the rectangle</returns>
|
||||||
public string GetDescription() {
|
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>
|
/// <summary>
|
||||||
/// Draws the rectangle
|
/// Draws the rectangle
|
||||||
/// </summary>
|
/// </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;
|
||||||
using System.CodeDom;
|
using System.CodeDom;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@@ -41,7 +40,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
Value.ConvertToInt(parameters[0]),
|
Value.ConvertToInt(parameters[0]),
|
||||||
Value.ConvertToInt(parameters[1]));
|
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 "drawto":
|
||||||
case "line":
|
case "line":
|
||||||
@@ -95,7 +94,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
case "rectangle":
|
case "rectangle":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
if (parameters.Length == 2) {
|
if (parameters.Length == 2) {
|
||||||
return new Advanced_Software_Engineering.Verbs.DrawingVerbs.Rectangle(drawer,
|
return new Rectangle(drawer,
|
||||||
Value.ConvertToDouble(parameters[0]),
|
Value.ConvertToDouble(parameters[0]),
|
||||||
Value.ConvertToDouble(parameters[1])
|
Value.ConvertToDouble(parameters[1])
|
||||||
);
|
);
|
||||||
@@ -106,11 +105,6 @@ namespace Advanced_Software_Engineering {
|
|||||||
Value.ConvertToPoint(parameters[4], parameters[5]),
|
Value.ConvertToPoint(parameters[4], parameters[5]),
|
||||||
Value.ConvertToPoint(parameters[6], parameters[7])
|
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");
|
} else throw new Exception("Command has an incorrect number of parameters");
|
||||||
case "circle":
|
case "circle":
|
||||||
//Check parameters
|
//Check parameters
|
||||||
|
|||||||
Reference in new issue
Block a user