Beispiel #1
0
        double Distance(Point p1, Point p2)
        {
            double xd = Math.Abs(p1.X - p2.X);
            double yd = Math.Abs(p1.Y - p2.Y);

            return(Math.Sqrt(Math.Pow(xd, 2) + Math.Pow(yd, 2)));
        }
Beispiel #2
0
 void TranslateToOriginCoords(Point point)
 {
     point.X = Math.Max(0, point.X - xOffset);
     point.Y = Math.Max(0, point.Y - yOffset);
     point.X = Math.Min(sourceWidth, (int)(point.X / xScale));
     point.Y = Math.Min(sourceHeight, (int)(point.Y / yScale));
 }
Beispiel #3
0
        void DrawArrow(Context c, Point src, Point dest)
        {
            double vx1, vy1, vx2, vy2;
            double angle = Math.Atan2(dest.Y - src.Y, dest.X - src.X) + Math.PI;

            vx1 = dest.X + (ARROW_LENGHT + LINE_WIDTH) * Math.Cos(angle - ARROW_DEGREES);
            vy1 = dest.Y + (ARROW_LENGHT + LINE_WIDTH) * Math.Sin(angle - ARROW_DEGREES);
            vx2 = dest.X + (ARROW_LENGHT + LINE_WIDTH) * Math.Cos(angle + ARROW_DEGREES);
            vy2 = dest.Y + (ARROW_LENGHT + LINE_WIDTH) * Math.Sin(angle + ARROW_DEGREES);

            c.MoveTo(dest.X, dest.Y);
            c.LineTo(vx1, vy1);
            c.MoveTo(dest.X, dest.Y);
            c.LineTo(vx2, vy2);
            c.Stroke();
            c.Fill();
        }
Beispiel #4
0
        protected virtual void OnDrawingareaMotionNotifyEvent(object o, Gtk.MotionNotifyEventArgs args)
        {
            Point point;

            if (!Sensitive)
            {
                return;
            }

            if (selectedCoords == null)
            {
                return;
            }
            point = new Point((int)args.Event.X, (int)args.Event.Y);
            TranslateToOriginCoords(point);
            selectedPoint.Y = point.Y;
            selectedPoint.X = point.X;
            QueueDraw();
        }
Beispiel #5
0
        void FindNearestPoint(Point cursor, out Coordinates coords, out Point point)
        {
            double minDistance = Int32.MaxValue;

            coords = null;
            point  = null;

            TranslateToOriginCoords(cursor);
            foreach (Coordinates c in Coordinates)
            {
                foreach (Point p in c)
                {
                    double dist = Distance(cursor, p);
                    if (dist < minDistance)
                    {
                        minDistance = dist;
                        coords      = c;
                        point       = p;
                    }
                }
            }
        }
Beispiel #6
0
 void DrawPoint(Context c, Point location)
 {
     c.Arc(location.X, location.Y, LINE_WIDTH, 0, 2 * Math.PI);
     c.StrokePreserve();
     c.Fill();
 }
Beispiel #7
0
 void DrawLine(Context c, Point src, Point dest)
 {
     c.MoveTo(src.X, src.Y);
     c.LineTo(dest.X, dest.Y);
     c.Stroke();
 }
Beispiel #8
0
 Point TranslateToDestCoords(Point point)
 {
     return(new Point((int)(point.X * xScale),
                      (int)(point.Y * yScale)));
 }