def get_pos(self, pos): def is_left_of(point, line): ax = point[0] - line[0][0] ay = point[1] - line[0][1] bx = line[1][0] - line[0][0] by = line[1][1] - line[0][1] if ax * by - bx * ay > 0: return True return False x, y = pos tw, th = self.pixelsize * 3 / 4, self.pixelsize tx, ty = x / tw, y / th ttx, tty = x - tx * tw, y - ty * th if tx % 2 == 0: if is_left_of((ttx, tty), ((0, th / 2), (tw / 3, 0))): tx -= 1; ty -= 1 elif is_left_of((ttx, tty), ((tw / 3, th), (0, th / 2))): tx -= 1 else: if tty < th / 2: if is_left_of((ttx, tty), ((tw / 3, th / 2), (0, 0))): tx -= 1 else: ty -= 1 else: if is_left_of((ttx, tty), ((0, th), (tw / 3, th / 2))): tx -= 1 return tx, ty