Gradient Refactoring

This is a refactoring I started while on a train. Basically because I saw some repetition and really complex methods.

* improved naming
* extracted a repeated method
* got rid of a block, replaced it with a method and call it at a single place instead of every if branch
* removed some confusing `width, height = height, width` swap

This could be merged but there are some parts where I feel like gathering feedback/help:

* There are quite many variables being juggled around. Maybe some of them should form an object of their own or there should be a method object somewhere?
* I really don't know what happens in calculate_x_and_y and all the math stuff that is going on, or rather why that is happening. Does anyone know? Otherwise I'd have to have a deeper look at how gradient works and what it does exactly.

Cheers,
Tobi