code: def t_seg(p1, p2, t, align=0):
      
      v = vector(p1, p2)
      result = {
          1: lambda a, b: (a, translate(b, scale(v, -t))),
          2: lambda a, b: (translate(a, scale(v, t)), b),
          0: lambda a, b: (translate(a, scale(v, t / 2)),
                           translate(b, scale(v, -t / 2)))
      }
      return result[align](p1, p2)
docs: trim segment
      Args:
        p1, p2: point(x, y)
        t: scaling factor (1 - trimed segment / original segment)
        align: 1: trim p2, 2: trim p1, 0: both side
      Return:
        trimmed segment(p1, p2)