scale or nativescale? which one to use when you want to round to the nearest pixel?

I am trying to draw a grid inside a SwiftUI view. I am using Path with 'move(to' 'addLine(to' etc. I am trying to adjust the position of the lines to the nearest pixel to avoid anti-aliasing. At first I had a plan line this.

Code Block Swift
        let positionX: CGFloat = start.x
        let scaleFactor = UIScreen.main.scale
        let posInPixels = positionX * scaleFactor
        let posRoundedToNearestHalfPixel = Int(round(posInPixels * 2))        
        let adjustByHalfpixel: Bool
        if posRoundedToNearestHalfPixel.isMultiple(of: 2) {
            /*that means we have a whole number of pixels, which means we are between pixels so add half a pixel*/
            adjustByHalfpixel = true
        } else {
            /*we have a postion that is already on a pixel so no need to adjust*/
            adjustByHalfpixel = false
        }
        let finalValueInWholePixels = CGFloat(posRoundedToNearestHalfPixel + (adjustByHalfpixel ? 1 : 0))/CGFloat(2)
        let finalAdjjustedValueInPoints = finalValueInWholePixels / scaleFactor

What I am not sure about is the scale factor
Should I use UIScreen.main.scale or UIScreen.main.nativescale ?

It is not clear from the documentation what the difference is between those two?




scale or nativescale? which one to use when you want to round to the nearest pixel?
 
 
Q