more stuff
This commit is contained in:
1
.idea/.idea.Shapes/.idea/.name
generated
Normal file
1
.idea/.idea.Shapes/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
Shapes
|
||||
2
.idea/.idea.Shapes/.idea/contentModel.xml
generated
2
.idea/.idea.Shapes/.idea/contentModel.xml
generated
@@ -5,7 +5,7 @@
|
||||
<e p="$USER_HOME$/.nuget/packages/nunit3testadapter/3.11.0/build/netcoreapp1.0/NUnit3.TestAdapter.dll" t="Include" />
|
||||
<e p="$USER_HOME$/.nuget/packages/nunit3testadapter/3.11.0/build/netcoreapp1.0/NUnit3.TestAdapter.pdb" t="Include" />
|
||||
<e p="$USER_HOME$/Library/Caches/Rider2019.2/extResources" t="IncludeRecursive" />
|
||||
<e p="$USER_HOME$/Library/Caches/Rider2019.2/resharper-host/local/Transient/ReSharperHost/v192/SolutionCaches/_Shapes.-1053000488.00" t="ExcludeRecursive" />
|
||||
<e p="$USER_HOME$/Library/Caches/Rider2019.2/resharper-host/local/Transient/ReSharperHost/v192/SolutionCaches/_Shapes.1185620916.00" t="ExcludeRecursive" />
|
||||
<e p="$PROJECT_DIR$" t="IncludeFlat">
|
||||
<e p="packages" t="ExcludeRecursive" />
|
||||
<e p="Shapes" t="IncludeRecursive">
|
||||
|
||||
@@ -5,11 +5,9 @@ namespace Shapes
|
||||
{
|
||||
public class Circle : Shape
|
||||
{
|
||||
public Point Center { get; private set; }
|
||||
public override Point CenterPoint { get; }
|
||||
public double Radius { get; private set; }
|
||||
|
||||
public override Color Fill { get; set; }
|
||||
public override Color Color { get; set; }
|
||||
|
||||
public override double Height { get; }
|
||||
public override double Width { get; }
|
||||
|
||||
@@ -24,10 +22,8 @@ namespace Shapes
|
||||
public Circle(double x, double y, double radius)
|
||||
{
|
||||
Validator.ValidatePositiveDouble(radius, "Invalid radius");
|
||||
Center = new Point(x, y);
|
||||
CenterPoint = new Point(x, y);
|
||||
Radius = radius;
|
||||
Color = Color.Black;
|
||||
Fill = Color.White;
|
||||
Height = radius * 2;
|
||||
Width = radius * 2;
|
||||
}
|
||||
@@ -44,10 +40,8 @@ namespace Shapes
|
||||
Validator.ValidatePositiveDouble(radius, "Invalid radius");
|
||||
if (center == null)
|
||||
throw new ShapeException("Invalid center point");
|
||||
Center = center;
|
||||
CenterPoint = center;
|
||||
Radius = radius;
|
||||
Color = Color.Black;
|
||||
Fill = Color.White;
|
||||
Height = radius * 2;
|
||||
Width = radius * 2;
|
||||
}
|
||||
@@ -60,7 +54,7 @@ namespace Shapes
|
||||
*/
|
||||
public void Move(double deltaX, double deltaY)
|
||||
{
|
||||
Center.Move(deltaX, deltaY);
|
||||
CenterPoint.Move(deltaX, deltaY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,6 +78,5 @@ namespace Shapes
|
||||
{
|
||||
return Math.PI * Math.Pow(Radius, 2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ namespace Shapes
|
||||
{
|
||||
public Point Point1 { get; private set; }
|
||||
public Point Point2 { get; private set; }
|
||||
public Color Color { get; set; }
|
||||
|
||||
/**
|
||||
* Constructor based on x-y Locations
|
||||
@@ -19,7 +18,6 @@ namespace Shapes
|
||||
*/
|
||||
public Line(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
Color = Color.Black;
|
||||
Point1 = new Point(x1, y1);
|
||||
Point2 = new Point(x2, y2);
|
||||
}
|
||||
@@ -34,7 +32,6 @@ namespace Shapes
|
||||
{
|
||||
if (point1==null || point2==null)
|
||||
throw new ShapeException("Invalid point");
|
||||
Color = Color.Black;
|
||||
Point1 = point1;
|
||||
Point2 = point2;
|
||||
}
|
||||
@@ -68,5 +65,6 @@ namespace Shapes
|
||||
{
|
||||
return (Point2.Y - Point1.Y) / (Point2.X - Point1.X);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -62,5 +62,27 @@ namespace Shapes
|
||||
{
|
||||
return new Point(X, Y);
|
||||
}
|
||||
|
||||
public static Point operator -(Point point1, Point point2)
|
||||
{
|
||||
var x = point1.X - point2.X;
|
||||
var y = point1.Y - point2.Y;
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public static Point operator +(Point point1, Point point2)
|
||||
{
|
||||
var x = point1.X + point2.X;
|
||||
var y = point1.Y + point2.Y;
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public static Point operator /(Point point1, double divisor)
|
||||
{
|
||||
var x = point1.X / divisor;
|
||||
var y = point1.Y / divisor;
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ namespace Shapes
|
||||
{
|
||||
public class Rectangle : Shape
|
||||
{
|
||||
public override Color Fill { get; set; }
|
||||
public override Color Color { get; set; }
|
||||
public List<Point> Points { get; }
|
||||
public Point CenterPoint { get; }
|
||||
public override List<Point> Points { get; }
|
||||
|
||||
public List<Line> Lines { get; }
|
||||
public override Point CenterPoint { get; }
|
||||
public sealed override double Width { get; }
|
||||
public sealed override double Height { get; }
|
||||
|
||||
@@ -17,10 +17,19 @@ namespace Shapes
|
||||
public Rectangle(Point point1, Point point2, Point point3, Point point4)
|
||||
{
|
||||
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));
|
||||
Lines.Add(new Line(point4, point1));
|
||||
|
||||
|
||||
Height = new Line(point1, point4).ComputeLength();
|
||||
Width = new Line(point1, point2).ComputeLength();
|
||||
CenterPoint = new Point(point1.X + (Width/2), point1.Y + (Height/2));
|
||||
@@ -82,27 +91,7 @@ namespace Shapes
|
||||
return new Line(Points[0], Points[1]).ComputeLength();
|
||||
}
|
||||
|
||||
public void Rotate(double degrees)
|
||||
{
|
||||
double radians = degrees * (Math.PI / 180);
|
||||
double cosTheta = Math.Cos(radians);
|
||||
double sinTheta = Math.Sin(radians);
|
||||
foreach (var point in Points)
|
||||
{
|
||||
var oldPoint = point;
|
||||
|
||||
|
||||
var tempX = oldPoint.X - CenterPoint.X;
|
||||
var tempY = oldPoint.Y - CenterPoint.X;
|
||||
|
||||
var rotatedX = tempX*cosTheta - tempY*sinTheta;
|
||||
var rotatedY = tempX*sinTheta + tempY*cosTheta;
|
||||
|
||||
point.X = rotatedX + CenterPoint.X;
|
||||
point.Y = rotatedY + CenterPoint.Y;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,45 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
namespace Shapes
|
||||
{
|
||||
public abstract class Shape
|
||||
{
|
||||
public abstract Color Fill { get; set; }
|
||||
public abstract Color Color { get; set; }
|
||||
|
||||
public abstract double Width { get; }
|
||||
public abstract double Height { get; }
|
||||
public abstract double ComputeArea();
|
||||
|
||||
public abstract Point CenterPoint { get; }
|
||||
|
||||
public virtual List<Point> Points { get; }
|
||||
|
||||
|
||||
public abstract void Scale(double scaleFactor);
|
||||
|
||||
|
||||
public void Rotate(double degrees)
|
||||
{
|
||||
double radians = degrees * (Math.PI / 180);
|
||||
double cosTheta = Math.Cos(radians);
|
||||
double sinTheta = Math.Sin(radians);
|
||||
foreach (var point in Points)
|
||||
{
|
||||
var oldPoint = point;
|
||||
|
||||
|
||||
var tempX = oldPoint.X - CenterPoint.X;
|
||||
var tempY = oldPoint.Y - CenterPoint.X;
|
||||
|
||||
var rotatedX = tempX*cosTheta - tempY*sinTheta;
|
||||
var rotatedY = tempX*sinTheta + tempY*cosTheta;
|
||||
|
||||
point.X = rotatedX + CenterPoint.X;
|
||||
point.Y = rotatedY + CenterPoint.Y;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
namespace Shapes
|
||||
{
|
||||
public class Triangle : Shape
|
||||
{
|
||||
public override Color Fill { get; set; }
|
||||
public override Color Color { get; set; }
|
||||
public override double Width { get; }
|
||||
public sealed override List<Point> Points { get; }
|
||||
|
||||
public override double Height { get; }
|
||||
|
||||
public override double Width { get; }
|
||||
|
||||
public sealed override Point CenterPoint { get; }
|
||||
public List<Line> Lines { get; }
|
||||
|
||||
public Triangle(Point point1, Point point2, Point point3)
|
||||
{
|
||||
Points = new List<Point>();
|
||||
Lines = new List<Line>();
|
||||
|
||||
Points.Add(point1);
|
||||
Points.Add(point2);
|
||||
Points.Add(point3);
|
||||
|
||||
Lines.Add(new Line(point1, point2));
|
||||
Lines.Add(new Line(point2, point3));
|
||||
Lines.Add(new Line(point3, point1));
|
||||
|
||||
Point centerOfLine3 = ((point1 - point3) / 2) + point1;
|
||||
var centerTriangle = ((point1 - centerOfLine3) / 2) + point1;
|
||||
|
||||
|
||||
CenterPoint = centerTriangle;
|
||||
|
||||
Height = new Line(point1, centerOfLine3).ComputeLength();
|
||||
Width = new Line(point1, point2).ComputeLength();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Triangle(double x1, double y1, double x2, double y2, double x3, double y3)
|
||||
{
|
||||
var point1 = new Point(x1, y1);
|
||||
var point2 = new Point(x2, y2);
|
||||
var point3 = new Point(x3, y3);
|
||||
|
||||
|
||||
Points = new List<Point>();
|
||||
Lines = new List<Line>();
|
||||
|
||||
Points.Add(point1);
|
||||
Points.Add(point2);
|
||||
Points.Add(point3);
|
||||
|
||||
Lines.Add(new Line(point1, point2));
|
||||
Lines.Add(new Line(point2, point3));
|
||||
Lines.Add(new Line(point3, point1));
|
||||
|
||||
Point centerOfLine3 = ((point1 - point3) / 2) + point1;
|
||||
var centerTriangle = ((point1 - centerOfLine3) / 2) + point1;
|
||||
|
||||
CenterPoint = centerTriangle;
|
||||
}
|
||||
|
||||
public override double ComputeArea()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
var a = Lines[0].ComputeLength();
|
||||
var b = Lines[1].ComputeLength();
|
||||
var c = Lines[2].ComputeLength();
|
||||
|
||||
var p = (a + b + c) / 2;
|
||||
|
||||
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
|
||||
}
|
||||
|
||||
public override void Scale(double scaleFactor)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (var point in Points)
|
||||
{
|
||||
point.X *= scaleFactor;
|
||||
point.Y *= scaleFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,13 @@ namespace Temp
|
||||
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}");
|
||||
|
||||
|
||||
|
||||
var triangle = new Triangle(new Point(3,3), new Point(7,3), new Point(7,6));
|
||||
Console.WriteLine($"({triangle.Points[0].X}, {triangle.Points[0].Y}) ({triangle.Points[1].X}, {triangle.Points[1].Y}) ({triangle.Points[2].X}, {triangle.Points[2].Y}) Center: ({triangle.CenterPoint.X}, {triangle.CenterPoint.Y}) Area = {triangle.ComputeArea()} Height: {triangle.Height}");
|
||||
triangle.Rotate(30);
|
||||
Console.WriteLine($"({triangle.Points[0].X}, {triangle.Points[0].Y}) ({triangle.Points[1].X}, {triangle.Points[1].Y}) ({triangle.Points[2].X}, {triangle.Points[2].Y}) Center: ({triangle.CenterPoint.X}, {triangle.CenterPoint.Y}) Area = {triangle.ComputeArea()} Height: {triangle.Height}");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user