Skip to content

Instantly share code, notes, and snippets.

@tomasen
Created December 25, 2021 17:19
Show Gist options
  • Save tomasen/263f153084cd5c82b903be3cd7593f0f to your computer and use it in GitHub Desktop.
Save tomasen/263f153084cd5c82b903be3cd7593f0f to your computer and use it in GitHub Desktop.
simularWordSizes for WordCloudView
func simularWordSizes(a: [CGSize], b: [CGSize]) -> Bool {
if a == b {
return true
}
if a.count != b.count {
return false
}
var diff : CGFloat = 0
for i in 0...(a.count-1) {
diff += abs(a[i].width - b[i].width) +
abs(a[i].height - b[i].height)
}
return diff < 0.01
}
func calcPositions(canvasSize: CGSize, itemSizes: [CGSize]) -> [CGPoint] {
// ...
if positionCache.canvasSize == canvasSize
&& simularWordSizes(a: positionCache.wordSizes, b: wordSizes) {
return positionCache.positions
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment