3.1 General Regions

  • 3.1.1 The Region Predicate Protocol
  • 3.1.2 Region Composition Protocol
  • A region is an object that denotes a set of mathematical points in the plane. Regions include their boundaries, that is, they are closed. Regions have infinite resolution. [annotate]

    [region, Concept← A Glossary]
    [region, Concept← A Glossary]
    [region, Concept← A Glossary]
    [region, Concept← A Glossary]
    [region, Concept← A Glossary]
    [region, Concept← A Glossary]
    [region, Concept← A Glossary]
    [region, Concept← 16.4.1 The Output Recording Stream Protocol, stream-replay]
    [region, Concept← 16.2.2 The Output Record "Database" Protocol, map-over-output-records-overlapping-region]
    [region, Concept← 8.4.1 Repaint Protocol Functions, repaint-sheet]
    [region, Concept← 7.3.1 Sheet Geometry Functions, children-overlapping-region]
    [region, Concept← 5.3.3 Applying Transformations, transform-region]
    [region, Concept← 5.3.3 Applying Transformations]
    [region, Concept← 3.1.2 Region Composition Protocol, region-difference]
    [region, Concept← 3.1.2 Region Composition Protocol, region-difference]
    [region, Concept← 3.1.1 The Region Predicate Protocol, region-contains-position-p]
    [region, Concept← 3.1.1 The Region Predicate Protocol, region-contains-region-p]
    [region, Concept← 3.1.1 The Region Predicate Protocol, region-contains-region-p]
    [region, Concept← 3.1 General Regions, regionp]

    A bounded region is a region that contains at least one point and for which there exists a number, d, called the region's diameter, such that if p1 and p2 are points in the region, the distance between p1 and p2 is always less than or equal to d. [annotate]

    [bounded region, Concept← A Glossary]

    An unbounded region either contains no points or contains points arbitrarily far apart. [annotate]

    Another way to describe a region is that it maps every (x,y) pair into either true or false (meaning member or not a member, respectively, of the region). Later, in Chapter 14, we will generalize a region to something called a design that maps every point (x,y) into color and opacity values. [annotate]

    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← A Glossary]
    [design, Concept← 14.5 Arbitrary Designs, draw-design]
    [design, Concept← 14.3 Tiling, make-rectangular-tile]
    [design, Concept← 14.1 The Compositing Protocol, compose-out]
    [design, Concept← 14.1 The Compositing Protocol, compose-out]
    [design, Concept← 14.1 The Compositing Protocol, compose-in]
    [design, Concept← 14.1 The Compositing Protocol, compose-in]
    [design, Concept← 14.1 The Compositing Protocol, compose-over]
    [design, Concept← 14.1 The Compositing Protocol, compose-over]
    [design, Concept← 13.2 Basic Designs, designp]

    region   [Protocol Class]
              

    The protocol class that corresponds to a set of points. This includes both bounded and unbounded regions. This is a subclass of design (see Chapter 13). [annotate]

    If you want to create a new class that behaves like a region, it should be a subclass of region. All instantiable subclasses of region must obey the region protocol. [annotate]

    Note: The spec mentions the "region predicate protocol" and the "region composition protocol", but there seems to be no explicit mention of "the region protocol". Should we assume that the "region protocol" is the union of those two protocols? [edit]-- Robert Strandh 2007-08-23 08:57Z
     

    There is no general constructor called make-region because of the impossibility of a uniform way to specify the arguments to such a function. [annotate]

    [annotate]

    regionp  object [Protocol Predicate]
              

    Returns true if object is a region, otherwise returns false. [annotate]

    [annotate]

    path   [Protocol Class]
              

    The protocol class path denotes bounded regions that have dimensionality 1 (that is, have length). It is a subclass of region and bounding-rectangle. If you want to create a new class that behaves like a path, it should be a subclass of path. All instantiable subclasses of path must obey the path protocol. [annotate]

    Constructing a path object with no length (via make-line*, for example) may canonicalize it to +nowhere+. [annotate]

    Some rendering models support the constructing of areas by filling a closed path. In this case, the path needs a direction associated with it. Since CLIM does not currently support the path-filling model, paths are directionless. [annotate]

    [annotate]

    pathp  object [Protocol Predicate]
              

    Returns true if object is a path, otherwise returns false. [annotate]

    Note that constructing a path object with no length (such as calling make-line with two coincident points), for example) may canonicalize it to +nowhere+. [annotate]

    [annotate]

    area   [Protocol Class]
              

    The protocol class area denotes bounded regions that have dimensionality 2 (that is, have area). It is a subclass of region and bounding-rectangle. If you want to create a new class that behaves like an area, it should be a subclass of area. All instantiable subclasses of area must obey the area protocol. [annotate]

    Note that constructing an area object with no area (such as calling make-rectangle with two coincident points), for example) may canonicalize it to +nowhere+. [annotate]

    [annotate]

    areap  object [Protocol Predicate]
              

    Returns true if object is an area, otherwise returns false. [annotate]

    [annotate]

    coordinate   [Type]
              

    The type that represents a coordinate. This must either be t, or a subtype of real. CLIM implementations may use a more specific subtype of real, such as single-float, for reasons of efficiency. [annotate]

    All of the specific region classes and subclasses of bounding-rectangle will use this type to store their coordinates. However, the constructor functions for the region classes and for bounding rectangles must accept numbers of any type and coerce them to coordinate. [annotate]

    [annotate]

    coordinate  n [Function]
              

    Coerces the number n to be a coordinate. [annotate]

    [annotate]

    +everywhere+   [Constant]
    +nowhere+   [Constant]

    3.1.1 The Region Predicate Protocol

    The following generic functions comprise the region predicate protocol. All classes that are subclasses of region must either inherit or implement methods for these generic functions. [annotate]

    Note: My hunch is that it might be very hard to implement some of these functions for all region types, in particular region-equal and region-contains-region-p when one of the arguments is a union or intersection of other regions. [edit]-- Robert Strandh 2007-08-23 09:15Z
     

    The methods for region-equal, region-contains-region-p, and region-intersects-region-p will typically specialize both the region1 and region2 arguments. [annotate]

    region-equal  region1 region2 [Generic Function]
              

    Returns true if the two regions region1 and region2 contain exactly the same set of points, otherwise returns false. [annotate]

    [annotate]

    region-contains-region-p  region1 region2 [Generic Function]
              

    Returns true if all points in the region region2 are members of the region region1, otherwise returns false. [annotate]

    [annotate]

    region-contains-position-p  region x y [Generic Function]
              

    Returns true if the point at (x,y) is contained in the region region, otherwise returns false. Since regions in CLIM are closed, this must return true if the point at (x,y) is on the region's boundary. CLIM implementations are permitted to return different non-nil values depending on whether the point is completely inside the region or is on the border. [annotate]

    region-contains-position-p is a special case of region-contains-region-p in which the region is the point (x,y). [annotate]

    [annotate]

    region-intersects-region-p  region1 region2 [Generic Function]
              

    Returns false if region-intersection of the two regions region1 and region2 would be +nowhere+, otherwise returns true. [annotate]

    [annotate]

    3.1.2 Region Composition Protocol

    Region composition is not always equivalent to simple set operations. Instead, composition attempts to return an object that has the same dimensionality as one of its arguments. If this is not possible, then the result is defined to be an empty region, which is canonicalized to +nowhere+. (The exact details of this are specified with each function.) [annotate]

    Sometimes, composition of regions can produce a result that is not a simple contiguous region. For example, region-union of two rectangular regions might not be a single rectangle. In order to support cases like this, CLIM has the concept of a region set, which is an object that represents one or more region objects related by some region operation, usually a union. CLIM provides standard classes to cover the cases of region union, intersection, and difference. [annotate]

    [region set, Concept← A Glossary]
    [region set, Concept← 3.1.2 Region Composition Protocol, map-over-region-set-regions]
    [region set, Concept← 3.1.2 Region Composition Protocol, map-over-region-set-regions]
    [region set, Concept← 3.1.2 Region Composition Protocol, region-set-regions]
    [region set, Concept← 3.1.2 Region Composition Protocol, region-set-regions]
    [region set, Concept← 3.1.2 Region Composition Protocol, region-set-p]

    Some CLIM implementations might only implement a subset of full region composition. Because of the importance of rectangular regions and region sets that are the union of rectangular regions, every CLIM implementation is required to fully support all functions that use regions for those cases. (For example, CLIM implementations must be able do clipping and repainting on region sets composed entirely of axis-aligned rectangles.) If a CLIM implementation does not support some functions on non-rectangular region sets (for example, clipping), it must signal an error when an unsupported case is encountered; the exact details of this depend on the particular CLIM implementation. [annotate]

    region-set   [Protocol Class]
              

    The protocol class that represents a region set; a subclass of region and bounding-rectangle. [annotate]

    In addition to the three classes below, there may be other instantiable subclasses of region-set that represent special cases, for instance, some implementations might have a standard-rectangle-set class that represents the union of several axis-aligned rectangles. [annotate]

    Members of this class are immutable. [annotate]

    [annotate]

    region-set-p  object [Protocol Predicate]
              

    Returns true if object is a region set, otherwise returns false. [annotate]

    [annotate]

    standard-region-union   [Class]
    standard-region-intersection   [Class]
    standard-region-difference   [Class]
              

    These three instantiable classes respectively implement the union, intersection, and differences of regions. Implementations may, but are not required to, take advantage of the commutativity and associativity of union and intersection in order to "collapse" complicated region sets into simpler ones. [annotate]

    Region sets that are composed entirely of axis-aligned rectangles must be canonicalized into either a single rectangle or a union of rectangles. Furthermore, the rectangles in the union must not overlap each other. [annotate]

    The following generic functions comprise the region composition protocol. All classes that are subclasses of region must implement methods for these generic functions. [annotate]

    The methods for region-union, region-intersection, and region-difference will typically specialize both the region1 and region2 arguments. [annotate]

    [annotate]

    region-set-regions  region &key normalize [Generic Function]
              

    Returns a sequence of the regions in the region set region. region can be either a region set or a "simple" region, in which case the result is simply a sequence of one element: region. This function returns objects that reveal CLIM's internal state; do not modify those objects. [annotate]

    For the case of region sets that are unions of axis-aligned rectangles, the rectangles returned by region-set-regions are guaranteed not to overlap. [annotate]

    If normalize is supplied, it must be either :x-banding or :y-banding. If it is :x-banding and all the regions in region are axis-aligned rectangles, the result is normalized by merging adjacent rectangles with banding done in the x direction. If it is :y-banding and all the regions in region are rectangles, the result is normalized with banding done in the y direction. Normalizing a region set that is not composed entirely of axis-aligned rectangles using x- or y-banding causes CLIM to signal the region-set-not-rectangular error. [annotate]

    [annotate]

    map-over-region-set-regions  function region &key normalize [Generic Function]
              

    Calls function on each region in the region set region. This is often more efficient than calling region-set-regions. function is a function of one argument, a region; it has dynamic extent. region can be either a region set or a "simple" region, in which case function is called once on region itself. normalize is as for region-set-regions. [annotate]

    Note: What does "it has dynamic extent" mean? [edit]-- Otto Drachen 2013-09-09 00:58Z
     
    Note: The function can safely be allocated on the stack instead of the heap, as with the dynamic-extent declaration. [edit]-- Elijah Malaby 2016-09-04 15:03Z
     


    Figure 3.1: Normalization of rectangular region sets.

    [annotate]

    region-union  region1 region2 [Generic Function]
              

    Returns a region that contains all points that are in either of the regions region1 or region2 (possibly with some points removed in order to satisfy the dimensionality rule). The result of region-union always has dimensionality that is the maximum dimensionality of region1 and region2. For example, the union of a path and an area produces an area; the union of two paths is a path. [annotate]

    region-union will return either a simple region, a region set, or a member of the class standard-region-union. [annotate]

    This function is permitted to capture its mutable inputs; the consequences of modifying those objects are unspecified. [annotate]

    [annotate]

    region-intersection  region1 region2 [Generic Function]
              

    Returns a region that contains all points that are in both of the regions region1 and region2 (possibly with some points removed in order to satisfy the dimensionality rule). The result of region-intersection has dimensionality that is the minimum dimensionality of region1 and region2, or is +nowhere+. For example, the intersection of two areas is either another area or +nowhere+; the intersection of two paths is either another path or +nowhere+; the intersection of a path and an area produces the path clipped to stay inside of the area. [annotate]

    region-intersection will return either a simple region or a member of the class standard-region-intersection. [annotate]

    This function is permitted to capture its mutable inputs; the consequences of modifying those objects are unspecified. [annotate]

    [annotate]

    region-difference  region1 region2 [Generic Function]
              

    Returns a region that contains all points in the region region1 that are not in the region region2 (possibly plus additional boundary points to make the result closed). The result of region-difference has the same dimensionality as region1, or is +nowhere+. For example, the difference of an area and a path produces the same area; the difference of a path and an area produces the path clipped to stay outside of the area. [annotate]

    region-difference will return either a simple region, a region set, or a member of the class standard-region-difference. [annotate]

    This function is permitted to capture its mutable inputs; the consequences of modifying those objects are unspecified. [annotate]


    Figure 3.2: Examples of region union, intersection, and difference.

    [annotate]