// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Closest point on or inside an aligned box // Not compiled or tested in-world // Setup: Use a spare owned prim. Set POINT, CENTER and positive SIZE. Touch for owner-only calculation output. // Stop / restore: Remove/disable. Does not sense, collide with, or modify actual objects. // Notes: A point already inside returns itself; this is nearest point in the solid box, not necessarily on its surface. // License: see LICENSE in this distribution. // Original Incoprea. MIT. Ideal geometry only. vector POINT=<5.0,1.0,-3.0>; vector CENTER=ZERO_VECTOR; vector SIZE=<4.0,4.0,4.0>; default { touch_start(integer detectedCount) { if(llDetectedKey(0)!=llGetOwner())return; if(SIZE.x<=0.0||SIZE.y<=0.0||SIZE.z<=0.0) { llOwnerSay("Positive sizes required."); return; } vector low=CENTER-SIZE*0.5; vector high=CENTER+SIZE*0.5; vector q=POINT; if(q.xhigh.x)q.x=high.x; if(q.yhigh.y)q.y=high.y; if(q.zhigh.z)q.z=high.z; llOwnerSay("Closest="+(string)q+" distance="+(string)llVecDist(POINT,q)); } }