How to represent a pattern in a rectangle area

The goal is to have an object that represents a two-dimensional collection of boolean values.

Grid problem

I have a grid of points of size (x, y)

Objects are placed on the grid at Point (x, y) with Rectangle boundaries (new dimension (w, h), new point (x, y))

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

Maybe I thought about it a bit, so I'll explain that I used Rectangle because of the very handy IntersectsWith.

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 use 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 like pattern matching. I would like the overall size and shape of the template to change.

I am trying to come up with a way to override a template with specific rules based on total area.

I am looking for advice on the best way to solve this problem.

+3


source to share


2 answers


You can try treemap. Sort the rectangles and place the first one in the 2d tree. Divide the tree along both axes and place the next rectangle where it fits. Rinse and repeat.



+1


source


I decided to go with a simple Points list. I feel like I may have thought too much about this. Each feature has a list of points, a method to determine if the newly added point is an adjacent existing point, and a method to determine if the point belongs to the feature.

This is a quasi-proxy pattern, the root object contains a list of many helper objects, the sub-objects ask the root object for points to be available, the root object requests all the sub-objects.



This should, some of them, help support SOLID / SRP.

0


source







All Articles