From 84081e5c1a84072560a90256fb8b0686ce071bbb Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 21 Dec 2020 01:55:08 +0000 Subject: [PATCH] Added: circle class --- 2020/12/Circle.cs | 148 +++++++++++++++++++++++++++++++++++++++++++++ 2020/12/circle.dia | Bin 0 -> 2958 bytes 2 files changed, 148 insertions(+) create mode 100644 2020/12/Circle.cs create mode 100644 2020/12/circle.dia diff --git a/2020/12/Circle.cs b/2020/12/Circle.cs new file mode 100644 index 0000000..a57c357 --- /dev/null +++ b/2020/12/Circle.cs @@ -0,0 +1,148 @@ +using System; +using System.Drawing; + +namespace System.Drawing +{ + public class Circle + { + + public Circle() + { + + } + + public Circle(int x, int y, int width, int height) + { + this.X = x; + this.Y = y; + this.Width = width; + this.Height = height; + } + + public Circle(Rectangle rectangle) + { + this.X = rectangle.X; + this.Y = rectangle.Y; + this.Width = rectangle.Width; + this.Height = rectangle.Height; + } + + public Circle(Point position, Size size) + { + this.X = position.X; + this.Y = position.Y; + this.Width = size.Width; + this.Height = size.Height; + } + + public Circle(Size size) + { + this.X = 0; + this.Y = 0; + this.Width = size.Width; + this.Height = size.Height; + } + + + public int X { get; set; } = 0; + + public int Y { get; set; } = 0; + + public int Width { get; set; } = 0; + + public int Height { get; set; } = 0; + + public PointF Origin + { + get + { + return new PointF() + { + X = (this.Width / 2) + this.X, + Y = (this.Height / 2) + this.Y + }; + } + } + + public int MinSideLength => Math.Min(this.Width, this.Height); + + public static PointF GetPointromOrigin(PointF originPosition, Size size) + { + float offsetX = (size.Width / 2); + float offsetY = (size.Height / 2); + + PointF rs = new PointF() + { + X = originPosition.X, + Y = originPosition.Y + }; + + rs.X -= offsetX; + rs.Y -= offsetY; + + return rs; + } + + public PointF GetPoint(int deg, int distance) + { + PointF origin = this.Origin; + PointF rs = new PointF() + { + X = origin.X, + Y = origin.Y + }; + + if (deg == 0) + { + rs.Y -= distance; + } + else if (deg == 90) + { + rs.X += distance; + } + else if (deg == 180) + { + rs.Y += distance; + } + else if (deg == 270) + { + rs.X -= distance; + } + else if ((deg > 0) && (deg < 90)) + { + rs.X += (float)(distance * Math.Sin(calcToRad(deg))); + rs.Y -= (float)(distance * Math.Cos(calcToRad(deg))); + } + else if ((deg > 90) && (deg < 180)) + { + rs.X += (float)(distance * Math.Cos(calcToRad(deg - 90))); + rs.Y += (float)(distance * Math.Sin(calcToRad(deg - 90))); + } + else if ((deg > 180) && (deg < 270)) + { + rs.X -= (float)(distance * Math.Sin(calcToRad(deg - 180))); + rs.Y += (float)(distance * Math.Cos(calcToRad(deg - 180))); + } + else if ((deg > 270) && (deg < 360)) + { + rs.X -= (float)(distance * Math.Cos(calcToRad(deg - 270))); + rs.Y -= (float)(distance * Math.Sin(calcToRad(deg - 270))); + } + + // adjust position + rs.X += this.X; + rs.Y += this.Y; + + return rs; + } + + public void Deflate(int x, int y) + { + this.Width -= x; + this.Height -= y; + } + + protected double calcToRad(int deg) => ((Math.PI / 180) * deg); + + } +} diff --git a/2020/12/circle.dia b/2020/12/circle.dia new file mode 100644 index 0000000000000000000000000000000000000000..f94018de9a19cc8e3a4d69c8236887b3abf63281 GIT binary patch literal 2958 zcmV;93vu)xiwFP!000023+-LYa^p4@-S=0p)Ej3?4dYE9iaXUaHK|^tsuxKrGbfN{k}VQU(+yR%ZK)w#0zCJ109^j?QZK}~-A`0j^g6nqc=R%vkM!8ekvd3QFs%(Bh*r>D2KwK3`{I(y51#sJy3kf3*;SCPqNFYd<|ZyCf+9sJ zg~RU;EDfTpE^@wJ$6=5ZQnU0rJYLRr5ySwo zeZ%T7ii;@A)(5WtB8ayy89?#zqqeF~MQ6-Mgb*VWF-g>Mf*0!~IS-R%K9<*xu-=OKM^8a=eYMzBFQ7?j zU(+eLmGFF5&l&@dQ6_K0$ zE)t3l3&lHL6G>N1q;&d0SX4qva_s{l2#Xn|x$aHjx6wt*I#?N7V}oPC=G5=)tKU!Y z`gU;{q#5YnKjS#sY@1Y&c2z+_r#9UnAxMkq2W<3@QTREf=I66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