Last active
December 25, 2021 17:19
-
-
Save tomasen/4ef4c6da4ac998711b765c1995c1c4a6 to your computer and use it in GitHub Desktop.
WordCloudStateCache for WordCloudView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var positionCache = WordCloudPositionCache() | |
func calcPositions(canvasSize: CGSize, itemSizes: [CGSize]) -> [CGPoint] { | |
var pos = [CGPoint](repeating: CGPoint.zero, count: itemSizes.count) | |
if canvasSize.height == 0 { | |
return pos | |
} | |
if positionCache.canvasSize == canvasSize { | |
return positionCache.positions | |
} | |
defer { | |
positionCache.canvasSize = canvasSize | |
positionCache.wordSizes = wordSizes | |
positionCache.positions = pos | |
}} | |
// ... | |
} | |
class WordCloudPositionCache { | |
var canvasSize = CGSize.zero | |
var wordSizes = [CGSize]() | |
var positions = [CGPoint]() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment