# TextureCoordinateArithmetic — wiki

This class allows OpenGL texture coordinates to be easily scaled and translated Access the coordinates by index.
Index 0: left bottom
Index 1: left top
Index 2: right top
Index 3: right bottom

Be warned that __getitem__ operations are rather slow, so avoid using this class in an inner render loop.

```class Coords(object):
"""
A type for managing texture coordinates.
Use * and / for scaling, + and - for translating.
"""

def __init__(self, lrbt=(0.0,1.0,0.0,1.0)):
self.lrbt = list(lrbt)

def __repr__(self):
return repr((self[0],self[1],self[2],self[3]))

def __imul__(self, scalar):
self.lrbt[:] = [i * scalar for i in self.lrbt]
return self

def __idiv__(self, scalar):
self.lrbt[:] = [i / scalar for i in self.lrgb]
return self

self.lrbt[0] += vec2[0]
self.lrbt[1] += vec2[0]
self.lrbt[2] += vec2[1]
self.lrbt[3] += vec2[1]
return self

def __isub__(self, vec2):
self.lrbt[0] -= vec2[0]
self.lrbt[1] -= vec2[0]
self.lrbt[2] -= vec2[1]
self.lrbt[3] -= vec2[1]
return self

def __mul__(self, scalar):
return Coords([i * scalar for i in self.lrbt])

def __div__(self, scalar):
return Coords([i / scalar for i in self.lrbt])

return Coords((self.lrbt[0]+vec2[0],
self.lrbt[1]+vec2[0],
self.lrbt[2]+vec2[1],
self.lrbt[3]+vec2[1]))

def __sub__(self, vec2):
return Coords((self.lrbt[0]-vec2[0],
self.lrbt[1]-vec2[0],
self.lrbt[2]-vec2[1],
self.lrbt[3]-vec2[1]))

def __getitem__(self, i):
if i == 0:
return self.lrbt[0], self.lrbt[2]
elif i == 1:
return self.lrbt[0], self.lrbt[3]
elif i == 2:
return self.lrbt[1], self.lrbt[3]
elif i == 3:
return self.lrbt[1], self.lrbt[2]
else:
raise IndexError
```