dimanche 21 décembre 2014

How to represent a pattern within a Rectangle's area

I'm racking my brain trying to come up with a way to do this.


The goal is to have an object that represents a 2D collection of Boolean values.


Grid Problem


I have a point grid of Size(x, y)


Objects are placed on the grid at location Point(x, y) with bounds Rectangle(new Size(w, h), new Point(x, y))


The goal is to represent the object as a bool[,] where the index of the array location represent the offset in the Rectangles bounds.


I may be .. over thinking this a bit, so I'll explain that I used Rectangle because of the very handy IntersectsWith.


The objects will be allowed to move one unit in any direction, but they are not allowed to move to a location already occupied by another object.


I would like the end usage to be something like:



Pattern p1 = new Pattern(Point location1, bool[,] pattern);
Pattern p2 = new Pattern(Point location2, bool[,] pattern);

if(p1.Intersects(p2))
throw new ...


I only care of the patterns overlap. I'd like the general size and shape of the pattern to be mutable.


I'm trying to think of a way to redefine the pattern with certain rules based on total area.


I'm looking for advice on the best way to approach this problem.


Aucun commentaire:

Enregistrer un commentaire