refactored spatialcontraint and added unit testing