public bool Toca(Point pos)
        {
            Rectangle mouse = new Rectangle(pos.X, pos.Y, 3, 3);
            Rectangle pix   = new Rectangle(Source.Position.X, Source.Position.Y, 1, 1);

            PointF p1 = Punto(-50, 1);
            PointF p2 = Punto(-140, 1);

            int x1 = Source.Position.X;
            int y1 = Source.Position.Y;
            int x2 = Destiny.Position.X;
            int y2 = Destiny.Position.Y;

            int dx = x2 - x1; //nodo origen y destino
            int dy = y2 - y1; //nodo origen y destino


            if (Math.Abs(dx) > Math.Abs(dy))  // si esta 90 grados hasta 46
            {
                float m = (float)dy / (float)dx;
                if (m == 0)
                {
                }
                float b = y1 - m * x1;
                if (dx < 0)
                {
                    dx = -1;
                }
                else
                {
                    dx = 1;
                }

                while (x1 != x2)  //calcula las pendientes de toda la linea
                {
                    x1 += dx;
                    y1  = (int)Math.Round(m * x1 + b);

                    pix.X = x1;
                    pix.Y = y1;

                    if (mouse.IntersectsWith(pix))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                if (dy != 0)  // si esta de 45 a 0 grados
                {
                    float m = (float)dx / (float)dy;
                    float b = x1 - m * y1;
                    if (dy < 0)
                    {
                        dy = -1;
                    }
                    else
                    {
                        dy = 1;
                    }

                    while (y1 != y2)
                    {
                        y1   += dy;
                        x1    = (int)Math.Round(m * y1 + b);
                        pix.X = x1;
                        pix.Y = y1;

                        if (mouse.IntersectsWith(pix))
                        {
                            return(true);
                        }
                    }
                }
            }

            if (Destiny == Source) // si oreja
            {
                List <double> ptList = new List <double>();
                Bezier        bc     = new Bezier();

                ptList.Add(p1.X);
                ptList.Add(p1.Y);
                ptList.Add(p1.X + 20);
                ptList.Add(p1.Y - 50);
                ptList.Add(p1.X - 50);
                ptList.Add(p1.Y - 50);
                ptList.Add(p2.X);
                ptList.Add(p2.Y);

                const int Puntos = 200;
                double[]  ptind  = new double[ptList.Count];
                double[]  p      = new double[Puntos];
                ptList.CopyTo(ptind, 0);
                bc.Bezier2D(ptind, (Puntos) / 2, p);

                for (int i = 1; i != Puntos - 1; i += 2)
                {
                    if (mouse.IntersectsWith(new Rectangle((int)p[i + 1], (int)p[i], 10, 10)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
        public bool toca(Point pos)
        {
            Rectangle mouse = new Rectangle(pos.X, pos.Y, 3, 3);
            Rectangle pix   = new Rectangle(Origen.POS.X, Origen.POS.Y, 3, 3);

            PointF p1 = Punto(-50, 1);
            PointF p2 = Punto(-140, 1);


            int x0 = Origen.POS.X;
            int y0 = Origen.POS.Y;
            int x1 = Destino.POS.X;
            int y1 = Destino.POS.Y;

            int dx = Destino.POS.X - Origen.POS.X;
            int dy = Destino.POS.Y - Origen.POS.Y;

            if (Math.Abs(dx) > Math.Abs(dy))
            {
                float m = (float)dy / (float)dx;
                float b = y0 - m * x0;
                if (dx < 0)
                {
                    dx = -1;
                }
                else
                {
                    dx = 1;
                }
                while (x0 != x1)
                {
                    x0   += dx;
                    y0    = (int)Math.Round(m * x0 + b);
                    pix.X = x0;
                    pix.Y = y0;

                    if (mouse.IntersectsWith(pix))
                    {
                        return(true);
                    }
                }
            }
            else
            if (dy != 0)
            {
                float m = (float)dx / (float)dy;
                float b = x0 - m * y0;
                if (dy < 0)
                {
                    dy = -1;
                }
                else
                {
                    dy = 1;
                }
                while (y0 != y1)
                {
                    y0   += dy;
                    x0    = (int)Math.Round(m * y0 + b);
                    pix.X = x0;
                    pix.Y = y0;

                    if (mouse.IntersectsWith(pix))
                    {
                        return(true);
                    }
                }
            }

            if (Destino == Origen)
            {
                List <double> ptList = new List <double>();
                Bezier        bc     = new Bezier();

                ptList.Add(p1.X);
                ptList.Add(p1.Y);
                ptList.Add(p1.X + 20);
                ptList.Add(p1.Y - 50);
                ptList.Add(p1.X - 50);
                ptList.Add(p1.Y - 50);
                ptList.Add(p2.X);
                ptList.Add(p2.Y);


                const int Puntos = 200;
                double[]  ptind  = new double[ptList.Count];
                double[]  p      = new double[Puntos];
                ptList.CopyTo(ptind, 0);
                bc.Bezier2D(ptind, (Puntos) / 2, p);

                for (int i = 1; i != Puntos - 1; i += 2)
                {
                    if (mouse.IntersectsWith(new Rectangle((int)p[i + 1], (int)p[i], 10, 10)))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                p1 = Punto(1, 2);
                p2 = Punto(1, 3);
                List <double> ptList = new List <double>();
                Bezier        bc     = new Bezier();

                ptList.Add(Origen.POS.X);
                ptList.Add(Origen.POS.Y);
                ptList.Add(p1.X);
                ptList.Add(p1.Y);
                ptList.Add(p2.X);
                ptList.Add(p2.Y);
                ptList.Add(destino.POS.X);
                ptList.Add(destino.POS.Y);

                const int Puntos = 200;
                double[]  ptind  = new double[ptList.Count];
                double[]  p      = new double[Puntos];
                ptList.CopyTo(ptind, 0);
                bc.Bezier2D(ptind, (Puntos) / 2, p);

                for (int i = 1; i != Puntos - 1; i += 2)
                {
                    if (mouse.IntersectsWith(new Rectangle((int)p[i + 1], (int)p[i], 10, 10)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }