MCPcopy Create free account
hub / github.com/PageBot/PageBot / getTransformed

Method getTransformed

Lib/pagebot/contexts/flatcontext/flatcontext.py:371–415  ·  view source on GitHub ↗

Takes a point and puts it through the transformation matrix, handling translation, rotation and scaling at once. >>> context = FlatContext() >>> w = 800 >>> h = 600 >>> dx = 6 >>> dy = 8 >>> context.newPage(w, h) >>> x, y = 4, 5

(self, x, y, z=0)

Source from the content-addressed store, hash-verified

369 height = property(_get_height)
370
371 def getTransformed(self, x, y, z=0):
372 """Takes a point and puts it through the transformation matrix,
373 handling translation, rotation and scaling at once.
374
375 >>> context = FlatContext()
376 >>> w = 800
377 >>> h = 600
378 >>> dx = 6
379 >>> dy = 8
380 >>> context.newPage(w, h)
381 >>> x, y = 4, 5
382 >>> p1 = context.getTransformed(x, y)
383 >>> p1
384 (4.0, 595.0)
385 >>> context.translate(dx, dy)
386 >>> p1 = context.getTransformed(x, y)
387 >>> p1
388 (10.0, 587.0)
389 >>> p1[0] == 4 + dx
390 True
391 >>> p1[1] == h - (dy + 5)
392 True
393 >>> context.scale(2)
394 >>> p2 = context.getTransformed(x, y)
395 >>> p2[0] == (4 * 2) + dx
396 True
397 >>> p2[1] == h - ((5 * 2) + dy)
398 True
399 >>> p2
400 (14.0, 582.0)
401 """
402 p0 = (x, y, z)
403 p1 = self.transform3D.transformPoint(p0)
404 x1, y1, _ = p1
405
406 # Makes sure the page height has been initiated.
407 assert self.height
408
409 '''Because the origin is at the bottom, like in DrawBot and as opposed
410 to Flat, we need to subtract all vertical coordinates from the page
411 height before an object gets placed. In case of (bounding) boxes, we
412 also need to subtract the box height.'''
413
414 y1 = self.height - y1
415 return upt(x1, y1)
416
417 # S T A T E
418

Callers 7

getGlyphPathMethod · 0.95
textMethod · 0.95
rectMethod · 0.95
ovalMethod · 0.95
circleMethod · 0.95
lineMethod · 0.95
polygonMethod · 0.95

Calls 2

uptFunction · 0.90
transformPointMethod · 0.80

Tested by

no test coverage detected