GetSelection() public méthode

public GetSelection ( Point p, double pr = 0.05, bool inMotion = false ) : Selection
p Point
pr double
inMotion bool
Résultat Selection
Exemple #1
0
        public void TestGetSelection()
        {
            Point p1, p2, p3;
            Selection s;

            p1 = new Point (0, 5);
            p2 = new Point (5, 5);
            Line line = new Line (p1, p2, LineType.Arrow, LineStyle.Dashed);

            /* None */
            p3 = new Point (10, 5);
            s = line.GetSelection (p3, 1);
            Assert.IsNull (s);

            /* Start */
            p3 = new Point (0, 5);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.LineStart, s.Position);
            Assert.AreEqual ((double)0, s.Accuracy);
            p3 = new Point (1, 5);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.LineStart, s.Position);
            Assert.AreEqual ((double)1, s.Accuracy);

            /* Stop */
            p3 = new Point (5, 5);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.LineStop, s.Position);
            Assert.AreEqual ((double)0, s.Accuracy);
            p3 = new Point (6, 5);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.LineStop, s.Position);
            Assert.AreEqual ((double)1, s.Accuracy);

            /* All */
            p3 = new Point (2, 5);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.All, s.Position);
            Assert.AreEqual ((double)0, s.Accuracy);
            p3 = new Point (2, 5.1);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.All, s.Position);
            Assert.AreEqual (0.1, Math.Round (s.Accuracy, 3));

            p1 = new Point (0, 0);
            p2 = new Point (5, 5);
            line = new Line (p1, p2, LineType.Arrow, LineStyle.Dashed);

            p3 = new Point (0, 3);
            s = line.GetSelection (p3, 1);
            Assert.IsNull (s);

            p3 = new Point (2.5, 2.5);
            s = line.GetSelection (p3, 1);
            Assert.AreEqual (SelectionPosition.All, s.Position);
            Assert.AreEqual ((double)0, s.Accuracy);
        }
Exemple #2
0
        public override Selection GetSelection(Point p, double pr = 0.05, bool inMotion = false)
        {
            double    d;
            Selection sel;

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

            if (MatchPoint(Start, p, pr, out d))
            {
                return(new Selection(this, SelectionPosition.TopLeft, d));
            }
            else if (MatchPoint(StopI, p, pr, out d))
            {
                return(new Selection(this, SelectionPosition.BottomRight, d));
            }
            else if (MatchPoint(StartI, p, pr, out d))
            {
                return(new Selection(this, SelectionPosition.TopRight, d));
            }
            else if (MatchPoint(StopI, p, pr, out d))
            {
                return(new Selection(this, SelectionPosition.BottomLeft, d));
            }
            else
            {
                Line aline = new Line {
                    Start = Start, Stop = Stop
                };
                sel = aline.GetSelection(p, pr);
                if (sel == null)
                {
                    Line bline = new Line {
                        Start = StartI, Stop = StopI
                    };
                    sel = bline.GetSelection(p, pr);
                }
                if (sel != null)
                {
                    sel.Drawable = this;
                }
                return(sel);
            }
        }
Exemple #3
0
        public override Selection GetSelection(Point p, double pr = 0.05, bool inMotion = false)
        {
            double d;
            Selection sel;

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

            if (MatchPoint (Start, p, pr, out d)) {
                return new Selection (this, SelectionPosition.TopLeft, d);
            } else if (MatchPoint (StopI, p, pr, out d)) {
                return new Selection (this, SelectionPosition.BottomRight, d);
            } else if (MatchPoint (StartI, p, pr, out d)) {
                return new Selection (this, SelectionPosition.TopRight, d);
            } else if (MatchPoint (StopI, p, pr, out d)) {
                return new Selection (this, SelectionPosition.BottomLeft, d);
            } else {
                Line aline = new Line { Start = Start, Stop = Stop };
                sel = aline.GetSelection (p, pr);
                if (sel == null) {
                    Line bline = new Line { Start = StartI, Stop = StopI };
                    sel = bline.GetSelection (p, pr);
                }
                if (sel != null) {
                    sel.Drawable = this;
                }
                return sel;
            }
        }