def vector pos, align, hash case hash[pos] when -1; [0.0, -1.0] when 1; [1.0, 0.0] else case hash[align] when -1; [0.0, 0.0] when 1; [1.0, -1.0] else [0.5, -0.5] end end end y_t, y_s = vector(pos, align, "top" => -1, "bottom" => 1) x_t, x_s = vector(pos, align, "left" => -1, "right" => 1) sy = ty + y_t*t.height + y_s*s.height sx = tx + x_t*t.width + x_s*s.width
or
def vector pos, align, head, tail case pos when head; [0.0, -1.0] when tail; [1.0, 0.0] else case align when head; [0.0, 0.0] when tail; [1.0, -1.0] else [0.5, -0.5] end end end y_t, y_s = vector(pos, align, "top", "bottom") x_t, x_s = vector(pos, align, "left", "right") sy = ty + y_t*t.height + y_s*s.height sx = tx + x_t*t.width + x_s*s.width
source share