; ---------------------------------------------------------------------- ; Compute fraction of a pixel is within given boundaries. ; pp1 is the lower real boundary position in pixel space. ; pp2 is the upper real boundary position in pixel space. ; rb1 is the real lower pixel edge (pixel-0.5). ; rb2 is the real upper pixel edge (pixel+0.5). ; (How much is rb1 to rb2 enclosed within pp1 to pp2 boundaries?) ; function nsx_boundary_fraction, pp1, pp2, rb1, rb2 if (rb1 gt pp2) then begin frac= 0.0 ; /* fully above */ endif else begin if (rb2 lt pp1) then begin frac= 0.0 ; /* fully below */ endif else begin if ((rb1 gt pp1)&&(rb2 lt pp2)) then begin frac= 1.0 ; /* fully enclosed */ endif else begin if ((rb1 lt pp1)&&(pp2 gt rb2)) then begin frac= (rb2 - pp1) ; /* pixel straddles lower boundary */ endif else begin if ((rb2 gt pp2)&&(pp1 lt rb1)) then begin frac= (pp2 - rb1) ; /* pixel straddles upper boundary */ endif else begin frac= (pp2 - pp1) ; /* boundaries must be within pixel */ endelse endelse endelse endelse endelse return,frac end