示例#1
0
        public double GetDistanceToCircle(ACircularUnit circle)
        {
            var distToCenter = GetDistanceTo(circle);

            if (distToCenter <= circle.Radius)
            {
                return(0);
            }
            return(distToCenter - circle.Radius);
        }
示例#2
0
 public AVehicle GetFirstIntersector(ACircularUnit circle, bool isAerial)
 {
     for (var isMy = 0; isMy < 2; isMy++)
     {
         var nearby = _tree(isMy == 1, isAerial).FindFirstNearby(circle.X, circle.Y, Geom.Sqr(circle.Radius + G.VehicleRadius), -1);
         if (nearby != null && nearby.IntersectsWith(circle))
         {
             return(nearby);
         }
     }
     return(null);
 }
示例#3
0
        private static AVehicle _doFacilityProd(Sandbox env, AFacility facility)
        {
            var vehicleType = facility.VehicleType.Value;
            var isMy        = facility.IsMy;

            var pt = new ACircularUnit();

            pt.Radius = G.VehicleRadius;

            for (var j = 0; j < 11; j++)
            {
                for (var i = 0; i < 11; i++)
                {
                    if (facility.IsMy)
                    {
                        pt.X = facility.X + i * 6 + G.VehicleRadius;
                        pt.Y = facility.Y + j * 6 + G.VehicleRadius;
                    }
                    else
                    {
                        pt.X = facility.X2 - i * 6 - G.VehicleRadius;
                        pt.Y = facility.Y2 - j * 6 - G.VehicleRadius;
                    }

                    var nearby = env.GetFirstIntersector(pt, Utility.IsAerial(vehicleType));
                    if (nearby == null && !facility.IsMy)
                    {
                        nearby = OppUncheckedVehicles.Values
                                 .Where(x => Utility.IsAerial(x.Type) == Utility.IsAerial(vehicleType))
                                 .ArgMin(x => x.GetDistanceTo2(pt));
                    }

                    if (nearby == null || !nearby.IntersectsWith(pt) || nearby.Id == _nextFreeId && Geom.PointsEquals(nearby, pt))
                    {
                        return(new AVehicle(pt, _nextFreeId++, vehicleType, isMy));
                    }
                }
            }
            return(null);
        }
示例#4
0
 public virtual bool IntersectsWith(ACircularUnit unit)
 {
     // если касаются, то false
     return(GetDistanceTo2(unit) < Geom.Sqr(Radius + unit.Radius));
 }
示例#5
0
 public ACircularUnit(ACircularUnit unit) : base(unit)
 {
     Radius = unit.Radius;
 }