getRayLength computes the distance to the container boundary from (offsetPosX, offsetPosY). It should use (offsetPosX + offsetAnchorX, offsetPosY + offsetAnchorY).