Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

region-generic.h

00001 /* $TOG: region.h /main/9 1998/02/06 17:50:30 kaleb $ */
00002 /************************************************************************
00003 
00004 Copyright 1987, 1998  The Open Group
00005 
00006 All Rights Reserved.
00007 
00008 The above copyright notice and this permission notice shall be included in
00009 all copies or substantial portions of the Software.
00010 
00011 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00012 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00013 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00014 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00015 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00016 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 
00018 Except as contained in this notice, the name of The Open Group shall not be
00019 used in advertising or otherwise to promote the sale, use or other dealings
00020 in this Software without prior written authorization from The Open Group.
00021 
00022 
00023 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
00024 
00025                         All Rights Reserved
00026 
00027 Permission to use, copy, modify, and distribute this software and its 
00028 documentation for any purpose and without fee is hereby granted, 
00029 provided that the above copyright notice appear in all copies and that
00030 both that copyright notice and this permission notice appear in 
00031 supporting documentation, and that the name of Digital not be
00032 used in advertising or publicity pertaining to distribution of the
00033 software without specific, written prior permission.  
00034 
00035 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00036 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00037 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00038 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00039 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00040 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00041 SOFTWARE.
00042 
00043 ************************************************************************/
00044 
00045 // Stolen from Gtk+ and C++-ized by Ron Steinke, January 2003
00046 
00047 #ifndef _WFTK_REGION_GENERIC_H_
00048 #define _WFTK_REGION_GENERIC_H_
00049 
00050 #include "region.h"
00051 
00052 /*  1 if two BOXs overlap.
00053  *  0 if two BOXs do not overlap.
00054  *  Remember, x2 and y2 are not in the region 
00055  */
00056 #define EXTENTCHECK(r1, r2) \
00057     ((r1)->x2 > (r2)->x1 && \
00058      (r1)->x1 < (r2)->x2 && \
00059      (r1)->y2 > (r2)->y1 && \
00060      (r1)->y1 < (r2)->y2)
00061 
00062 /*
00063  *  update region extents
00064  */
00065 #define EXTENTS(r,idRect){\
00066             if((r)->x1 < (idRect)->extents.x1)\
00067               (idRect)->extents.x1 = (r)->x1;\
00068             if((r)->y1 < (idRect)->extents.y1)\
00069               (idRect)->extents.y1 = (r)->y1;\
00070             if((r)->x2 > (idRect)->extents.x2)\
00071               (idRect)->extents.x2 = (r)->x2;\
00072             if((r)->y2 > (idRect)->extents.y2)\
00073               (idRect)->extents.y2 = (r)->y2;\
00074         }
00075 
00076 /*
00077  *   Check to see if there is enough memory in the present region.
00078  */
00079 #define MEMCHECK(reg, rect, firstrect){                      \
00080         if ((reg)->numRects >= ((reg)->size - 1)) {              \
00081       RegionBox *tmp = new RegionBox[2 * (reg)->size];           \
00082       memcpy(tmp, (firstrect), (reg)->size * sizeof(RegionBox));         \
00083       delete [] (firstrect);                             \
00084           (firstrect) = tmp;                             \
00085           (reg)->size *= 2;                          \
00086           (rect) = &(firstrect)[(reg)->numRects];                \
00087          }                                   \
00088        }
00089 
00090 /*  this routine checks to see if the previous rectangle is the same
00091  *  or subsumes the new rectangle to add.
00092  */
00093 
00094 #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
00095                (!(((Reg)->numRects > 0)&&\
00096                   ((R-1)->y1 == (Ry1)) &&\
00097                   ((R-1)->y2 == (Ry2)) &&\
00098                   ((R-1)->x1 <= (Rx1)) &&\
00099                   ((R-1)->x2 >= (Rx2))))
00100 
00101 /*  add a rectangle to the given Region */
00102 #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
00103     if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
00104         CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
00105               (r)->x1 = (rx1);\
00106               (r)->y1 = (ry1);\
00107               (r)->x2 = (rx2);\
00108               (r)->y2 = (ry2);\
00109               EXTENTS((r), (reg));\
00110               (reg)->numRects++;\
00111               (r)++;\
00112             }\
00113         }
00114 
00115 
00116 
00117 /*  add a rectangle to the given Region */
00118 #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
00119             if ((rx1 < rx2) && (ry1 < ry2) &&\
00120                 CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
00121               (r)->x1 = (rx1);\
00122               (r)->y1 = (ry1);\
00123               (r)->x2 = (rx2);\
00124               (r)->y2 = (ry2);\
00125               (reg)->numRects++;\
00126               (r)++;\
00127             }\
00128         }
00129 
00130 #define EMPTY_REGION(pReg) pReg->numRects = 0
00131 
00132 #define REGION_NOT_EMPTY(pReg) pReg->numRects
00133 
00134 #define INBOX(r, x, y) \
00135       ( ( ((r).x2 >  x)) && \
00136         ( ((r).x1 <= x)) && \
00137         ( ((r).y2 >  y)) && \
00138         ( ((r).y1 <= y)) )
00139 
00140 #endif // _WFTK_REGION_GENERIC_H_

Generated Tue Aug 9 18:40:26 2005.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.