Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061extension TileTree { public func balancedSplits() -> TileTree { fold( { stack in (tree: TileTree.tile(stack), count: 1) }, { node, first, second in let count = first.count + second.count let axis: Axis switch node { case .tile: preconditionFailure("A branch must have children") case .split(let value, _, _, _), .partition(let value, _, _, _): axis = value } return ( node.transformingNode( axis: axis, fraction: Double(first.count) / Double(count), first: first.tree, second: second.tree), count ) } ).tree }
public func rotatedClockwise() -> TileTree { fold( { .tile($0) }, { node, first, second in switch node { case .tile: preconditionFailure("A branch must have children") case .split(let axis, let fraction, _, _), .partition(let axis, let fraction, _, _): if axis == .horizontal { return node.transformingNode(axis: .vertical, fraction: fraction, first: first, second: second) } return node.transformingNode( axis: .horizontal, fraction: 1 - fraction, first: second, second: first) } }) }
public func mirrored(along mirrorAxis: Axis) -> TileTree { fold( { .tile($0) }, { node, first, second in switch node { case .tile: preconditionFailure("A branch must have children") case .split(let axis, let fraction, _, _), .partition(let axis, let fraction, _, _): if axis == mirrorAxis { return node.transformingNode(axis: axis, fraction: 1 - fraction, first: second, second: first) } return node.transformingNode(axis: axis, fraction: fraction, first: first, second: second) } }) }
private func transformingNode(axis: Axis, fraction: Double, first: TileTree, second: TileTree) -> TileTree { switch self { case .tile: return self case .split: return .split(axis: axis, fraction: fraction, first: first, second: second) case .partition: return .partition(axis: axis, fraction: fraction, first: first, second: second) } }}