I was just surprised that it matters
which notes are selected.
My expectation of "contrast" operations was something like you calculate the average velocity of all selected notes, then determine which ones values to increase or decrease and apply that incrementally by this operation up to the average value or the upper(127)/lower(0) bound.
Looking at it a bit more "complex" it's a kind of curve adjustment - like some midi filters or imaging programs offer with curves - here applied to midi velocity values.
Probably my main "problem" is
I don't understand what you are really doing here and some explanation would help.