
CD-Section: Determine Spatial Overlap Between Two Spots
C These routines are to determine whether two spots are spatially 
C overlapped. The elliptical LDM spot shapes are used and two different
C methods are available.
CD-end

C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LRL_OVQ          **
C**************************
C
CD-Routine: Determine Spot Ellipse Overlap (analytical) - LRL_OVQ
C This routine determines whether two elliptical spots, with or without
C a background border, overlap using an anlytical procedure. The
C routine makes the approximation that the two ellipses are the
C same size and have the same orientation (reasonable as close
C spots are being considered).
CD-end
CD-Fortran:
      LOGICAL FUNCTION LRL_OVQ (SPOT_L, SPOT_W, SPOTFAC, SPOT_B, CTOF,
     +                          RASTOMM, X1, Y1, X2, Y2, ITYP)
CD-end
      INCLUDE 'implicit_none.finc'
C
C Purpose: Determine if two elliptical reflection masks overlap using
C          analytical procedure. 
C
C          Note: Makes approximations that the two ellipses are the
C                same size and orientation (reasonable as close
C                spots are being considered)
C
C Author:  Quan Hao, John W. Campbell, July 1993
C
C Return:  .TRUE. if spots overlap, otherwise .FALSE.
C
C Arguments:
C
      REAL SPOT_L
      REAL SPOT_W
      REAL SPOTFAC
      REAL SPOT_B
      REAL CTOF
      REAL RASTOMM
      REAL X1
      REAL Y1
      REAL X2
      REAL Y2
      INTEGER ITYP
CD-Parameters:   
C SPOT_L    r (R)  Spot length in mm.
C SPOT_W    r (R)  Spot width in mm.
C SPOTFAC   r (R)  Spot expansion factor
C SPOT_B    r (R)  Background border width in rasters
C CTOF      r (R)  Crystal to plate distance in mm.
C RASTOMM   r (R)  Conversion factor rasters to mm (x)
C X1        r (R)  'x' position of reference spot in mm. 
C Y1        r (R)  'y' position of reference spot in mm.
C X2        r (R)  'x' position of second spot in mm.
C Y2        r (R)  'y' position of second spot in mm.
C ITYP      i (R)  Flag = 1, Check that (spot + unused pixel + background 
C                            border) does not overlap with next spot 
C                       = 2, Check that (spot + background border) does not    
C                            overlap with next spot
C                       = 3, Check overlap strictly for spot area
C
C           Return is .TRUE. if spots overlap, otherwise .FALSE.
C
CD-end
C
C====== LOCALS:
C
      REAL CMASK
      REAL RADIUS
      REAL AMAJOR
      REAL BMINOR
      REAL CTH, STH
      REAL EXTRA
      REAL PI
      REAL XO
      REAL YO
      REAL XO2
      REAL YO2
      REAL A2
      REAL B2
      REAL CC
      REAL QTEST

      DATA PI/3.1415927/
C
C-------------------------------------------------------------------------------
C
      LRL_OVQ = .FALSE.
      CMASK = SPOT_L/2.0
      RADIUS = SQRT(X1*X1+Y1*Y1)
      AMAJOR = CMASK*(1.0+SPOTFAC*RADIUS/CTOF)
      BMINOR = SPOT_W/2.0
      EXTRA = 0.0
      IF (ITYP.EQ.1) THEN
         EXTRA = RASTOMM*(1.0 + SPOT_B)/2.0
      ELSE IF (ITYP.EQ.2) THEN
         EXTRA = RASTOMM*SPOT_B/2.0
      END IF
      CTH = X1/RADIUS
      STH = Y1/RADIUS
      XO = (X2-X1)*CTH + (Y2-Y1)*STH
      YO = (Y2-Y1)*CTH - (X2-X1)*STH
      AMAJOR = AMAJOR + EXTRA
      BMINOR = BMINOR + EXTRA
      A2 = AMAJOR*AMAJOR
      B2 = BMINOR*BMINOR
      XO2 = XO*XO
      YO2 = YO*YO
      CC = (B2*XO2 + A2*YO2)
      CC = CC*CC/(4.0*B2)
      QTEST = A2*B2*XO2 + A2*A2*YO2 - CC
      IF (QTEST.GT.0.0) LRL_OVQ = .TRUE.
      RETURN
      END
