first unit test
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
@@ -10,33 +9,17 @@ namespace Shapes
|
||||
[DataContract]
|
||||
public class Rectangle : GeometricShape
|
||||
{
|
||||
[DataMember]
|
||||
public override List<Point> Points { get; internal set; }
|
||||
[DataMember]
|
||||
public override Color Fill { get; set; }
|
||||
[DataMember]
|
||||
public override Color Stroke { get; set; }
|
||||
[DataMember]
|
||||
public List<Line> Lines { get; }
|
||||
[DataMember]
|
||||
public override Point CenterPoint { get; protected set; }
|
||||
[DataMember]
|
||||
public sealed override double Width { get; internal set; }
|
||||
[DataMember]
|
||||
public sealed override double Height { get; internal set; }
|
||||
|
||||
|
||||
public Rectangle(Point point1, Point point2, Point point3, Point point4)
|
||||
{
|
||||
Stroke = Color.Black;
|
||||
Points = new List<Point>();
|
||||
Lines = new List<Line>();
|
||||
|
||||
|
||||
Points.Add(point1);
|
||||
Points.Add(point2);
|
||||
Points.Add(point3);
|
||||
Points.Add(point4);
|
||||
|
||||
|
||||
Lines.Add(new Line(point1, point2));
|
||||
Lines.Add(new Line(point2, point3));
|
||||
Lines.Add(new Line(point3, point4));
|
||||
@@ -45,8 +28,8 @@ namespace Shapes
|
||||
|
||||
Height = new Line(point1, point4).ComputeLength();
|
||||
Width = new Line(point1, point2).ComputeLength();
|
||||
CenterPoint = new Point(point1.X + (Width/2), point1.Y + (Height/2));
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
CenterPoint = new Point(point1.X + Width / 2, point1.Y + Height / 2);
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {GetType()}");
|
||||
}
|
||||
|
||||
public Rectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
|
||||
@@ -64,9 +47,10 @@ namespace Shapes
|
||||
Height = new Line(point1, point2).ComputeLength();
|
||||
Width = new Line(point1, point4).ComputeLength();
|
||||
ComputeCenter();
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {GetType()}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rectangle(Point point, Size size)
|
||||
{
|
||||
Stroke = Color.Black;
|
||||
@@ -82,9 +66,23 @@ namespace Shapes
|
||||
Height = new Line(point1, point2).ComputeLength();
|
||||
Width = new Line(point1, point4).ComputeLength();
|
||||
ComputeCenter();
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {GetType()}");
|
||||
}
|
||||
|
||||
|
||||
[DataMember] public override List<Point> Points { get; internal set; }
|
||||
|
||||
[DataMember] public override Color Fill { get; set; }
|
||||
|
||||
[DataMember] public override Color Stroke { get; set; }
|
||||
|
||||
[DataMember] public List<Line> Lines { get; }
|
||||
|
||||
[DataMember] public override Point CenterPoint { get; protected set; }
|
||||
|
||||
[DataMember] public sealed override double Width { get; internal set; }
|
||||
|
||||
[DataMember] public sealed override double Height { get; internal set; }
|
||||
|
||||
public override double ComputeArea()
|
||||
{
|
||||
return Height * Width;
|
||||
@@ -97,6 +95,7 @@ namespace Shapes
|
||||
point.X *= scaleFactor;
|
||||
point.Y *= scaleFactor;
|
||||
}
|
||||
|
||||
foreach (var line in Lines)
|
||||
{
|
||||
line.Point1.X *= scaleFactor;
|
||||
@@ -114,14 +113,14 @@ namespace Shapes
|
||||
|
||||
public override void Draw(Stream stream)
|
||||
{
|
||||
var tmp = new Bitmap(1000, 1000);
|
||||
Pen blackPen = new Pen(Stroke, 3);
|
||||
var tmp = new Bitmap((int) Width * 2, (int) Height * 2);
|
||||
var blackPen = new Pen(Stroke, 3);
|
||||
// Draw line to screen.
|
||||
using (var graphics = Graphics.FromImage(tmp))
|
||||
{
|
||||
for (int i = 1; i < Points.Count; i++)
|
||||
graphics.DrawLine(blackPen,
|
||||
(float) Points[i - 1].X,
|
||||
for (var i = 1; i < Points.Count; i++)
|
||||
graphics.DrawLine(blackPen,
|
||||
(float) Points[i - 1].X,
|
||||
(float) Points[i - 1].Y,
|
||||
(float) Points[i].X,
|
||||
(float) Points[i].Y);
|
||||
@@ -133,7 +132,6 @@ namespace Shapes
|
||||
public double CalculateWidth()
|
||||
{
|
||||
return new Line(Points[0], Points[3]).ComputeLength();
|
||||
|
||||
}
|
||||
|
||||
public double CalculateHeight()
|
||||
@@ -143,10 +141,7 @@ namespace Shapes
|
||||
|
||||
internal override void ComputeCenter()
|
||||
{
|
||||
CenterPoint = new Point((Points[0].X + Width)/2, (Points[0].Y + Height)/2);
|
||||
CenterPoint = new Point((Points[0].X + Width) / 2, (Points[0].Y + Height) / 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user