Added Check in Validator for rectangle having the same points.
This commit is contained in:
@@ -24,7 +24,7 @@ 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(point1, point2, point3, point4, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
}
|
||||
|
||||
public Rectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
|
||||
@@ -41,7 +41,7 @@ namespace Shapes
|
||||
Height = new Line(point1, point2).ComputeLength();
|
||||
Width = new Line(point1, point4).ComputeLength();
|
||||
CenterPoint = new Point((point1.X + Width)/2, (point1.Y + Height)/2);
|
||||
Validator.ValidateRectangle(point1, point2, point3, point4, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
}
|
||||
|
||||
public Rectangle(Point point, Size size)
|
||||
@@ -58,7 +58,7 @@ namespace Shapes
|
||||
Height = new Line(point1, point2).ComputeLength();
|
||||
Width = new Line(point1, point4).ComputeLength();
|
||||
CenterPoint = new Point((point1.X + Width)/2, (point1.Y + Height)/2);
|
||||
Validator.ValidateRectangle(point1, point2, point3, point4, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
Validator.ValidateRectangle(Points, $"Attempted to create an invalid shape {this.GetType()}");
|
||||
}
|
||||
|
||||
public override double ComputeArea()
|
||||
|
||||
@@ -4,7 +4,31 @@ using System.Drawing;
|
||||
|
||||
namespace Shapes
|
||||
{
|
||||
public class Triangle
|
||||
public class Triangle : Shape
|
||||
{
|
||||
public override Color Fill { get; set; }
|
||||
public override Color Color { get; set; }
|
||||
public override double Width { get; }
|
||||
public override double Height { get; }
|
||||
|
||||
public Triangle(Point point1, Point point2, Point point3)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Triangle(double x1, double y1, double x2, double y2, double x3, double y3)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override double ComputeArea()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Scale(double scaleFactor)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,21 +20,33 @@ namespace Shapes
|
||||
throw new ShapeException(errorMessage);
|
||||
}
|
||||
|
||||
public static void ValidateRectangle(Point point1, Point point2, Point point3, Point point4, String errorMessage)
|
||||
{
|
||||
public static void ValidateRectangle(List<Point> points, String errorMessage)
|
||||
{
|
||||
List<Point> pointList = new List<Point>(points);
|
||||
|
||||
var TOLERANCE = Double.Epsilon + Double.Epsilon;
|
||||
var plumLine1 = new Line(point1, point3);
|
||||
var plumLine2 = new Line(point2, point4);
|
||||
var heightLine1 = new Line(point1, point4);
|
||||
var heightLine2 = new Line( point2, point3);
|
||||
var lengthLine1 = new Line(point1, point2);
|
||||
var lengthLine2 = new Line(point4, point3);
|
||||
var plumLine1 = new Line(points[0], points[2]);
|
||||
var plumLine2 = new Line(points[1], points[3]);
|
||||
var heightLine1 = new Line(points[0], points[3]);
|
||||
var heightLine2 = new Line( points[1], points[2]);
|
||||
var lengthLine1 = new Line(points[0], points[1]);
|
||||
var lengthLine2 = new Line(points[3], points[2]);
|
||||
if (Math.Abs(plumLine1.ComputeLength() - plumLine2.ComputeLength()) > TOLERANCE
|
||||
|| Math.Abs(heightLine1.ComputeLength() - heightLine2.ComputeLength()) > TOLERANCE
|
||||
|| Math.Abs(lengthLine1.ComputeLength() - lengthLine2.ComputeLength()) > TOLERANCE )
|
||||
{
|
||||
throw new ShapeException(errorMessage);
|
||||
}
|
||||
|
||||
while(pointList.Count > 0)
|
||||
{
|
||||
var tmp = pointList[0];
|
||||
pointList.Remove(tmp);
|
||||
if (pointList.Contains(tmp))
|
||||
{
|
||||
throw new ShapeException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ namespace Temp
|
||||
var tmp = line.ComputeLength();
|
||||
var point = new Point(3, 3);
|
||||
point.Color = Color.Aqua;
|
||||
var rectangle = new Rectangle(new Point(3,3), new Point(6,3), new Point(6,6), new Point(3,6));
|
||||
var rectangle = new Rectangle(new Point(3,3), new Point(7,3), new Point(7,6), new Point(3,6));
|
||||
//var rectangle2 = new Rectangle(new Point(3,0), new Point(3,0), new Point(3,2), new Point(0,3));
|
||||
Console.WriteLine($"({rectangle.Points[0].X}, {rectangle.Points[0].Y}), ({rectangle.Points[1].X}, {rectangle.Points[1].Y}), ({rectangle.Points[2].X}, {rectangle.Points[2].Y}), ({rectangle.Points[3].X}, {rectangle.Points[3].Y}) Height:{rectangle.CalculateHeight()} Width:{rectangle.CalculateWidth()} Center: {rectangle.CenterPoint.X}, {rectangle.CenterPoint.Y}");
|
||||
rectangle.Rotate(180);
|
||||
Console.WriteLine($"({rectangle.Points[0].X}, {rectangle.Points[0].Y}), ({rectangle.Points[1].X}, {rectangle.Points[1].Y}), ({rectangle.Points[2].X}, {rectangle.Points[2].Y}), ({rectangle.Points[3].X}, {rectangle.Points[3].Y}) Height:{rectangle.CalculateHeight()} Width:{rectangle.CalculateWidth()} Center: {rectangle.CenterPoint.X}, {rectangle.CenterPoint.Y}");
|
||||
rectangle.Rotate(90);
|
||||
rectangle.Rotate(180);
|
||||
Console.WriteLine($"({rectangle.Points[0].X}, {rectangle.Points[0].Y}), ({rectangle.Points[1].X}, {rectangle.Points[1].Y}), ({rectangle.Points[2].X}, {rectangle.Points[2].Y}), ({rectangle.Points[3].X}, {rectangle.Points[3].Y}) Height:{rectangle.CalculateHeight()} Width:{rectangle.CalculateWidth()} Center: {rectangle.CenterPoint.X}, {rectangle.CenterPoint.Y}");
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user