private Point[] GetZones(FloatRectangle rect) { List <Point> result = new List <Point>(); Point firstZone = new Point((int)Math.Floor(rect.X / zoneSize), (int)Math.Floor(rect.Y / zoneSize)); int width = 0; int height = 0; FloatRectangle zone = new FloatRectangle(firstZone.X * 32, firstZone.Y * 32, zoneSize, zoneSize); while (rect.Intersects(zone)) { zone.X += zoneSize; width++; } zone = new FloatRectangle(firstZone.X * 32, firstZone.Y * 32, zoneSize, zoneSize); while (rect.Intersects(zone)) { zone.Y += zoneSize; height++; } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { result.Add(new Point(firstZone.X + x, firstZone.Y + y)); } } return(result.ToArray()); }
public GamePoleObject[] GetObjectsIntersectsRect(FloatRectangle rect) { Point[] zones = GetZones(rect); HashSet <GamePoleObject> objs = new HashSet <GamePoleObject>(); for (int i = 0; i < zones.Length; i++) { HashSet <GamePoleObject> obj; if (!p2o.TryGetValue(zones[i], out obj)) { obj = new HashSet <GamePoleObject>(); p2o[zones[i]] = obj; } for (int j = 0; j < obj.Count; j++) { objs.Add(obj.ElementAt(j)); } } return(objs.Where((GamePoleObject o) => o.Rectangle.Intersects(rect)).ToArray()); }
public bool IsInside(FloatRectangle rect) { throw new NotImplementedException(); }
//public bool Intersects(FloatRectangle rect) //{ // return !( // rect.X > X + Width || // rect.Y > Y + Height || // rect.Y + rect.Height < Y || //rect.X + rect.Width < X //); //} public bool Intersects(FloatRectangle rect) { return(rect.X < this.X + this.Width && this.X < rect.X + rect.Width && rect.Y < this.Y + this.Height && this.Y < rect.Y + rect.Height); }
public GamePoleObject[] GetObjectsIntersectsRect(FloatRectangle rect) { return(cache.GetObjectsIntersectsRect(rect)); }