Limit cycles in piecewise polynomial Hamiltonian systems allowing nonlinear switching boundaries