
export function executeRotatedWithCaret(d,p,l,u,f,ox,oy,oz){
	const r=Math.PI/180,g=d.location,R=d.getRotation(),y=R.y*r,pv=p*r,sy=Math.sin(y),cy=Math.cos(y),sp=Math.sin(pv),cp=Math.cos(pv),fx=-sy*cp,fy=-sp,fz=cy*cp,rx=cy,rz=sy,ux=-rz*fy,uy=rz*fx-rx*fz,uz=rx*fy,X=g.x+ox+f*fx+l*rx-u*ux,Y=g.y+oy+f*fy-u*uy,Z=g.z+oz+f*fz+l*rz-u*uz;return{x:Math.round(X*100)/100,y:Math.round(Y*100)/100,z:Math.round(Z*100)/100};
};
export const lerp = (a,b,t)=>a+(b-a)*t;
export function pickWeightedOutcome(list) {
    let total = 0;
    for (const o of list) total += o.weight;
    const r = Math.random() * total;
    let sum = 0;
    for (const o of list) {
        sum += o.weight;
        if (r <= sum) return o;
    }
    return list[list.length-1];
};
export const randomInteger = (min,max)=>Math.floor(Math.random()*(max-min+1))+min;
export function resolvedRandomisedState(stateObj) {
	if (!stateObj) return undefined;
	const out = {};
	for (const [key,val] of Object.entries(stateObj)) {
		if (typeof val === "object" && val.min !== undefined && val.max !== undefined) {
			out[key] = randomInteger(val.min,val.max);
		}
		else {
			out[key] = val;
		}
	}
	return out;
};
export function wrapDegrees(angle) {
	return ((angle+180)%360+360)%360-180;
};