Rivl_Region is built on top of the X11R5 region library: XCreateRegion, XUnionRegion, etc. The names have changed to match the rest of Rivl's external interface, the internal structure has been changed to use long ints instead of short ints, and many new interface functions have been added.
Storage for regions works as follows. A variable declared as Rivl_Region is a pointer to an opaque structure. Before the variable is used it must be assigned to a new initialized region by calling one of the three Rivl_Create functions. After that, it may be passed to any of the Rivl_Region functions until it is destroyed with Rivl_RegionDestroy. Functions such as Rivl_RegionUnion work by overwriting the value in the argument named dr, which must be an initialized region but need not be empty.
Rivl_RegionCreate creates and returns a new empty region. Rivl_RegionClear sets dr to the empty region.
Rivl_RegionCreateFromBox creates and returns a new region containing only box. Rivl_RegionCopyFromBox sets dr to contain only box.
Rivl_RegionCreateFromRegion creates and returns a duplicate of sr. Rivl_RegionCopy copies sr into dr.
Rivl_RegionIntersect sets dr to the intersection of sra and srb. Rivl_RegionIntersectWithBox sets dr to the intersection of sra and box.
Rivl_RegionUnion sets dr to the union of sra and srb. Rivl_RegionUnionWithBox sets dr to the union of sra and box.
Rivl_RegionSubtract subtracts srb from sra and places the difference in dr. Rivl_RegionSubtractBox sets dr to the union of sra and box.
Rivl_RegionDestroy destroys dr and frees up resources associated with it.
Rivl_RegionSetInf sets dr to the region from negative infinity to positive infinity, with respect to sampleRate, on both axes.
Rivl_RegionOffset, Rivl_RegionPad, and RivlRegionScale destructively apply the functions Rivl_BoxOffset, Rivl_BoxPad, and Rivl_BoxScale (respectively) to all of the boxes in dr.
Rivl_RegionClipBox returns the smallest box enclosing all the boxes in reg.
Rivl_RegionEmpty returns 1 if reg is empty, 0 otherwise. Rivl_RegionContained returns 1 if sra is contained in srb, 0 otherwise.
Rivl_RegionGetBoxes returns the list of boxes that make up reg. It places a pointer to an array of boxes in **boxesPtr and the number of boxes in *boxCountPtr. The array is not NULL terminated. The area of memory pointed to by *boxesPtr is contained within the region data structure and is guaranteed not to change until the next call that modifies or destroys the region. The array and the boxes inside it should not be modified.
Rivl_RegionArea sums up the areas of the boxes in reg, and returns the sum.