using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;

namespace 试验版
{
    [Serializable]
    public class element:Object
    {
        public RectangleF rect;
        public RectangleF rect2;
        public RectangleF rect5;
        public String sbname;
        public Point Point;
        public int direction = 0;
        public dian  dian1;
        public dian  dian2;
        public dian  dian3;
        public bool fh;
        public bool isPowered;
        
        public bool edgesRemoved;
        public List<dian> removedEdges;
        public List<dian> removedEdges2;

        public element(Graphics gra)
        {
            rect2 = new RectangleF(60, 60, 50, 25);
            rect = new RectangleF(50,50,50,50);
            rect5 = new RectangleF(80, 90, 25, 50);
            Point = new Point();
            dian1 = new dian(this, gra);
            dian2 = new dian(this, gra);
            dian3 = new dian(this, gra);

            sbname = "el";
            isPowered = false;

            

            edgesRemoved = false;
            removedEdges = new List<dian>();
            removedEdges2 = new List<dian>();

        }

        public virtual bool ispick(Point p)
        {
            float xmax = rect.X + rect.Width;
            float ymax = rect.Y + rect.Height;
            if ((p.X >= rect.X) && (p.X <= xmax) && (p.Y >= rect.Y) && (p.Y <= ymax))
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        public virtual bool ispickpoint(Point p)
        {

            int n = 0;
            int s = 0;
            int w = 0;
            int e = 0;
            float rr = rect.Width / 8;

            if (direction % 4 == 0)
            {
                e = 1; s = 0; n = 0; w = 0;
            }
            else if (direction % 4 == 1)
            {
                e = 0; s = 0; n = 1; w = 0;
            }
            else if (direction % 4 == 2)
            {
                e = 0; s = 0; n = 0; w = 1;
            }
            else
            {
                e = 0; s = 1; n = 0; w = 0;
            }

            float xmax = rect.X + e * 2 * rect.Width + n * rect.Width / 2 - w * rect.Width + s * rect.Width / 2 - n * rr / 2 - w * rr - s * rr / 2 + rr;
            float ymax = rect.Y + e * rect.Height / 2 - n * rect.Height + w * rect.Height / 2 + 2 * s * rect.Height - e * rr / 2 - n * rr - w * rr / 2 + rr;
            if ((p.X >= rect.X + e * 2 * rect.Width + n * rect.Width / 2 - w * rect.Width + s * rect.Width / 2 - n * rr / 2 - w * rr - s * rr / 2) && (p.X <= xmax) && (p.Y >= rect.Y + e * rect.Height / 2 - n * rect.Height + w * rect.Height / 2 + 2 * s * rect.Height - e * rr / 2 - n * rr - w * rr / 2) && (p.Y <= ymax))
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        public virtual bool ispickpoint2(Point p)
        {
            return false;
        }

        public virtual bool ispickpoint3(Point p)
        {
            return false;
        }




        public virtual void Resize(float scale)
        {
            float Scale = 1.0f;
            Scale *= scale;//放大缩小
            rect.Width *= scale;
            rect.Height *= scale;
        }
        


        public virtual void draw(Graphics g, Pen mypen, float scale)
        {
            

            rect.Width = rect.Width * scale;
            rect.Height = rect.Height * scale;

            int n = 0;
            int s = 0;
            int w = 0;
            int e = 0;

            if (direction % 4 == 0)
            {
                e = 1; s = 0; n = 0; w = 0;
            }
            else if (direction % 4 == 1)
            {
                e = 0; s = 0; n = 1; w = 0;
            }
            else if (direction % 4 == 2)
            {
                e = 0; s = 0; n = 0; w = 1;
            }
            else
            {
                e = 0; s = 1; n = 0; w = 0;
            }

            // 在矩形内部绘制图案
            //鼠标位置
            PointF center = new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
            float radius = Math.Min(rect.Width, rect.Height) / 2;
            PointF p1 = new PointF(rect.X + e * rect.Width + n * rect.Width / 2 + s * rect.Width / 2, rect.Y + e * rect.Height / 2 + w * rect.Height / 2 + s * rect.Height);
            PointF p2 = new PointF(rect.X + e * 2 * rect.Width + n * rect.Width / 2 - w * rect.Width + s * rect.Width / 2, rect.Y + e * rect.Height / 2 - n * rect.Height + w * rect.Height / 2 + 2 * s * rect.Height);
            float rr = rect.Width / 8;

            dian1.pos = p2;
            
            


            int pointsCount = 1000; // 正弦曲线的点数
            PointF[] points = new PointF[pointsCount];
            float step = (float)(rect.Width) / (pointsCount - 1);

            int pointsCount2 = 1000; // 正弦曲线的点数
            PointF[] points2 = new PointF[pointsCount];
            float step2 = (float)(rect.Width) / (pointsCount2 - 1);


            float frequency = 1f; ;// 正弦曲线的频率
               for (int i = 0; i < pointsCount; i++)
                {
                    float x1 = (e + w) * (rect.X + i * step + n * rect.Width / 2 + s * rect.Width / 2);
                    float y1 = (e + w) * (rect.Y + e * rect.Height / 2 + n * rect.Height + w * rect.Width / 2 + (float)(rect.Width / 4 * Math.Sin(2 * Math.PI * frequency * (x1 - rect.X) / (2 * rect.Width / 2))));
                    
                    float y2 = (n + s) * (rect.Y + i * step);
                    float x2 = 2 * (rect.X + rect.Width / 2) - (n + s) * (rect.X + n * rect.Height / 2 + s * rect.Width / 2 + (float)(rect.Width / 4 * Math.Sin(2 * Math.PI * frequency * (y2 - rect.Y) / (2 * rect.Width / 2))));
                   

                    points[i] = new PointF(x1, y1);
                    points2[i] = new PointF(x2,y2);
                }






               g.DrawLines(mypen, points);
               g.DrawLines(mypen, points2);

               g.DrawEllipse(mypen, rect.X, rect.Y, rect.Width, rect.Height);

               g.DrawLine(mypen, p1, p2);

               g.DrawEllipse(mypen, p2.X - n * rr / 2 - w * rr - s * rr / 2, p2.Y - e * rr / 2 - n * rr - w * rr / 2, rr, rr);
                
            
        }


        

        
    }
}
