"""Run the production lie-down footprint against controlled collision geometry.""" from pathlib import Path import subprocess import tempfile root = Path(__file__).resolve().parents[2] code = r''' #include "AdventureRestSpace.h" #include using namespace AdventureRestSpace; int main() { Spot p{0,0,10,0}; auto flat=[](float,float,float){return 10.0f;}; auto open=[](float,float,float,float,float,float){return true;}; auto empty=[](float,float,float){return false;}; assert(Clear(p,2,flat,open,empty)); auto platform=[](float,float y,float){return std::fabs(y)<1?10.0f:9.3f;}; auto slope=[](float,float y,float){return 10.0f-std::fabs(y)*0.5f;}; assert(Raised(p,platform));assert(!Raised(p,slope));assert(!Raised(p,flat)); // A chair can be non-colliding: native chair occupancy must still veto it. auto chair=[](float x,float y,float){return std::fabs(x-1.0f)<0.5f && std::fabs(y)<0.5f;}; assert(!Clear(p,2,flat,open,chair)); // Standing cylinder is clear; a wall at the sleeping body's foot is not. auto wall=[](float,float,float,float x,float,float){return x<1.5f;}; assert(!Clear(p,2,flat,wall,empty)); auto underTable=[](float,float,float z,float,float,float c){return !(z<10.7f && c>10.7f);}; assert(!Clear(p,2,flat,underTable,empty)); auto ledge=[](float x,float,float){return x>1?8.0f:10.0f;}; assert(!Clear(p,2,ledge,open,empty)); auto stairs=[](float x,float,float){return x>0.5f?10.3f:10.0f;}; assert(!Clear(p,2,stairs,open,empty)); auto missing=[](float,float,float){return -100000.0f;}; assert(!Clear(p,2,missing,open,empty)); auto nan=[](float,float,float){return NAN;}; assert(!Clear(p,2,nan,open,empty)); // Rotate the whole body into a corridor; the unrotated pose hits its wall. auto corridor=[](float,float,float,float x,float,float){return std::fabs(x)<0.8f;}; assert(!Clear(p,2,flat,corridor,empty));p.O=1.5707963f; assert(Clear(p,2,flat,corridor,empty)); // A larger model requires proportionally more space. assert(!Clear(p,4,flat,corridor,empty)); assert(BedName("Fancy Bed") && BedName("Hospital Bed") && BedName("Bedroll")); assert(!BedName("Flowerbed") && !BedName("Wooden Chair") && !BedName("Bedside Table")); } ''' with tempfile.TemporaryDirectory() as tmp: src=Path(tmp)/'space.cpp';src.write_text(code) exe=Path(tmp)/'space' subprocess.run(['g++','-std=c++17','-Wall','-Wextra','-Werror','-I'+str(root/'src/server/game/World'),str(src),'-o',str(exe)],check=True) subprocess.run([str(exe)],check=True) print('Sleep footprint: furniture, body extent, overhead collision, ledges, stairs, missing heights, rotation and scale passed.')