Exemple #1
0
def getRotatedRectanglePoints(angle, base_point, height, width):
    # base_point is the upper left (ul)
    ur = point.Point(width * math.cos(angle), -width * math.sin(angle))
    lr = point.Point(ur.x + height * math.sin(angle),
                     ur.y + height * math.cos(angle))
    ll = point.Point(height * math.cos(math.pi / 2 - angle),
                     height * math.sin(math.pi / 2 - angle))
    return tuple(base_point + pt for pt in (point.Point(0, 0), ur, lr, ll))
Exemple #2
0
 def testGetBounds(self):
     points = [
         point.Point(0, 0),
         point.Point(1, 0),
         point.Point(0, 1),
         point.Point(1, 1)
     ]
     correct = util.Bound(0, 0, 1, 1)
     self.assertNamedTupleAlmostEqual(correct, util.getBounds(points))
Exemple #3
0
 def testGetRotatedRectanglePoints(self):
     """Rotate a unit square by 45 degrees"""
     m = math.sqrt(2) / 2
     correct = (point.Point(0, 0), point.Point(m,
                                               -m), point.Point(2 * m, 0),
                point.Point(m, m))
     results = util.getRotatedRectanglePoints(math.pi / 4,
                                              point.Point(0, 0), 1, 1)
     for points in zip(correct, results):
         self.assertPointEqual(*points)
Exemple #4
0
def getCenter(im):
    return point.Point(*(d / 2 for d in im.size))
Exemple #5
0
def getBoundsCenter(bounds):
    return point.Point((bounds.right - bounds.left) / 2 + bounds.left,
                       (bounds.lower - bounds.upper) / 2 + bounds.upper)
Exemple #6
0
 def testGetBoundsCenter(self):
     self.assertPointEqual(point.Point(.5, 1),
                           util.getBoundsCenter(util.Bound(0, 0, 1, 2)))
Exemple #7
0
 def testGetCenter(self):
     im = mock.Mock()
     im.size = (23, 82)
     self.assertPointEqual(point.Point(11.5, 41), util.getCenter(im))
Exemple #8
0
 def testAdd(self):
     self.assertPointEqual(point.Point(2, 3),
                           point.Point(1, 1) + point.Point(1, 2))
Exemple #9
0
 def testRotate90Degrees(self):
     p = point.Point(1, 0)
     center = point.Point(0, 0)
     result = point.Point(0, 1)
     self.assertPointEqual(result, p.rotate(center, math.pi / 2))
Exemple #10
0
 def testRecenter(self):
     p = point.Point(1, 1)
     old_center = point.Point(0, 0)
     new_center = point.Point(1, 1)
     result = point.Point(2, 2)
     self.assertPointEqual(result, p.recenter(old_center, new_center))
Exemple #11
0
 def testSubtract(self):
     self.assertPointEqual(point.Point(1, 0),
                           point.Point(2, 1) - point.Point(1, 1))