Geometric constrained variational calculus I: Piecewise smooth extremals