home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 21
/
macformat_21.iso
/
Shareware
/
Programación
/
VideoToolbox
/
VideoToolboxSources
/
CenterRectInRect.c
< prev
next >
Wrap
Text File
|
1995-06-18
|
2KB
|
79 lines
/*
CenterRectInRect.c
©1991-1995 Denis G. Pelli
These routines are trivial, but enhance the readability of programs that use them.
HISTORY:
8/24/91 dgp Made compatible with THINK C 5.0.
1/25/93 dgp removed obsolete support for THINK C 4.
11/22/94 dgp renamed "RectInRect" to IsRectInRect().
5/31/95 dgp added ExpandRect, ExpandAndOffsetRect, and ShrinkRect.
6/17/95 dgp rewrote ShrinkRect to extend the rect to fully include any partial tiles.
*/
#include "VideoToolbox.h"
void CenterRectInRect(Rect *a,Rect *b)
{
OffsetRect(a,(b->left + b->right - a->left - a->right)/2
,(b->top + b->bottom - a->top - a->bottom)/2);
}
void OffsetRectTile(Rect *r,int nx,int ny)
// Shift rect by multiples of itself
{
OffsetRect(r,nx*(r->right-r->left),ny*(r->bottom-r->top));
}
Boolean IsRectInRect(Rect *r,Rect *R)
// Is the first rect entirely inside the second?
// If either rect has zero area then this routine will return false.
{
Rect t;
if(!SectRect(r,R,&t))return 0;
return EqualRect(r,&t);
}
void ShrinkRect(Rect *r,int hDivisor,int vDivisor)
// Imagine that the plane is tiled by rects of size hDivisor by vDivisor.
// We first extend your rect to fully include any tiles that were only partly included.
// Then we shrink your rect by hDivisor and vDivisor.
{
r->top=floor((float)r->top/vDivisor);
r->bottom=ceil((float)r->bottom/vDivisor);
r->left=floor((float)r->left/hDivisor);
r->right=ceil((float)r->right/hDivisor);
}
void ExpandRect(Rect *r,double hMag,double vMag)
{
r->top=round(r->top*vMag);
r->bottom=round(r->bottom*vMag);
r->left=round(r->left*hMag);
r->right=round(r->right*hMag);
}
void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset)
{
r->top=round(r->top*vMag+vOffset);
r->bottom=round(r->bottom*vMag+vOffset);
r->left=round(r->left*hMag+hOffset);
r->right=round(r->right*hMag+hOffset);
}
void LocalToGlobalRect(Rect *r)
{
Point pt={0,0};
LocalToGlobal(&pt);
OffsetRect(r,pt.h,pt.v);
}
void GlobalToLocalRect(Rect *r)
{
Point pt={0,0};
GlobalToLocal(&pt);
OffsetRect(r,pt.h,pt.v);
}