Move piston code to shared location in math.