(coord, fromDim, toDim int)
| 149 | } |
| 150 | |
| 151 | func scaleDesktopCoordinate(coord, fromDim, toDim int) int { |
| 152 | if toDim <= 0 { |
| 153 | return 0 |
| 154 | } |
| 155 | if fromDim <= 0 || fromDim == toDim { |
| 156 | return clampDesktopCoordinate(coord, toDim) |
| 157 | } |
| 158 | |
| 159 | scaled := (float64(coord)+0.5)*float64(toDim)/float64(fromDim) - 0.5 |
| 160 | scaled = math.Max(scaled, 0) |
| 161 | scaled = math.Min(scaled, float64(toDim-1)) |
| 162 | return int(math.Round(scaled)) |
| 163 | } |
| 164 | |
| 165 | func clampDesktopCoordinate(coord, dim int) int { |
| 166 | if dim <= 0 { |
no test coverage detected