As you might imagine, it is possible to consider this as a purely mathematical problem and to thereby come up with measures of gerrymandered-ness. It is a widely studied field. e.g.:
https://digital.lib.washington.edu/researchworks/bitstream/h...
https://www.researchgate.net/profile/Matthew_Dube/publicatio...