Пример #1
0
        public void TestGridRectangle()
        {
            GridRectangle rectA = new GridRectangle(10, 50, 20, 40);

            bool success = rectA.Contains(new GridVector2(10, 20));
            Debug.Assert(success);

            success = rectA.Contains(new GridVector2(50, 40));
            Debug.Assert(success);

            success = rectA.Contains(rectA.Center);
            Debug.Assert(success);

            GridRectangle rectBOverlaps = new GridRectangle(5, 15, 10, 21);
            success = rectA.Intersects(rectBOverlaps);
            Debug.Assert(success);

            success = rectA.Contains(rectBOverlaps);
            Debug.Assert(false == success);

            GridRectangle rectCNoOverlap = new GridRectangle(5, 15, 10, 19);
            success = rectA.Intersects(rectCNoOverlap);
            Debug.Assert(false == success);

            success = rectA.Contains(rectBOverlaps);
            Debug.Assert(false == success);

            GridRectangle rectDContained = new GridRectangle(15, 45, 25, 35);
            success = rectA.Intersects(rectDContained);
            Debug.Assert(success);

            success = rectA.Contains(rectDContained);
            Debug.Assert(success);

            /*Scale the rectangle and test again*/
            rectA.Scale(2);

            Debug.Assert(-10.0 == rectA.Left &&
                         70 == rectA.Right &&
                         10 == rectA.Bottom &&
                         50 == rectA.Top);

            /*Scale the rectangle and test again*/
            rectA.Scale(0.5);

            Debug.Assert(10.0 == rectA.Left &&
                         50 == rectA.Right &&
                         20 == rectA.Bottom &&
                         40 == rectA.Top);
        }
Пример #2
0
        private static List<Location_CanvasViewModel> FindVisibleLocations(ICollection<Location_CanvasViewModel> locations,  GridRectangle VisibleBounds)
        {
            GridCircle VisibleCircle = new GridCircle(VisibleBounds.Center, GridVector2.Distance(VisibleBounds.Center, new GridVector2(VisibleBounds.Left, VisibleBounds.Top)));
            List<Location_CanvasViewModel> listLocationsToDraw = new List<Location_CanvasViewModel>(locations.Count);

            foreach (Location_CanvasViewModel loc in locations)
            {
                if (loc == null)
                    continue;

                if (!loc.VolumePositionHasBeenCalculated)
                    continue;

                //Find out if we should draw the location
                if (loc.TypeCode == LocationType.CIRCLE)
                {
                    if (VisibleCircle.Intersects(loc.VolumePosition, loc.Radius) == false)
                        continue;
                }
                else if (loc.TypeCode == LocationType.POINT)
                {
                    if (VisibleBounds.Contains(loc.VolumePosition) == false)
                        continue;
                }
                else
                {
                    Debug.Fail("Unknown location type");
                }

                Structure ParentStructure = loc.Parent;
                if (ParentStructure == null)
                    continue;

                if (ParentStructure.Type == null)
                    continue;

                listLocationsToDraw.Add(loc);
            }

            return listLocationsToDraw;
        }
Пример #3
0
        public List<MappingGridVector2> IntersectingMappedRectangle(GridRectangle gridRect, bool IncludeAdjacent)
        {
            List<MappingGridVector2> foundPoints = IntersectingRectangle(gridRect, this.mapTriangles);
            if (!IncludeAdjacent)
            {
                for (int i = 0; i < foundPoints.Count; i++)
                {
                    if (!gridRect.Contains(foundPoints[i].MappedPoint))
                    {
                        foundPoints.RemoveAt(i);
                        i--;
                    }
                }
            }

            return foundPoints;
        }
Пример #4
0
        /// <summary>
        /// Returns all points inside the requested region.  
        /// If include adjacent is set to true we include points with an edge that crosses the border of the requested rectangle
        /// </summary>
        /// <param name="gridRect"></param>
        /// <returns></returns>
        private List<MappingGridVector2> IntersectingRectangle(GridRectangle gridRect,
                                                               QuadTree<List<MappingGridTriangle>> PointTree)
        {
            List<GridVector2> Points;
            List<List<MappingGridTriangle>> ListofListTriangles;

            List<MappingGridVector2> MappingPointList= null;

            if (gridRect.Contains(PointTree.Border))
            {
                MappingPointList = new List<MappingGridVector2>(_mapPoints);
                return MappingPointList;
            }

            PointTree.Intersect(gridRect, out Points, out ListofListTriangles);

            bool[] Added = new bool[_mapPoints.Length];
            MappingPointList = new List<MappingGridVector2>(Points.Count * 2);
            List<List<MappingGridTriangle>> MappingTriangleList = new List<List<MappingGridTriangle>>(Points.Count * 2);

            //Add all the unique points bordering the requested rectangle
            for (int iPoint = 0; iPoint < Points.Count; iPoint++)
            {
                List<MappingGridTriangle> FoundTriangleList = ListofListTriangles[iPoint];
                for (int iTri = 0; iTri < FoundTriangleList.Count; iTri++)
                {
                    MappingGridTriangle Triangle = FoundTriangleList[iTri];
                    if (!Added[Triangle.N1])
                    {
                        Added[Triangle.N1] = true;
                        MappingPointList.Add(this._mapPoints[Triangle.N1]);
                        MappingTriangleList.Add(this._TriangleList[Triangle.N1]);
                    }
                    if (!Added[Triangle.N2])
                    {
                        Added[Triangle.N2] = true;
                        MappingPointList.Add(this._mapPoints[Triangle.N2]);
                        MappingTriangleList.Add(this._TriangleList[Triangle.N1]);
                    }
                    if (!Added[Triangle.N3])
                    {
                        Added[Triangle.N3] = true;
                        MappingPointList.Add(this._mapPoints[Triangle.N3]);
                        MappingTriangleList.Add(this._TriangleList[Triangle.N1]);
                    }
                }
            }

            return MappingPointList;
        }
        /// <summary>
        /// Return true if the passed point falls within our location
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public bool Contains(WebAnnotation.ViewModel.SectionLocationsViewModel sectionAnnotations, GridVector2 pos)
        {
            GridVector2 locPosition = this.VolumePosition;

            switch (modelObj.TypeCode)
            {
                case LocationType.POINT: //A point
                    //HACK, assume label size is 256 pixels across
                    Vector2 offset = GetLabelSize();
                    offset.X *= AnnotationOverlay.LocationTextScaleFactor;
                    offset.Y *= AnnotationOverlay.LocationTextScaleFactor;

                    GridRectangle _Bounds = new GridRectangle(new GridVector2(locPosition.X - (offset.X / 2), locPosition.Y - (offset.Y / 2)),
                                                        offset.X,
                                                        offset.Y);
                    return _Bounds.Contains(pos);
                case LocationType.CIRCLE: //A circle
                    double distance = GridVector2.Distance(locPosition, pos);
                    return distance <= Radius;

                default:
                    Trace.WriteLine("Calling LocationObj::Contains on an unknown type of location", "WebAnnotation");
                    return false;
            }
        }