I create a room based on any Array with points. Objects that can be moved are added to the room. The goal is to block the possibility of moving the object out of the room.
When the object is moved, I check if all 4 bottom points belong to the floor - if so, you can move the object further - if not, it means that the object would go behind the wall, so you have to restore it to the previous position.
Prisoner849 user - gave in response an algorithm that checks if points are inside a polygon. It works great until I add rotation to the polygon - this solution does not work. Ultimately, orbitControls will be added to the cameras.
Just another idea is to use polybool.js (related topic [Closed] How to split/separate a single ShapeGeometry into individual Geometries base on faces?) to work with polygons: find intersection of the polygon of your floor and the polygon of your four point rectangle, if the result (its area or coordinates of vertices or amount of veriteces) is not the same as your original rectangle, then your rectangle is out of the floor.
Checking the points works perfectly, but it does not quite solve my stackowerflow problem.
the idea is that the green square (in the original will be different models) could not go beyond the lines. Any attempt to modify the cube.position ends badly.
Look at: https://codepen.io/jagodanat/pen/oORyLJ?editors=0000