'Split an object based on other intersecting objects

I'm trying to create a wall placement system a kin to Sims, and am having trouble figuring out how to split the wall if you put another wall perpendicular to it.

Players place a post and a post, and a wall is created in between 1

I store these 2 post vectors in a table, with the wall object being the key

self.Poles[Wall] = {
    Pole1 = pole1CFrame.Position,
    Pole2 = pole2CFrame.Position
}

However, placing a wall perpendicular, like so 2

Would mean I need to split the previous wall in half like here 3

As well as if they place the wall further in, so there's no post on the wall, it needs to know what walls needed to connected and what not like here 4

I'm unsure if placing the walls in a table is necessary.
Maybe if I just stored like 1 post in the table, and have it's value be the second post?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source