MCPcopy Create free account
hub / github.com/ActiveState/code / mapper

Class mapper

recipes/Python/578875_Analog_Clock/recipe-578875.py:45–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43# to viewport coordinates.
44#
45class mapper:
46 ## Constructor.
47 #
48 # @param world window rectangle.
49 # @param viewport screen rectangle.
50 #
51 def __init__(self, world, viewport):
52 self.world = world
53 self.viewport = viewport
54 x_min, y_min, x_max, y_max = self.world
55 X_min, Y_min, X_max, Y_max = self.viewport
56 f_x = float(X_max-X_min) / float(x_max-x_min)
57 f_y = float(Y_max-Y_min) / float(y_max-y_min)
58 self.f = min(f_x,f_y)
59 x_c = 0.5 * (x_min + x_max)
60 y_c = 0.5 * (y_min + y_max)
61 X_c = 0.5 * (X_min + X_max)
62 Y_c = 0.5 * (Y_min + Y_max)
63 self.c_1 = X_c - self.f * x_c
64 self.c_2 = Y_c - self.f * y_c
65
66 ## Maps a single point from world coordinates to viewport (screen) coordinates.
67 #
68 # @param x, y given point.
69 # @return a new point in screen coordinates.
70 #
71 def __windowToViewport(self, x, y):
72 X = self.f * x + self.c_1
73 Y = self.f * -y + self.c_2 # Y axis is upside down
74 return X , Y
75
76 ## Maps two points from world coordinates to viewport (screen) coordinates.
77 #
78 # @param x1, y1 first point.
79 # @param x2, y2 second point.
80 # @return two new points in screen coordinates.
81 #
82 def windowToViewport(self,x1,y1,x2,y2):
83 return self.__windowToViewport(x1,y1),self.__windowToViewport(x2,y2)
84
85## Class for creating a new thread.
86#

Callers 3

map_reduceFunction · 0.85
__init__Method · 0.85
resizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected