Point in polygon

I am trying to predict points that lie on a 2D Cartesian map constrained by a floor-plan which contains rooms of arbitrary shapes. I am currently calculating l2-distance to the bounding-box around a room as a loss (since I only need to consider the four sides), however I would prefer to more precisely penalise the model especially for non-rectangular rooms.

Is anyone aware of a point-in-polygon loss I could use to train my model?

Some methods I have considered (but have not worked well are):

  1. Generating many points and training an MLP to know whether the point belongs to the room or not, then using this as a loss-term; however this is very slow
  2. Precomputing the closest-distance on the exterior of the room and using L2-distance to that when training, and masking out the loss if inside, however then there is no gradient information when inside and the point can jump outside