4.7 Combining Shapes

When constructing complex shapes, it is often convenient to define the shape as simpler shapes and then combining the simpler shapes into the complex shape [2]. Shape is a subclass of Segment. This makes it possible to combine simple shapes into more complex ones in Bifrost: shapes can be treated as segments. Notice, that it was not shown in the segment hierarchy figure that Shape is a subclass of Segment [3].

The shape to be combined with another shape will be called the source shape, and the shape that receives the source shape will be known as the destination shape. Shapes inside another shape is referred to as subshapes. Four different semantics are possible for combining two shapes:

AppendShape.
The source shape is automatically translated in such a way that FirstPoint comes to coincide with the LastPoint of the destination shape
ConnectShape.
A transformation matrix is supplied that defines how the source shape should be transformed into the destination shape. LastPoint of the destination shape is connected to FirstPoint of the source shape with a line segment
ConnectShapeSmooth.
Like ConnectShape except that the two shapes are connected with a spline segment
CombineShape.
A supplied transformation matrix transforms the source shape into the coordinate system of the destination shape. The two shapes do not become connected

All operations make a copy of the source shape, and use this copy in the operation. It is important to notice that it is not all kinds of shapes that can be used as source shapes in all of the above four ways of combining shapes: the first three cannot take as argument a shape that only consist of circular spline segments. The reason is that a circular spline segment does not have a well-defined FirstPoint or a LastPoint. CombineShape cannot take an open shape as argument if it is open itself.

A shape is defined in its own coordinate system, which defaults to the CCS coordinate system. A shape has only one coordinate system, implying that all subshapes of a shape are defined in the same coordinate system as the destination shape itself. This is done by transforming the control points of the source shape into destination shape coordinates when shapes are combined.

The reason for only having one coordinate system for a shape is to limit the computing overhead and complication that would otherwise result by defining shapes with many coordinate systems within the same shape. This restriction does not reduce the power of the shape construction language, since nothing is gained by having more than one coordinate system in the same shape. Shapes in different graphical objects may each have different coordinate systems related to the graphical objects.

For each combination operation, there are four cases to consider, depending on the state of the source shape and of the destination shape:

  1. Open source shape and open destination shape
  2. Closed source shape and closed destination shape
  3. Open source shape and closed destination shape
  4. Closed source shape and open destination shape

Each case is illustrated with examples in the description of each combination operation below. The underlying philosophy of the four shape combination operations is to have consistent semantics in an operation. This can result in some combinations of shapes that do not seem useful. The most useful combinations are:

4.7.1 AppendShape

The source shape is automatically translated in such a way that FirstPoint comes to coincide with the LastPoint of the destination shape. After the operation the following two statements holds:

  1. FirstPoint of the source shape is equal to LastPoint of the destination shape
  2. LastPoint of the resulting shape is the translated LastPoint of the source shape

In the examples below, FirstPoint of the source shape, LastPoint of the destination shape, and LastPoint of the resulting shape are marked with bullets ([bullet] 
[818 bytes 5x5 GIF]).

[4kb 387x241 GIF]

Notice, that in the two cases where the source shape is closed, FirstPoint and LastPoint coincide, which means that the LastPoint of the resulting shape remains unchanged (i.e. the same as LastPoint of the destination shape).

4.7.2 ConnectShape

The supplied transformation matrix transforms the source shape into the coordinate system of the destination shape. LastPoint of the source shape is connected to the FirstPoint of the destination shape with a line segment. After the operation the following statement holds:

  1. LastPoint of the resulting shape is the transformed LastPoint of the source shape

In the examples below, FirstPoint of the source shape, LastPoint of the destination shape, and LastPoint of the resulting shape are marked with bullets. In all four cases the same transformation matrix is used. It performs rotation, scaling, and translation of the source shape.

[4kb 387x232 GIF]

Notice, that in the two cases where the source shape is closed, FirstPoint and LastPoint coincide, which means that LastPoint of the resulting shape remains unchanged (i.e. the same as LastPoint of the destination shape). Notice also, that when both the source and the destination shapes are closed the resulting shape is open (FirstPoint <> LastPoint).

4.7.3 ConnectShapeSmooth

The supplied transformation matrix transforms the source shape into the coordinate system of the destination shape. LastPoint of the source shape is connected to the FirstPoint of the destination shape with a spline segment. After the operation the following statement becomes true:

  1. LastPoint of the resulting shape is the transformed LastPoint of the source shape

In the examples below, FirstPoint of the source shape, LastPoint of the destination shape, and LastPoint of the resulting shape are marked with bullets. In all four cases the same transformation matrix is used. It performs rotation, scaling, and translation of the source shape.

[4kb 387x239 GIF]

Notice, that in the cases where the destination shape is closed, two of the control points defining the spline segment, that connects the two shapes, are from the destination shape: LastPoint, and the control point prior to LastPoint. The third and last control point that defines the spline segment is FirstPoint of the source shape. Notice also, that when both the source and the destination shapes are closed the resulting shape is open (FirstPoint <> LastPoint).

4.7.4 CombineShape

The supplied transformation matrix transforms the source shape into the coordinate system of the destination shape. The two shapes do not become connected. Notice, that it is an error if both source and destination shape are open, since the resulting shape would otherwise not be connected. After the operation, only one of the following statements holds:

  1. LastPoint of the destination shape is LastPoint of the resulting shape
  2. LastPoint of the source shape is LastPoint of the resulting shape

The latter statement only holds if the source shape is open and the destination shape is closed. The reason for this seemingly strange behavior is that the resulting shape can then be combined further in a consistent way. One can also think of this situation in terms of which shape is open after the operation - in this particular situation it is the source shape that is open.

In the examples below, FirstPoint of the source shape, LastPoint of the destination shape, and LastPoint of the resulting shape are marked with bullets.

[3kb 387x216 GIF]

Notice the last situation that is commented on above.


[2] This implements a limited form of graphics modelling. Later the concept of picture is defined as a more powerful way of doing graphics modelling.
[3] The discussion of the Shape inheritance hierarchy is deferred until the presentation of predefined shapes, see Predefined Shapes and Graphical Objects


The Bifrost Graphics System - Reference Manual
© 1991-2002 Mjølner Informatics
[Modified: Tuesday October 24th 2000 at 15:02]