home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / CSCAP323.ZIP / OWLSRC.EXE / OBOXDIST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-28  |  1.4 KB  |  63 lines

  1. /*
  2.     opboxdist.c    8/24/88
  3.  
  4.     % ocbox_FindDist
  5.  
  6.     OWL 1.2
  7.     Copyright (c) 1988, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.     12/13/88 jmd    fixed overlappin boxes problem
  13.      3/28/90 jmd    ansi-fied
  14. */
  15.  
  16. #include "oakhead.h"
  17.  
  18. int ocbox_FindDist(ocbox *box1, ocbox *box2, int dir)
  19. /*
  20.     Compute the distance from box1 to box2 in the
  21.     given direction.
  22.     returns ( <0 ) if the boxes are not on a line or
  23.     if box2 is not in the specified direction.
  24. */
  25. {
  26.     int dist = -1;
  27.  
  28.     switch(dir) {
  29.     case OAK_UP:
  30.         if (box1->leftcol <= box2->rightcol && box1->rightcol >= box2->leftcol) {
  31.             if (box1->toprow >= box2->toprow) {
  32.                 dist = int_max(0, box1->toprow - box2->botrow);
  33.             }
  34.         }
  35.         break;
  36.     case OAK_DOWN:
  37.         if (box1->leftcol <= box2->rightcol && box1->rightcol >= box2->leftcol) {
  38.             if (box2->botrow >= box1->botrow) {
  39.                 dist = int_max(0, box2->toprow - box1->botrow);
  40.             }
  41.         }
  42.         break;
  43.     case OAK_LEFT:
  44.         if (box1->toprow <= box2->botrow && box1->botrow >= box2->toprow) {
  45.             if (box1->leftcol >= box2->leftcol) {
  46.                 dist = int_max(0, box1->leftcol - box2->rightcol);
  47.             }
  48.         }
  49.         break;    
  50.     case OAK_RIGHT:
  51.         if (box1->toprow <= box2->botrow && box1->botrow >= box2->toprow) {
  52.             if (box2->rightcol >= box1->rightcol) {
  53.                 dist = int_max(0, box2->leftcol - box1->rightcol);
  54.             }
  55.         }
  56.         break;
  57.     default:
  58.         break;    
  59.     }
  60.  
  61.     return(dist);
  62. }
  63.