예제 #1
0
        private bool CheckLine(MyPoint p1, MyPoint p2, double X, double Y)
        {
            if (p1.X > p2.X)
            {
                MyPoint tmp = p2;
                p2 = p1;
                p1 = tmp;
            }
            int y;

            for (int x = p1.X; x < p2.X; x++)
            {
                y = (int)((p1.Y - p2.Y) * 1.0 / ((p1.X - p2.X) * 1.0) * x + p1.Y - ((p1.Y - p2.Y) * 1.0 / ((p1.X - p2.X) * 1.0)) * p1.X);
                if ((x - radius * 2 < X && x + radius * 2 > X) && (y - radius * 2 < Y && y + radius * 2 > Y))
                {
                    int y1, y2;
                    if (p2.Y > p1.Y)
                    {
                        y2 = p2.Y;
                        y1 = p1.Y;
                    }
                    else
                    {
                        y2 = p1.Y;
                        y1 = p2.Y;
                    }
                    middlePoint.setCoords(p1.X + (p2.X - p1.X) / 2, y1 + (y2 - y1) / 2);

                    return(true);
                }
            }
            if (p1.Y > p2.Y)
            {
                MyPoint tmp = p2;
                p2 = p1;
                p1 = tmp;
            }
            for (y = p1.Y; y < p2.Y; y++)
            {
                int x = p1.X;
                if ((x - radius * 2 < X && x + radius * 2 > X) && (y - radius * 2 < Y && y + radius * 2 > Y))
                {
                    int y1, y2;
                    if (p2.Y > p1.Y)
                    {
                        y2 = p2.Y;
                        y1 = p1.Y;
                    }
                    else
                    {
                        y2 = p1.Y;
                        y1 = p2.Y;
                    }
                    middlePoint.setCoords(p1.X + (p2.X - p1.X) / 2, y1 + (y2 - y1) / 2);

                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
 private void MainPictureBox_MouseMovePoly(object sender, MouseEventArgs e)
 {
     for (int i = 0; i < points.Count; i++)
     {
         MyPoint p = points[i];
         points[points.IndexOf(p)].setCoords(p.X + (e.X - mainPoint.X), p.Y + (e.Y - mainPoint.Y));
     }
     mainPoint.setCoords(e.X, e.Y);
     moved = true;
     mainPictureBox.Refresh();
 }
예제 #3
0
 public override void movePoint(MyPoint p1, MyPoint p2, ref int dX, ref int dY)
 {
     if (Math.Abs(calculateLength(p1, p2) - maxLength) > 1)
     {
         p2.setCoords(p2.X + dX, p2.Y + dY);
         if (Math.Abs(calculateLength(p1, p2) - maxLength) > 1)
         {
             if (p2.Y < p1.Y)
             {
                 p2.setCoords(p1.X, p1.Y - (int)(maxLength));
             }
             else
             {
                 p2.setCoords(p1.X, p1.Y + (int)(maxLength));
             }
         }
     }
     else
     {
         dX = 0;
         dY = 0;
     }
 }