Factored out geometry functions.