Unified Framework for the analysis of grazing and border-collisions in piecewise-smooth systems