I have n number of files on a ScrollView. Every time a file is added, x/y coordinates are stored in an array. The user is able to drag and drop the files anywhere they like. Overlapping files (e.g. distance between center less than 100 points) will form a stack, see screenshot.
At the moment, my implementation is not good. I don't come from a computer science background, so I was wondering which algorithm I should take a look at to improve the performance of this function.
var stacksSet: Set<Controller.File.View> = .init()
for fileView in fileViews {
for compareTo in fileViews {
comparisons += 1
if fileView == compareTo { continue }
let pointA = fileView.file.relativePosition
let pointB = compareTo.file.relativePosition
let distance = hypotf(Float(pointA.x - pointB.x), Float(pointA.y - pointB.y)) * Float(zoomViewSize.width)
if distance < 100 {
stacksSet.insert(fileView)
stacksSet.insert(compareTo)
}
}
}
set
in your code. Does the order of insertion matter in this question? If you want to "improve the performance of this function" since your "implementation is not good", do you mean the number of files can be too many for your implementation to be responsive enough? Can a user drag and drop many files at the same time? $\endgroup$