Ejemplo n.º 1
0
        private Position CheckHotSpot(MouseEventArgs e)
        {
            Point pt = e.Location;

            Point[] hots = RectTracker.GetPointsFromRect(Boundary);

            bool[] check = new bool[8];
            check[0] = CheckPointAt(hots[0], pt, PointAtPosition.TopLeft, ref PointAt, ref hotPoint);
            //check[1] =
            CheckPointAt(hots[1], pt, PointAtPosition.TopMiddle, ref PointAt, ref hotPoint);
            check[2] = CheckPointAt(hots[2], pt, PointAtPosition.TopRight, ref PointAt, ref hotPoint);
            //check[3] =
            CheckPointAt(hots[3], pt, PointAtPosition.RightMiddle, ref PointAt, ref hotPoint);
            check[4] = CheckPointAt(hots[4], pt, PointAtPosition.RightBottom, ref PointAt, ref hotPoint);
            //check[5] =
            CheckPointAt(hots[5], pt, PointAtPosition.BottomMiddle, ref PointAt, ref hotPoint);
            check[6] = CheckPointAt(hots[6], pt, PointAtPosition.BottomLeft, ref PointAt, ref hotPoint);
            //check[7] =
            CheckPointAt(hots[7], pt, PointAtPosition.LeftMidlle, ref PointAt, ref hotPoint);

            foreach (bool p in check)
            {
                if (p == true)
                {
                    return(Position.Corner);
                }
            }

            if (Boundary.Contains(pt))
            {
                return(Position.Center);
            }

            return(Position.Nothing);
        }
Ejemplo n.º 2
0
        public void Search_Area_ReturnsAreaPoints()
        {
            var center   = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad     = new QuadTree <Point>(boundary);

            var firstQuadrant  = new Boundary(new Point(+0.5, +0.5), 0.5, 0.5);
            var secondQuadrant = new Boundary(new Point(-0.5, +0.5), 0.5, 0.5);
            var thirdQuadrant  = new Boundary(new Point(-0.5, -0.5), 0.5, 0.5);
            var fourthQuadrant = new Boundary(new Point(+0.5, -0.5), 0.5, 0.5);

            var pointsPerQuadrant = 10;
            var generator         = new RandomGenerator();

            // insert points in the third quadrant
            var pointsInThirdQuadrant = generator.GeneratePointsWithin(thirdQuadrant, pointsPerQuadrant);

            pointsInThirdQuadrant.ForEach(p => quad.Insert(p));

            // insert points in other quadrants
            var pointsInOtherQuadrants = new List <Point>();

            pointsInOtherQuadrants.AddRange(generator.GeneratePointsWithin(firstQuadrant, pointsPerQuadrant));
            pointsInOtherQuadrants.AddRange(generator.GeneratePointsWithin(secondQuadrant, pointsPerQuadrant));
            pointsInOtherQuadrants.AddRange(generator.GeneratePointsWithin(fourthQuadrant, pointsPerQuadrant));
            pointsInOtherQuadrants.ForEach(p => quad.Insert(p));

            // search third quadrant
            var results = quad.Search(thirdQuadrant);

            // assert all result points are in third quadrant
            Assert.IsTrue(results.Count == pointsPerQuadrant);
            results.ForEach(p => Assert.IsTrue(thirdQuadrant.Contains(p)));
        }
Ejemplo n.º 3
0
        public void Contains_PointOutOfBoundary_ReturnsFalse()
        {
            var center = new Point(1,1);
            var boundary = new Boundary(center, 2, 2);

            var pointOutOfBounds = new Point(-2, -4);
            var result = boundary.Contains(pointOutOfBounds);

            Assert.IsFalse(result);
        }
Ejemplo n.º 4
0
        public void Contains_PointWithinBoundary_ReturnsTrue()
        {
            var center = new Point(-1, 1);
            var boundary = new Boundary(center, 1, 1);

            var pointWithinBounds = new Point(-0.3, 0.7);
            var result = boundary.Contains(pointWithinBounds);

            Assert.IsTrue(result);
        }
Ejemplo n.º 5
0
        public void GeneratePointsWithin_Boundary_BoundaryContainsAllPoints()
        {
            var center    = new Point(0, 0);
            var boundary  = new Boundary(center, 1, 1);
            var generator = new RandomGenerator();

            var results = generator.GeneratePointsWithin(boundary, 1000);

            results.ForEach(p => Assert.IsTrue(boundary.Contains(p)));
        }
Ejemplo n.º 6
0
        public void Contains_PointOnBoundary_ReturnsTrue()
        {
            var center   = new Point(-1, -1);
            var boundary = new Boundary(center, 1, 1);

            var pointOnBoundary = new Point(0, 0);
            var result          = boundary.Contains(pointOnBoundary);

            Assert.IsTrue(result);
        }
Ejemplo n.º 7
0
        public void Contains_PointWithinBoundary_ReturnsTrue()
        {
            var center   = new Point(-1, 1);
            var boundary = new Boundary(center, 1, 1);

            var pointWithinBounds = new Point(-0.3, 0.7);
            var result            = boundary.Contains(pointWithinBounds);

            Assert.IsTrue(result);
        }
Ejemplo n.º 8
0
        public void Contains_PointOutOfBoundary_ReturnsFalse()
        {
            var center   = new Point(1, 1);
            var boundary = new Boundary(center, 2, 2);

            var pointOutOfBounds = new Point(-2, -4);
            var result           = boundary.Contains(pointOutOfBounds);

            Assert.IsFalse(result);
        }
Ejemplo n.º 9
0
        public void Contains_PointOnBoundary_ReturnsTrue()
        {
            var center = new Point(-1, -1);
            var boundary = new Boundary(center, 1, 1);

            var pointOnBoundary = new Point(0, 0);
            var result = boundary.Contains(pointOnBoundary);

            Assert.IsTrue(result);
        }
Ejemplo n.º 10
0
        public void GeneratePointsWithin_Boundary_BoundaryContainsAllPoints()
        {
            var center = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var generator = new RandomGenerator();

            var results = generator.GeneratePointsWithin(boundary, 1000);

            results.ForEach(p => Assert.IsTrue(boundary.Contains(p)));
        }
Ejemplo n.º 11
0
        public virtual bool UpdateSelected(Point point, ref LeShape shape0)
        {
            if (Boundary.Contains(point))
            {
                selected = true;
                shape0   = this;
            }
            else
            {
                selected = false;
            }

            return(selected);
        }
Ejemplo n.º 12
0
    public QuadTree(Boundary boundary, int capacity, IEnumerable <Point2D> PointsInParent)
    {
        this.boundary = boundary;
        this.capacity = capacity;
        ListOfPoints  = new List <Point2D>();
        division      = false;


        foreach (Point2D p in PointsInParent)
        {
            if (boundary.Contains(p))
            {
                ListOfPoints.Add(p);
            }
        }
    }
Ejemplo n.º 13
0
        public override void MouseMove(object sender, MouseEventArgs e)
        {
            switch (curAction)
            {
            case Action.AboutToMoveShape:
                Common.MyDrawReversibleRectangle(LeCanvas.self.Canvas, AreaRect);
                curAction  = Action.MoveShape;
                ptPrevious = e.Location;
                break;

            case Action.MoveShape:
                MoveReversiableBoundary(e);
                break;

            case Action.ResizeShape:
                ptCurrent = new Point(e.X, e.Y);
                Common.MyDrawReversibleRectangle(LeCanvas.self.Canvas, AreaRect);
                Rectangle old0 = AreaRect;

                AreaRect = Common.GetRectangle(ptOrigin, ptCurrent);

                Common.CheckForBoundary(LeCanvas.self.Canvas, ref AreaRect, old0);
                Common.MyDrawReversibleRectangle(LeCanvas.self.Canvas, AreaRect);
                break;

            case Action.Nothing:
                LeCanvas.self.Canvas.Cursor = GetMouseIcon(e);
                if (Boundary.Contains(e.X, e.Y))
                {
                    curAction = Action.MouseAtShape;
                    base.DrawMouseHoverShape();
                }
                break;

            case Action.MouseAtShape:
                LeCanvas.self.Canvas.Cursor = GetMouseIcon(e);
                if (Boundary.Contains(e.X, e.Y) == false)
                {
                    curAction = Action.Nothing;
                }
                break;
            }
        }
Ejemplo n.º 14
0
        public void Search_PartialBoundary_ReturnResults()
        {
            var center   = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad     = new QuadTree <Point>(boundary);

            var point      = new Point(0.75, 0.75);
            var searchArea = new Boundary(new Point(1, 1), 1, 1);

            Assert.IsTrue(boundary.Contains(point));
            Assert.IsTrue(searchArea.Contains(point));

            quad.Insert(point);

            var results = quad.Search(searchArea);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results.Contains(point));
        }
Ejemplo n.º 15
0
        protected internal override void OnMouseUp(object sender, MouseEventArgs e)
        {
            base.OnMouseUp(sender, e);

            if (InUse)
            {
                var selectionQuery = canvas.SelectedLayer.Where(x => _selection.Contains(x));
                foreach (var target in selectionQuery)
                {
                    target.Selected = true;
                }

                canvas.Invalidate();
                if (selectionQuery.Count() > 0)
                {
                    canvas.Tool = ToolFactory.GetInstance <Pointer>();
                }
                _selection = null;
                InUse      = false;
            }
        }
Ejemplo n.º 16
0
    public bool Insert(Point2D point2D)
    {
        if (boundary.Contains(point2D) == false)
        {
            return(false);
        }

        if (ListOfPoints.Count < capacity)
        {
            ListOfPoints.Add(point2D);
            return(true);
        }
        else
        {
            if (division == false)
            {
                Subdivide();
            }

            if (northEast.Insert(point2D) == true)
            {
                return(true);
            }
            else if (northWest.Insert(point2D) == true)
            {
                return(true);
            }
            else if (southEast.Insert(point2D) == true)
            {
                return(true);
            }
            else if (southWest.Insert(point2D) == true)
            {
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 17
0
        /// <summary>
        /// Insert a point into the QuadTree.
        /// </summary>
        /// <param name="point">Position where to insert the point.</param>
        /// <param name="obj">The object that is attached to the point.</param>
        /// <returns>Returns true if the point was successfully inserted into this QuadTree, otherwise false.</returns>
        public bool Insert(Vector2 point, T obj)
        {
            if (!Boundary.Contains(point))
            {
                return(false);
            }

            if (points.Count < Capacity)
            {
                // Inserted a point successfully.
                points.Add(new Tuple <Vector2, T>(point, obj));
                return(true);
            }
            else if (!divided)
            {
                Subdivide();
            }

            if (NorthWest.Insert(point, obj))
            {
                return(true);
            }
            if (NorthEast.Insert(point, obj))
            {
                return(true);
            }
            if (SouthWest.Insert(point, obj))
            {
                return(true);
            }
            if (SouthEast.Insert(point, obj))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 18
0
        public void Search_Area_ReturnsAreaPoints()
        {
            var center = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad = new QuadTree<Point>(boundary);

            var firstQuadrant = new Boundary(new Point(+0.5, +0.5), 0.5, 0.5);
            var secondQuadrant = new Boundary(new Point(-0.5, +0.5), 0.5, 0.5);
            var thirdQuadrant = new Boundary(new Point(-0.5, -0.5), 0.5, 0.5);
            var fourthQuadrant = new Boundary(new Point(+0.5, -0.5), 0.5, 0.5);

            var pointsPerQuadrant = 10;
            var generator = new RandomGenerator();

            // insert points in the third quadrant
            var pointsInThirdQuadrant = generator.GeneratePointsWithin(thirdQuadrant, pointsPerQuadrant);
            pointsInThirdQuadrant.ForEach(p => quad.Insert(p));

            // insert points in other quadrants
            var pointsInOtherQuadrants = new List<Point>();
            pointsInOtherQuadrants.AddRange(generator.GeneratePointsWithin(firstQuadrant, pointsPerQuadrant));
            pointsInOtherQuadrants.AddRange(generator.GeneratePointsWithin(secondQuadrant, pointsPerQuadrant));
            pointsInOtherQuadrants.AddRange(generator.GeneratePointsWithin(fourthQuadrant, pointsPerQuadrant));
            pointsInOtherQuadrants.ForEach(p => quad.Insert(p));

            // search third quadrant
            var results = quad.Search(thirdQuadrant);

            // assert all result points are in third quadrant
            Assert.IsTrue(results.Count == pointsPerQuadrant);
            results.ForEach(p => Assert.IsTrue(thirdQuadrant.Contains(p)));
        }
Ejemplo n.º 19
0
        public void Search_PartialBoundary_ReturnResults()
        {
            var center = new Point(0, 0);
            var boundary = new Boundary(center, 1, 1);
            var quad = new QuadTree<Point>(boundary);

            var point = new Point(0.75, 0.75);
            var searchArea = new Boundary(new Point(1, 1), 1, 1);

            Assert.IsTrue(boundary.Contains(point));
            Assert.IsTrue(searchArea.Contains(point));

            quad.Insert(point);

            var results = quad.Search(searchArea);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results.Contains(point));
        }