//laser strategy comparator
//strategy 1
//  Multiple lasers can be on at a time, but a laser cannot show more than one point
//strategy 2
//  Only one laser can be on at a time, and a laser cannot show more than one point

num_lasers=240;
//generate random 3D points
minphigen=0.0458;//0.0458 for 240 pixels, 0.037399 for 126 pixels, 0.0432897 for 254 pixels
minz=sin(minphigen);
pts=rand(3,50);
pts(:,pts(3,:)<minz)=[];
pts(1:2,:)=pts(1:2,:)*2-1;
ds=sqrt(sum(pts.^2,1));
pts(:,ds>1|ds<1e-5)=[];
//scatter3(pts(1,:),pts(2,:),pts(3,:));
thetas=atan(pts(2,:),pts(1,:))+%pi;
phis=atan(pts(3,:),sqrt(sum(pts(1:2,:).^2,1)));

lss=[];
mss=[];
slos=[0,0];
smos=[0,0];
sbos=0;
merr=0;

for j=1:length(thetas)
   //Given a point at (t;p), find nearest quarter-point
    tp=[thetas(j);phis(j)];
    [qtp,laser,laseri,mirror_step,vres]=assignlaser(tp,num_lasers,laser_acceptance_angle_h);
    if(laser<0 || laser>=num_lasers)
        error('Laser assignment error theta');
    end
    if(abs(laseri)<1 || abs(laseri)>vres)
        error('Laser assignment error phi');
    end
    if(mirror_step<0)
        //disp("mirror step adjusted +");
        mirror_step=mirror_step+4*num_lasers;
    end
    if(mirror_step>=4*num_lasers)
        //disp("mirror step adjusted -");
        mirror_step=mirror_step-4*num_lasers;
    end
    
    if(sum(laser==lss)>0)
        slos(1)=slos(1)+1;
        slos(2)=max([slos(2),sum(laser==lss)]);
    end
    if(sum(mirror_step==mss)>0)
        smos(1)=smos(1)+1;
        smos(2)=max([smos(2),sum(mirror_step==mss)]);
        if(sum(laser==lss)>0)
            sbos=sbos+1;
        end
    end
    lss(j)=laser;
    mss(j)=mirror_step;
    
    tps=[tp,qtp];
    qtps=[cos(tps(1,:)).*cos(tps(2,:));sin(tps(1,:)).*cos(tps(2,:));sin(tps(2,:))];
    nm=norm(qtps(:,1)-qtps(:,2));
    if(nm>merr)
        merr=nm;
    end
end
mprintf("Actual max err with %i pts = %f\n",j,merr);
mprintf("Laser nums %i to %i ; Mirror nums %i to %i\n",min(lss),max(lss),min(mss),max(mss));
mprintf("Same-laser overlaps %i,%i ; Same-mirror overlaps %i,%i ; Both overlaps %i\n",slos(1),slos(2),smos(1),smos(2),sbos);
