Habitat structure mediates spatial segregation and therefore coexistence