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 dc (wx.DC) return 2-tuple (int, float): pixel size, actual size (meter) """ size = self.GetClientSize() maxWidth = max(5, size[0] - 3) maxActualWidth = maxWidth * self.mpp actualWidth = units.round_down_significant(maxActualWidth, self.significant) width = int(round(actualWidth / self.mpp)) return width, actualWidth
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, u"%f to %d figures = %f should be %f" % (i[0], i[1], o, eo))