using System; using System.Drawing; namespace ClassLibrary { public class RectDouble { double _x; double _y; double _width; double _height; public double X { get { return _x; } set { _x = value; } } public double Y { get { return _y; } set { _y = value; } } public double Width { get { return _width; } set { _width = value; } } public double Height { get { return _height; } set { _height = value; } } RectDouble() { } public RectDouble(double X, double Y, double Width, double Height) { _x = X; _y = Y; _width = Width; _height = Height; } //public RectDouble(double X0, double Y0, double X1, double Y1) //{ // _x = X0; // _y = Y0; // _width = X1 - X0; // _height = Y1 - Y0; //} Rectangle ConvertToInt(int coeff) { return new Rectangle(Convert.ToInt32(_x * coeff), Convert.ToInt32(_y * coeff), Convert.ToInt32(_width * coeff), Convert.ToInt32(_height * coeff)); } RectangleF ConvertToFloat(int coeff) { return new RectangleF(Convert.ToSingle(_x * coeff), Convert.ToSingle(_y * coeff), Convert.ToSingle(_width * coeff), Convert.ToSingle(_height * coeff)); } Rectangle ConvertToInt(RectDouble rect, int coeff) { return new Rectangle(Convert.ToInt32(rect.X * coeff), Convert.ToInt32(rect.Y * coeff), Convert.ToInt32(rect.Width * coeff), Convert.ToInt32(rect.Height * coeff)); } RectangleF ConvertToFloat(RectDouble rect, int coeff) { return new RectangleF(Convert.ToSingle(rect.X * coeff), Convert.ToSingle(rect.Y * coeff), Convert.ToSingle(rect.Width * coeff), Convert.ToSingle(rect.Height * coeff)); } void ShiftLeft(RectangleF rect, int shift) { rect.X -= shift; } public void DrawArc(Graphics g, Pen pen, int coeff, float startAngle, float sweepAngle) { //coeff = 600; //coeff = 5000; // !!! RectangleF rect = ConvertToFloat(coeff); if (rect.Width != 0 && rect.Height != 0) { //rect.X -= 6000; g.DrawArc(pen, rect, startAngle, sweepAngle); } } //public void DrawArc(Graphics g, Pen pen1, Pen pen2, int parallaxAng, int coeff, float startAngle, float sweepAngle) //{ // //coeff = 600; // //coeff = 5000; // !!! // RectangleF rect = ConvertToFloat(coeff); // if (rect.Width != 0 && rect.Height != 0) // { // //rect.X -= 6000; // g.DrawArc(pen1, rect, startAngle, sweepAngle); // g.DrawArc(pen2, rect, startAngle + parallaxAng, sweepAngle); // } //} public void DrawGradationArc(Graphics g, int coeff, float startAngle, float sweepAngle, int[] profileColor) { //coeff = 600; //coeff = 5000; // !!! RectangleF rectF = ConvertToFloat(coeff); if (rectF.Width != 0 && rectF.Height != 0) { float xC = rectF.X + rectF.Width / 2; float yC = rectF.Y + rectF.Height / 2; GradationCurve.DrawGradationArc(xC, yC, rectF.Width, rectF.Height, startAngle, sweepAngle, g, profileColor); } } public void DrawGradationArc(Graphics g, float startAngle, float sweepAngle, int[] profileColor) { //coeff = 600; //coeff = 5000; 1 int coeff = 50;// !!! RectangleF rectF = ConvertToFloat(coeff); if (rectF.Width != 0 && rectF.Height != 0) { float xC = rectF.X + rectF.Width / 2; float yC = rectF.Y + rectF.Height / 2; GradationCurve.DrawGradationArc(xC, yC, rectF.Width, rectF.Height, startAngle, sweepAngle, g, profileColor); } } public void DrawArcFromZeroCoord(Graphics g, Pen pen, int coeff, float startAngle, float sweepAngle) { //coeff = 600; coeff = 20; // !!! RectangleF rect = ConvertToFloat(coeff); Rectangle rectInt = ConvertToInt(coeff); rect.X = 0; // For debug only !!! Shift image to rhe center of bitmap rect.Y = 0; //rectInt.X = 100; //rectInt.Y = 60; //RectangleF rect = new RectangleF(20, 20, 40, 40); if (rect.Width != 0 && rect.Height != 0) { //rect.X -= 6000; //g.DrawRectangle(pen, rectInt); g.DrawArc(pen, rect, startAngle, sweepAngle); } } private RectDouble ShiftArcRect(RectDouble frameRect) { return new RectDouble(X - frameRect.X, Y - frameRect.Y, _width, _height); } public void DrawArcInFrame(RectDouble frameRect, RectDouble rectCircumf, Graphics g, Pen pen, int coeff, float startAngle, float sweepAngle) { //RectDouble arcRect = ShiftArcRect(frameRect); //RectDouble arcRectCircumf = rectCircumf.ShiftArcRect(frameRect); //RectangleF rectF = ConvertToFloat(arcRect, coeff); RectangleF rectF = ConvertToFloat(frameRect, coeff); //Rectangle rectIRect = ConvertToInt(frameRect, coeff); //Rectangle rectICircumf = ConvertToInt(arcRectCircumf, coeff); //rectIRect.X = 0; //rectIRect.Y = 0; //Rectangle rectInt = ConvertToInt(arcRect, coeff); if (rectF.Width != 0 && rectF.Height != 0) { g.DrawArc(pen, rectF, startAngle, sweepAngle); //g.DrawRectangle(pen, rectInt); //g.DrawRectangle(pen, rectIRect); //g.DrawRectangle(pen, rectICircumf); } } public void DrawGradationArcInFrame(RectDouble frameRect, RectDouble rectCircumf, Graphics g, int coeff, float startAngle, float sweepAngle, int[] profileColor) { RectDouble arcRect = ShiftArcRect(frameRect); RectangleF rectF = ConvertToFloat(arcRect, coeff); if (rectF.Width != 0 && rectF.Height != 0) { float xC = rectF.X + rectF.Width / 2; float yC = rectF.Y + rectF.Height / 2; GradationCurve.DrawGradationArc(xC, yC, rectF.Width, rectF.Height, startAngle, sweepAngle, g, profileColor); } } public void DrawRectangleFromZeroCoord(Graphics g, Pen pen, int coeff) { //coeff = 600; //coeff = 50; // !!! RectangleF rect = ConvertToFloat(coeff); Rectangle rectInt = ConvertToInt(coeff); //rect.X = 50; // For debug only !!! Shift image to rhe center of bitmap //rect.Y = 70; //rectInt.X = 50; //rectInt.Y = 70; //RectangleF rect = new RectangleF(20, 20, 40, 40); if (rect.Width != 0 && rect.Height != 0) { //rect.X -= 6000; //g.DrawRectangle(pen, rectInt); g.DrawRectangle(pen, rectInt); } } // Returns true if two rectangles (l1, r1) and (l2, r2) overlap bool doOverlap(Point l1, Point r1, Point l2, Point r2) { // If one rectangle is on left side of other if (l1.X > r2.X || l2.X > r1.X) return false; // If one rectangle is above other if (l1.Y < r2.Y || l2.Y < r1.Y) return false; return true; } public bool IntersectWith(RectDouble rect) { // If one rectangle is on left side of other if (this.X > rect.X + rect.Width || this.X + this.Width < rect.X) return false; // If one rectangle is above other if (this.Y > rect.Y + rect.Height || this.Y + this.Height < rect.Y) return false; return true; } } }