Notes on the geometry layer of CLIM II Regions and region-sets, primarily. What pieces exist, how do they fit together, how might they be implemented, and is the system conceptually whole? The presentation of regions in CLIM seems to be flawed. Why not defer region composition until /after/ the simple regions have been introduced? Additionally, bounding-rectangles can, and possibly should, be introduced before region composition. Part of the description of bounding-rectangles relies on transformations, but transformation application depends on simple regions. ** Object mutability and capture Most region objects capture their mutable arguments, meaning that the arguments must not be mutated while the geometry object is still in scope. There are no writers defined for any aspect of any simple region object, meaning that there is no standard way to mutate such objects. Additionally, all standard simple region classes are specified to produce immutable instances. The exception to the general immutability here is that the three standard REGION-SET classes are not specified to produce immutable instances and, while there are no writers defined for the region composition protcol, REGION-SET-REGIONS returns a list of regions that may share structure with the internal implementation of the standard REGION-SETs. Conclusion: This is a specific nod to the possibility of a user implementation of the various geometry protocols. ** The coordinate system CLIM II specification, chapter 3, paragraph three states that the coordinate system is an "abstract, continuous" system, and that the system (not the coordinates, but the entire system) is converted to "``real world''" coordinates only when doing things such as rendering a geometric object to a display device. Leaving aside the conversion of an entire coordinate system into a set of coordinates, and the notion of a "real world" with coordinates, section 3.1 defines a COORDINATE type which is required to be either T or a subtype of REAL and grants explicit permission to use a "more specific subtype of real", giving the example of SINGLE-FLOAT, "for reasons of efficiency". Amazingly enough, this gives permission to use a coordinate type such as BIT or (INTEGER 0 0). In any case, taking SINGLE-FLOAT as our coordinate type, we can immediately point out that the precision of a SINGLE-FLOAT is insufficient for a continuous coordinate space. The same applies for RATIONAL numbers, or any other convenient coordinate representation. If we acknowledge the coordinate system as an /approximation/ of a continuous system, however, we have the somewhat useful result that we cannot determine the two points on a line immediately adjacent to a given point, used in conjunction with dimensionality conservation when defining the region composition operations. ** Predicates The predicates used between regions are: - REGION-EQUAL: Do two regions contain exactly the same set of points? - REGION-CONTAINS-REGION-P: Are all of the points in the second region also contained in the first? - REGION-CONTAINS-POSITION-P: Is a particular point contained in a region? - REGION-INTERSECTS-REGION-P: Would the REGION-INTERSECTION of two regions contain any points at all? A few notes here: - Two regions are REGION-EQUAL iif REGION-CONTAINS-REGION-P for both orderings of the regions. - REGION-CONTAINS-POSITION-P is REGION-CONTAINS-REGION-P with a "spread" point argument. - REGION-INTERSECTS-REGION-P is not a question of "do two regions contain any points in common" because of dimensionality conservation in region composition. Two rectangles with a common border both contain the points along the line of the border, but do not intersect. Robert Strandh has raised concerns that some of these functions might be "very hard" to implement across the full range of region types, including the various REGION-SET subtypes, with particular emphasis on REGION-EQUAL and REGION-CONTAINS-REGION-P. REGION-EQUAL can be defined as #+begin_src lisp (and (region-contains-region-p region1 region2) (region-contains-region-p region2 region1)) #+end_src . REGION-CONTAINS-POSITION-P can reasonably be implemented for any simple region. For a STANDARD-REGION-UNION, there is #+begin_src lisp (some (lambda (sub-region) (region-contains-position-p sub-region x y)) (region-set-regions region)) #+end_src , or a formulation using MAP-OVER-REGION-SET-REGIONS could be used. For a STANDARD-REGION-INTERSECTION, the use of EVERY instead of SOME in the example above is sufficient. For a STANDARD-REGION-DIFFERENCE with two regions, #+begin_src lisp (and (region-contains-position-p (first sub-regions) x y) (not (region-contains-position-p (second sub-regions) x y))) #+end_src , with suitable extension for whatever semantic is decided on for a STANDARD-REGION-DIFFERENCE with more than two regions (assuming that such a semantic is defined). REGION-INTERSECTS-REGION-P can be implemented as #+begin_src lisp (eq +nowhere+ (region-intersection region1 region2)) #+end_src , by a trivial interpretation of its specification. This leaves REGION-CONTAINS-REGION-P as the "hard" case. [ FIXME: Solve the hard case. ] We begin with the unbounded regions, which are the easy cases: - REGION-CONTAINS-REGION-P for a super-region or sub-region that is NOWHERE is never true. - REGION-CONTAINS-REGION-P for a super-region that is EVERYWHERE is only false if the sub-region is NOWHERE. - REGION-CONTAINS-REGION-P for a sub-region that is EVERYWHERE is only true if the super-region is EVERYWHERE. REGION-CONTAINS-REGION-P is never true if the dimensionality of the sub-region is greater than the dimensionality of the super-region. This means that a sub-region that is a PATH or a REGION-SET of PATHs will never be contained in a super-region that is a POINT or a REGION-SET of POINTs, and the same logic applies with AREAs as sub-regions and POINTs or PATHs as super-regions. REGION-CONTAINS-REGION-P for a sub-region that is comprised of POINTs is trivially implemented by REGION-CONTAINS-POSITION-P. [ Can we just use (region-difference sub-region super-region) to do all this, and if the result is NOWHERE then the sub-region is contained entirely within the super-region? ] ** Dimensionality conservation When composing two regions, or creating a new "simple" region, dimensionality is "conserved" in a manner which does not correspond with set theory. If an entity normally having dimensionality $m$ is specified with parameters that would cause the entity to have dimensionalty $n$ where $n