home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / OBOXDIST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  1.4 KB  |  65 lines

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