Distance() public method

public Distance ( Point p ) : double
p Point
return double
Ejemplo n.º 1
0
        public void TestDistance()
        {
            Point p1 = new Point (5, 5);
            Point p2 = new Point (0, 0);

            Assert.AreEqual (Math.Sqrt (50), p1.Distance (p2));

            p2 = new Point (5, 10);
            Assert.AreEqual (5, p1.Distance (p2));
            p1 = new Point (2, 10);
            Assert.AreEqual (3, p1.Distance (p2));
        }
Ejemplo n.º 2
0
        public void TestSelection()
        {
            Point start, center, stop, p;
            Selection s;

            start = new Point (0, 10);
            stop = new Point (10, 0);
            center = new Point (0, 0);
            Angle a = new Angle (start, center, stop);

            p = new Point (0.1, 0.3);
            s = a.GetSelection (p, 0.5);
            Assert.AreEqual (SelectionPosition.AngleCenter, s.Position);
            Assert.AreEqual (p.Distance (center), s.Accuracy);

            p = new Point (9.8, 0.3);
            s = a.GetSelection (p, 0.5);
            Assert.AreEqual (SelectionPosition.AngleStop, s.Position);
            Assert.AreEqual (p.Distance (stop), s.Accuracy);

            p = new Point (0.2, 9.9);
            s = a.GetSelection (p, 0.5);
            Assert.AreEqual (SelectionPosition.AngleStart, s.Position);
            Assert.AreEqual (p.Distance (start), s.Accuracy);

            p = new Point (5, 5);
            s = a.GetSelection (p, 0.5);
            Assert.IsNull (s);
        }
Ejemplo n.º 3
0
        public override Selection GetSelection(Point p, double pr=0.05, bool inMotion=false)
        {
            double d;

            if (Selected) {
                return base.GetSelection (p, pr);
            }

            if (MatchPoint (Top, p, pr, out d)) {
                return new Selection (this, SelectionPosition.Top, d);
            } else if (MatchPoint (Bottom, p, pr, out d)) {
                return new Selection (this, SelectionPosition.Bottom, d);
            } else if (MatchPoint (Left, p, pr, out d)) {
                return new Selection (this, SelectionPosition.Left, d);
            } else if (MatchPoint (Right, p, pr, out d)) {
                return new Selection (this, SelectionPosition.Right, d);
            } else {
                /* Ellipse equation */
                double a = Math.Pow (p.X - Center.X, 2) / Math.Pow (AxisX, 2);
                double b = Math.Pow (p.Y - Center.Y, 2) / Math.Pow (AxisY, 2);
                if ((a + b) <= 1) {
                    return new Selection (this, SelectionPosition.All, p.Distance (Center));
                } else {
                    return null;
                }
            }
        }
Ejemplo n.º 4
0
 public override Selection GetSelection(Point p, double pr = 0.05, bool inMotion = false)
 {
     if (p.Distance (Start) < pr) {
         return new Selection (this, SelectionPosition.AngleStart, p.Distance (Start));
     } else if (p.Distance (Stop) < pr) {
         return new Selection (this, SelectionPosition.AngleStop, p.Distance (Stop));
     } else if (p.Distance (Center) < pr) {
         return new Selection (this, SelectionPosition.AngleCenter, p.Distance (Center));
     } else {
         return null;
     }
 }
Ejemplo n.º 5
0
 public Selection GetSelection(Point point, double precision, bool inMotion=false)
 {
     if (point.Distance (Start) < precision) {
         return new Selection (this, SelectionPosition.LineStart);
     } else if (Points.Count == 2 && point.Distance (Stop) < precision) {
         return new Selection (this, SelectionPosition.LineStop);
     }
     return null;
 }
Ejemplo n.º 6
0
        public override Selection GetSelection(Point p, double pr = 0.05, bool inMotion = false)
        {
            double d;

            if (MatchPoint (Start, p, pr, out d)) {
                return new Selection (this, SelectionPosition.LineStart, d);
            } else if (MatchPoint (Stop, p, pr, out d)) {
                return new Selection (this, SelectionPosition.LineStop, d);
            } else {
                double minx, maxx, miny, maxy;

                minx = Math.Min (Start.X, Stop.X) - pr;
                maxx = Math.Max (Start.X, Stop.X) + pr;
                miny = Math.Min (Start.Y, Stop.Y) - pr;
                maxy = Math.Max (Start.Y, Stop.Y) + pr;
                if (p.X < minx || p.X > maxx || p.Y < miny || p.Y > maxy) {
                    return null;
                }
                if (Start.X == Stop.X) {
                    d = p.Distance (new Point (Start.X, p.Y));
                } else if (Start.Y == Stop.Y) {
                    d = p.Distance (new Point (p.X, Start.Y));
                } else {
                    double yi, slope;

                    slope = (Start.Y - Stop.Y) / (Start.X - Stop.X);
                    yi = Start.Y - (slope * Start.X);
                    d = Math.Abs ((slope * p.X) + yi - p.Y);
                    d /= 2;
                }

                if (d < pr) {
                    return new Selection (this, SelectionPosition.All, d);
                } else {
                    return null;
                }
            }
        }