home *** CD-ROM | disk | FTP | other *** search
- /*
- opboxdist.c 8/24/88
-
- % ocbox_FindDist
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 12/13/88 jmd fixed overlappin boxes problem
- */
-
- #include "oakhead.h"
-
- int ocbox_FindDist(box1, box2, dir)
- ocbox *box1;
- ocbox *box2;
- int dir;
- /*
- Compute the distance from box1 to box2 in the
- given direction.
- returns ( <0 ) if the boxes are not on a line or
- if box2 is not in the specified direction.
- */
- {
- int dist = -1;
-
- switch(dir) {
- case OAK_UP:
- if (box1->leftcol <= box2->rightcol && box1->rightcol >= box2->leftcol) {
- if (box1->toprow >= box2->toprow) {
- dist = int_max(0, box1->toprow - box2->botrow);
- }
- }
- break;
- case OAK_DOWN:
- if (box1->leftcol <= box2->rightcol && box1->rightcol >= box2->leftcol) {
- if (box2->botrow >= box1->botrow) {
- dist = int_max(0, box2->toprow - box1->botrow);
- }
- }
- break;
- case OAK_LEFT:
- if (box1->toprow <= box2->botrow && box1->botrow >= box2->toprow) {
- if (box1->leftcol >= box2->leftcol) {
- dist = int_max(0, box1->leftcol - box2->rightcol);
- }
- }
- break;
- case OAK_RIGHT:
- if (box1->toprow <= box2->botrow && box1->botrow >= box2->toprow) {
- if (box2->rightcol >= box1->rightcol) {
- dist = int_max(0, box2->leftcol - box1->rightcol);
- }
- }
- break;
- default:
- break;
- }
-
- return(dist);
- }
-