Calculating Pivot Point for Building System

Hello, I’m working on a building system and am trying to figure out how to calculate which position would be used for a pivot point when rotating the object clockwise, and which pivot point would be used for rotating counter clockwise. The idea is to move a pivot point to a grid point, depending on which direction the player rotates the structure. I’ve captured a few screenshots, that hopefully capture what I’m trying to achieve.