some geometry work, and separated out the python threshold thing even though it's not fast enough to use