public BinNode(PackingObject obj, BinNode parent, Rect rect) { this.nodes = new BinNode[2]; this.parent = parent; this.obj = obj; this.rect = rect; }
private bool Add(PackingObject obj, BinNode currNode) { if (currNode.obj != null) { if (Add(obj, currNode.nodes[0]) || Add(obj, currNode.nodes[1])) { return(true); } } else if (currNode.obj == null && currNode.CanPack(obj.rect)) { return(currNode.SetObject(obj, packType)); } return(false); }
public bool SetObject(PackingObject obj, PackType packType) { this.obj = obj; if (packType == PackType.LEFT_ALIGN) { this.nodes[0] = new BinNode(null, this, new Rect( rect.x + this.obj.rect.width , rect.y , rect.width - obj.rect.width , obj.rect.height )); this.nodes[1] = new BinNode(null, this, new Rect( rect.x , rect.y + this.obj.rect.height , rect.width , rect.height - obj.rect.height )); } else if (packType == PackType.RIGHT_ALIGN) { this.nodes[0] = new BinNode(null, this, new Rect( rect.x , rect.y , rect.width - obj.rect.width , obj.rect.height )); this.nodes[1] = new BinNode(null, this, new Rect( rect.x , rect.y + this.obj.rect.height , rect.width , rect.height - obj.rect.height )); this.rect.x = this.rect.x + this.rect.width - obj.rect.width; } return(true); }
private BinNode CreateNode(PackingObject obj, Rect rect) { return(new BinNode(obj, null, rect)); }