예제 #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))
예제 #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))
예제 #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)
예제 #4
0
def getCenter(im):
    return point.Point(*(d / 2 for d in im.size))
예제 #5
0
def getBoundsCenter(bounds):
    return point.Point((bounds.right - bounds.left) / 2 + bounds.left,
                       (bounds.lower - bounds.upper) / 2 + bounds.upper)
예제 #6
0
 def testGetBoundsCenter(self):
     self.assertPointEqual(point.Point(.5, 1),
                           util.getBoundsCenter(util.Bound(0, 0, 1, 2)))
예제 #7
0
 def testGetCenter(self):
     im = mock.Mock()
     im.size = (23, 82)
     self.assertPointEqual(point.Point(11.5, 41), util.getCenter(im))
예제 #8
0
 def testAdd(self):
     self.assertPointEqual(point.Point(2, 3),
                           point.Point(1, 1) + point.Point(1, 2))
예제 #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))
예제 #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))
예제 #11
0
 def testSubtract(self):
     self.assertPointEqual(point.Point(1, 0),
                           point.Point(2, 1) - point.Point(1, 1))