First attempt at removing duplicated code

I've created _applyBoundaryConstraints() and _fitBounds() to remove
duplicated code.
adding demo to show benefit of fitBoundsWithConstraints