예제 #1
0
 def test_round_down_significant(self):
     #         (input) (expected output)
     values = [((1, 1), 1),
               ((-1.234, 1), -1),
               ((-1234, 1), -1000),
               ((1600, 1), 1000),
               ((-1600, 1), -1000),
               ((0.0001236, 3), 0.000123),
               ((0, 5), 0),
               ]
     for (i, eo) in values:
         o = units.round_down_significant(*i)
         self.assertEquals(o, eo,
                           "%f to %d figures = %f should be %f" % (i[0], i[1], o, eo))
예제 #2
0
 def GetLineWidth(self, dc):
     """
     Returns the size in pixel of the scale line and its actual size. 
     The pixel size is always less than the width of the window minus margin
     minus space for 8 characters
     dc (wx.DC)
     return 2-tuple (int, float): pixel size, actual size (meter) 
     """
     size = self.GetClientSize()
     maxWidth = size[0] - self.shift - dc.GetTextExtent(" 000mm")[0]
     maxWidth = max(1, maxWidth)
     maxActualWidth = maxWidth * self.mpp
     actualWidth = units.round_down_significant(maxActualWidth, self.significant)
     width = int(actualWidth / self.mpp)
     return (width, actualWidth)