public PolygonsContainer(Vector2 bottomLeft, Vector2 topRight, PolygonsContainer parent) { var vertices = new Vector2 [4]; vertices[0] = bottomLeft; vertices[1] = new Vector2(bottomLeft.x, topRight.y); vertices[2] = topRight; vertices[3] = new Vector2(topRight.x, bottomLeft.y); rectBounds = new Polygon(vertices); Parent = parent; }
public void CreateChildren() { ChildContainers = new PolygonsContainer[4]; var minX = rectBounds.MinX; var minY = rectBounds.MinY; var maxX = rectBounds.MaxX; var maxY = rectBounds.MaxY; var halfX = minX + (maxX - minX) / 2; var halfY = minY + (maxY - minY) / 2; ChildContainers[0] = new PolygonsContainer(new Vector2(minX, minY), new Vector2(halfX, halfY), this); ChildContainers[1] = new PolygonsContainer(new Vector2(minX, halfY), new Vector2(halfX, maxY), this); ChildContainers[2] = new PolygonsContainer(new Vector2(halfX, minY), new Vector2(maxX, halfY), this); ChildContainers[3] = new PolygonsContainer(new Vector2(halfX, halfY), new Vector2(maxX, maxY), this); }