Пример #1
0
        public CacheObject GetNearestObjectToCenteroid()
        {
            double    minimumDistance   = 0.0;
            int       nearestPointIndex = -1;
            GridPoint centeroid         = Midpoint;

            foreach (GridPoint p in ListPoints)
            {
                double distance = GridPoint.GetDistanceBetweenPoints(p, centeroid);

                if (ListPoints.IndexOf(p) == 0)
                {
                    minimumDistance   = distance;
                    nearestPointIndex = ListPoints.IndexOf(p);
                }
                else
                {
                    if (minimumDistance > distance)
                    {
                        minimumDistance   = distance;
                        nearestPointIndex = ListPoints.IndexOf(p);
                    }
                }
            }

            return(ListCacheObjects[nearestPointIndex]);
        }
Пример #2
0
        public CacheUnit GetClosestUnitToPosition(GridPoint loc)
        {
            double minimumDistance   = 0.0;
            int    nearestPointIndex = -1;

            foreach (GridPoint p in this.ListPoints)
            {
                double distance = GridPoint.GetDistanceBetweenPoints(p, loc);

                if (this.ListPoints.IndexOf(p) == 0)
                {
                    minimumDistance   = distance;
                    nearestPointIndex = this.ListPoints.IndexOf(p);
                }
                else
                {
                    if (minimumDistance > distance)
                    {
                        minimumDistance   = distance;
                        nearestPointIndex = this.ListPoints.IndexOf(p);
                    }
                }
            }

            return(this.ListUnits[nearestPointIndex]);
        }
Пример #3
0
 //Special Method used inside cache collection
 public virtual bool PointInside(GridPoint Pos)
 {
     //return (Math.Min(rect_.TopLeft.X, rect_.BottomRight.X)>=Pos.X&&Math.Max(rect_.TopLeft.X, rect_.BottomRight.X)<=Pos.X&&
     //Math.Min(rect_.TopLeft.Y, rect_.BottomRight.Y)>=Pos.Y&&Math.Max(rect_.TopLeft.Y, rect_.BottomRight.Y)<=Pos.Y);
     return(GridPoint.GetDistanceBetweenPoints(PointPosition, Pos) - PointRadius <= 2.5f);
 }
Пример #4
0
 public override bool PointInside(GridPoint Pos)
 {
     return(GridPoint.GetDistanceBetweenPoints(PointPosition, Pos) <= (PointRadius));
 }