Private
Public Access
Shapes updated to use new IValue interface
This commit is contained in:
1 parent
bd23d9e503
commit
52503b5872
7 files changed
+78
-86
No files matched your search
+10
-16
@@ -1,4 +1,6 @@
|
||||
using System.Drawing;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
|
||||
@@ -7,17 +9,14 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// </summary>
|
||||
public class DrawLines : IVerb {
|
||||
private readonly Drawer drawer;
|
||||
private readonly Point[] points;
|
||||
|
||||
private readonly bool descCreated = false;
|
||||
private string desc;
|
||||
private readonly PointValue[] points;
|
||||
|
||||
/// <summary>
|
||||
/// DrawLines constructor
|
||||
/// </summary>
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="points">All of the points to visit</param>
|
||||
public DrawLines(Drawer drawer, Point[] points) {
|
||||
public DrawLines(Drawer drawer, PointValue[] points) {
|
||||
this.drawer = drawer;
|
||||
this.points = points;
|
||||
}
|
||||
@@ -26,22 +25,17 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// Draws all the lines
|
||||
/// </summary>
|
||||
public void ExecuteVerb() {
|
||||
drawer.DrawLines(points);
|
||||
List<Point> pointList = new List<Point>();
|
||||
foreach (PointValue pointValue in points) pointList.Add(pointValue.GetPoint());
|
||||
drawer.DrawLines(pointList.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets description of the command.
|
||||
/// </summary>
|
||||
/// <returns>What points will be drawn to in what order</returns>
|
||||
/// <returns>A generic description of the command</returns>
|
||||
public string GetDescription() {
|
||||
if (!descCreated) {
|
||||
desc = "Draws a shape at points: ";
|
||||
|
||||
foreach (Point point in points) {
|
||||
desc += point.X + ", " + point.Y + "\n";
|
||||
}
|
||||
}
|
||||
return desc;
|
||||
return "Draws a shape at specific points.";
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -14,8 +14,7 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// Creates a MoveTo instance
|
||||
/// </summary>
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="x">X position</param>
|
||||
/// <param name="y">Y position</param>
|
||||
/// <param name="point">Position to move to</param>
|
||||
public MoveTo(Drawer drawer, PointValue point) {
|
||||
this.drawer = drawer;
|
||||
moveToPoint = point;
|
||||
|
||||
+5
-3
@@ -1,4 +1,6 @@
|
||||
using System.Drawing;
|
||||
using Advanced_Software_Engineering.Verbs.Value;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
|
||||
@@ -16,8 +18,8 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// <param name="point2">second point</param>
|
||||
/// <param name="point3">third point</param>
|
||||
/// <param name="point4">fourth point</param>
|
||||
public Quadrilateral(Drawer drawer, Point point1, Point point2, Point point3, Point point4) {
|
||||
IVerb = new DrawLines(drawer, new Point[] { point1, point2, point3, point4 });
|
||||
public Quadrilateral(Drawer drawer, PointValue point1, PointValue point2, PointValue point3, PointValue point4) {
|
||||
IVerb = new DrawLines(drawer, new PointValue[] { point1, point2, point3, point4 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+16
-27
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Advanced_Software_Engineering.Verbs.Value;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
@@ -11,11 +13,9 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// Correct
|
||||
/// </todo>
|
||||
public class Rectangle : IVerb {
|
||||
private readonly Drawer drawer;
|
||||
private readonly PointF[] points;
|
||||
private readonly PointValue[] points;
|
||||
|
||||
private readonly double width;
|
||||
private readonly double height;
|
||||
private readonly IVerb verb;
|
||||
|
||||
/// <summary>
|
||||
/// Create a rectangle instance. Makes sure that
|
||||
@@ -23,21 +23,19 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="width">rectangle width</param>
|
||||
/// <param name="height">rectangle height</param>
|
||||
public Rectangle(Drawer drawer, double width, double height) {
|
||||
this.drawer = drawer;
|
||||
public Rectangle(Drawer drawer, IValue width, IValue height) {
|
||||
IValue negativeWidth = new ExpressionValue(drawer, new IntValue(0), width, ExpressionValue.SUBTRACT);
|
||||
IValue negativeHeight = new ExpressionValue(drawer, new IntValue(0), height, ExpressionValue.SUBTRACT);
|
||||
|
||||
float root2 = (float)Math.Sqrt(2) / 2;
|
||||
|
||||
points = new PointF[]
|
||||
points = new PointValue[]
|
||||
{
|
||||
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)
|
||||
new PointValue(negativeWidth, negativeHeight),
|
||||
new PointValue(width, negativeHeight),
|
||||
new PointValue(width, height),
|
||||
new PointValue(negativeWidth, negativeHeight)
|
||||
};
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
verb = new DrawLines(drawer, points);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,23 +43,14 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// </summary>
|
||||
/// <returns>Describes the rectangle</returns>
|
||||
public string GetDescription() {
|
||||
return "Draws a rectangle with the width of" + width + " and the height of " + height + " with the pen in the center";
|
||||
return "Draws a rectangle with the pen in the center";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the rectangle
|
||||
/// </summary>
|
||||
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());
|
||||
verb.ExecuteVerb();
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
-26
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using Advanced_Software_Engineering.Verbs.Value;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
@@ -9,10 +12,10 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// </summary>
|
||||
public class RegularPolygon : IVerb {
|
||||
private readonly Drawer drawer;
|
||||
private readonly int sides;
|
||||
private readonly double scale;
|
||||
private readonly double offset;
|
||||
private readonly List<Point> points;
|
||||
private readonly IValue sides;
|
||||
private readonly IValue scale;
|
||||
private readonly IValue offset;
|
||||
private readonly IValue degMode;
|
||||
|
||||
/// <summary>
|
||||
/// Draws a regular polygon.
|
||||
@@ -24,36 +27,35 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// <param name="scale">The scale of the regular polygon</param>
|
||||
/// <param name="offset">Rotation offset of the regular polygon</param>
|
||||
/// <param name="degMode">Default is true. If true, offset is in degrees. If false, offset is in gradians.</param>
|
||||
public RegularPolygon(Drawer drawer, int sides, double scale, double offset = 0, bool degMode = true) {
|
||||
points = new List<Point>();
|
||||
|
||||
//if in degMode, convert the offset to radians
|
||||
if (degMode) offset = Math.PI * offset / 180;
|
||||
|
||||
double constantAngleDelta = 2 * Math.PI / sides;
|
||||
for (int side = 0; side < sides; side++) {
|
||||
double angle = (constantAngleDelta * side) + offset;
|
||||
|
||||
double dx = scale * Math.Sin(angle);
|
||||
double dy = scale * Math.Cos(angle);
|
||||
|
||||
points.Add(new Point((int)Math.Round(dx), (int)Math.Round(dy)));
|
||||
}
|
||||
|
||||
public RegularPolygon(Drawer drawer, IValue sides, IValue scale, IValue offset, IValue degMode) {
|
||||
this.sides = sides;
|
||||
this.scale = scale;
|
||||
this.drawer = drawer;
|
||||
this.offset = offset;
|
||||
this.degMode = degMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the regular polygons
|
||||
/// </summary>
|
||||
public void ExecuteVerb() {
|
||||
Point currentOrigin = drawer.GetPenPosition();
|
||||
List<Point> originShiftedPoints = new List<Point>();
|
||||
foreach (Point point in points) originShiftedPoints.Add(new Point(point.X + currentOrigin.X, point.Y + currentOrigin.Y));
|
||||
drawer.DrawLines(originShiftedPoints.ToArray());
|
||||
double offset = this.offset.ToDouble();
|
||||
//if in degMode, convert the offset to radian
|
||||
if (degMode.ToBool()) offset = Math.PI * offset / 180;
|
||||
|
||||
//Scale needs to be corercted to work correctly with Rectangle
|
||||
double scale = this.scale.ToInt() * 2 / Math.Sqrt(2);
|
||||
List<PointValue> points = new List<PointValue>();
|
||||
double constantAngleDelta = 2 * Math.PI / sides.ToInt();
|
||||
for (int side = 0; side < sides.ToInt(); side++) {
|
||||
double angle = (constantAngleDelta * side) + offset;
|
||||
|
||||
double dx = scale * Math.Sin(angle);
|
||||
double dy = scale * Math.Cos(angle);
|
||||
|
||||
points.Add(new PointValue(new IntValue((int)Math.Round(dx)), new IntValue((int)Math.Round(dy))));
|
||||
}
|
||||
new DrawLines(drawer, points.ToArray()).ExecuteVerb();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,7 +63,7 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// </summary>
|
||||
/// <returns>A description of how the polygon will be drawn</returns>
|
||||
public string GetDescription() {
|
||||
return "Draws a " + sides + " sided regular polygon, with rotation of " + offset + " radians, with inner radius of " + scale;
|
||||
return "Draws a regular polygon.";
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -1,4 +1,7 @@
|
||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
using Advanced_Software_Engineering.Verbs.Value;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
|
||||
/// <summary>
|
||||
/// The Square IVerb class
|
||||
@@ -11,8 +14,8 @@
|
||||
/// </summary>
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="scale">size of the square</param>
|
||||
public Square(Drawer drawer, double scale) {
|
||||
IVerb = new RegularPolygon(drawer, 4, scale);
|
||||
public Square(Drawer drawer, IValue scale) {
|
||||
IVerb = new RegularPolygon(drawer, new IntValue(4), scale, new IntValue(0), new BoolValue(true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -21,8 +24,8 @@
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="scale">size of the square</param>
|
||||
/// <param name="offset">rotation offset in degrees</param>
|
||||
public Square(Drawer drawer, double scale, double offset) {
|
||||
IVerb = new RegularPolygon(drawer, 4, scale, offset);
|
||||
public Square(Drawer drawer, IValue scale, IValue offset) {
|
||||
IVerb = new RegularPolygon(drawer, new IntValue(4), scale, offset, new BoolValue(true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+10
-7
@@ -1,4 +1,7 @@
|
||||
using System.Drawing;
|
||||
using Advanced_Software_Engineering.Verbs.Value;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueObjects;
|
||||
using Advanced_Software_Engineering.Verbs.Value.ValueTypes;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
|
||||
@@ -13,8 +16,8 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// </summary>
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="scale">the scale of the triangle</param>
|
||||
public Triangle(Drawer drawer, double scale) {
|
||||
IVerb = new RegularPolygon(drawer, 3, scale);
|
||||
public Triangle(Drawer drawer, IValue scale) {
|
||||
IVerb = new RegularPolygon(drawer, new IntValue(3), scale, new IntValue(0), new BoolValue(true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -23,8 +26,8 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// <param name="drawer">drawer</param>
|
||||
/// <param name="scale">the scale of the triangle</param>
|
||||
/// <param name="offset">the offset of the triangle in degrees</param>
|
||||
public Triangle(Drawer drawer, double scale, double offset) {
|
||||
IVerb = new RegularPolygon(drawer, 3, scale, offset);
|
||||
public Triangle(Drawer drawer, IValue scale, IValue offset) {
|
||||
IVerb = new RegularPolygon(drawer, new IntValue(3), scale, offset, new BoolValue(true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -34,8 +37,8 @@ namespace Advanced_Software_Engineering.Verbs.DrawingVerbs {
|
||||
/// <param name="point1">first point</param>
|
||||
/// <param name="point2">second point</param>
|
||||
/// <param name="point3">third point</param>
|
||||
public Triangle(Drawer drawer, Point point1, Point point2, Point point3) {
|
||||
IVerb = new DrawLines(drawer, new Point[] { point1, point2, point3 });
|
||||
public Triangle(Drawer drawer, PointValue point1, PointValue point2, PointValue point3) {
|
||||
IVerb = new DrawLines(drawer, new PointValue[] { point1, point2, point3 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user