Factor out common plane hit testing code