1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

mkicon.py: Use Python 3's true division mode.

In Python 2, x/y means floor division if both x and y are ints, and true
division otherwise: that is, 1/2 == 0.  In Python 3, x/y always means
true division even if both x and y are ints, so 1/2 == 0.5.

To prepare for porting to Python 3, change all the places that relied on
floor division to use the more explicit // operator, and use "from
__future__ import division" to change the / operator to use Python 3's
semantics even in Python 2.  Both of these features have been available
since Python 2.2.
This commit is contained in:
Colin Watson 2019-08-30 13:40:28 +01:00 committed by Simon Tatham
parent 40a4c6e06c
commit a88eb54312

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python
from __future__ import division
import math
# Python code which draws the PuTTY icon components at a range of
@ -244,8 +246,8 @@ def monitor(size):
if x >= surround and y >= surround and \
x < surround+swidth and y < surround+sheight:
# Screen.
sx = (float(x-surround) - swidth/3) / swidth
sy = (float(y-surround) - sheight/3) / sheight
sx = (float(x-surround) - swidth//3) / swidth
sy = (float(y-surround) - sheight//3) / sheight
shighlight = 1.0 - (sx*sx+sy*sy)*0.27
pix = bluepix(shighlight)
if x < surround+shadow or y < surround+shadow:
@ -400,8 +402,8 @@ def document(size):
# Decide where this line of text begins.
if line == 0:
start = round(4*size)
elif line < 5*nlines/7:
start = round((line - (nlines/7)) * size)
elif line < 5*nlines//7:
start = round((line - (nlines//7)) * size)
else:
start = round(1*size)
if start < round(1*size):
@ -845,7 +847,7 @@ def pageant_icon(size):
# Determine the relative y-coordinates of the computer and hat.
# We just centre the one on the other.
xrel = (cbb[0]+cbb[2]-hbb[0]-hbb[2])/2
xrel = (cbb[0]+cbb[2]-hbb[0]-hbb[2])//2
# Determine the relative y-coordinates of the computer and hat.
# We do this by sitting the hat as low down on the computer as
@ -1086,7 +1088,7 @@ else:
def halftone(col1, col2):
r1,g1,b1,a1 = col1
r2,g2,b2,a2 = col2
colret = (int(r1+r2)/2, int(g1+g2)/2, int(b1+b2)/2, int(a1+a2)/2)
colret = (int(r1+r2)//2, int(g1+g2)//2, int(b1+b2)//2, int(a1+a2)//2)
return (colret, colret)
if test: