4.4 Shape Definition Primitives

Usually the application programmer does not have to use segments directly when defining a shape. Instead there are a few operations in the shape that can be perceived as a language for shape definition: Open, Close, LineTo, SplineTo, Stroke, in addition to several operations for combining shapes. Combining shapes is not a straightforward task and is the subject of a subsequent section.

When using these operations, the concept of shape control points is used instead of segment control points. When looking at control points of the shape, the two control points in a joining of two segments are seen as one control point of the shape.

The first four operations for shape definition are used for adding control points to the shape. Depending on which operation is used, the curve between the previously placed control point and the new control point can be either a line or a non-circular spline. The Stroke operations is a powerful way of defining shapes illustrating outlines of graphical objects. It will be presented in the next section.

Open.
Open takes one argument (a point) and defines this as the first control point of the shape. After opening the shape, it is prepared to be constructed by means of a sequence of LineTo and SplineTo messages.
Close.
This places a control point at the same position as the first point hereby closing the shape.Close does not have to be invoked on a shape to make it a legal shape, but it ensures that the shape is closed, which is necessary when it is used with a paint in a graphical object. More on this later.
LineTo.
This operation adds a line segment to the shape, using the last control point of the shape as the first control point of the line segment, and the specified point as the last control point of the line segment.

The following example illustrates the use of the LineTo and Close operations:

aTriangle: @Shape
  (# 
  do (  0,  0) -> Open;
     (100,100) -> LineTo;
     (100,  0) -> LineTo;
     Close;
  #);
[45 bytes 50x5 GIF]

Resulting triangle:

[1kb 55x55 GIF]

The triangle shape now consists of three line segments, is closed and could be used in a graphical object.

SplineTo.
This operation adds a control point to the non-circular spline segment under construction.

Two different cases must be considered: is there currently a non-circular spline under construction or not.
In the former case (the last operation was SplineTo) the specified point is just added as a spline control point to that spline segment.
In the latter case (the last operations was LineTo or Open) a spline segment will be created with the ending point of the shape as the first spline control point and the specified point as the second spline control point. The following example illustrates the use of SplineTo:

aShape: @Shape
  (# 
  do (  0, 0) -> Open;
     (100,50) -> LineTo;
     (150,40) -> SplineTo;
     (130, 0) -> SplineTo;
     (100, 0) -> LineTo;
  #);
[45 bytes 50x5 GIF]

Resulting open shape:

[1006 bytes 95x34 GIF]

If a LineTo message follows a spline construction, LastPoint of the spline segment becomes FirstPoint of the new line segment. The shape in the example above consists of two line segments and one spline segments with three control points. Notice that the shape is not closed.

If a Close message follows a spline construction, the spline will be ended with a control point in the starting point of the shape:

myShape: @Shape
  (#
  do (  0,  0) -> Open;
     (  0, 50) -> LineTo;
     ( 25,100) -> SplineTo;
     (100, 70) -> SplineTo;
     ( 95,  0) -> SplineTo;
     Close;
  #);
[45 bytes 50x5 GIF]

Resulting closed shape:

[1kb 61x62 GIF]

MyShape consists of two segments, one line segment and one spline segment with five control points. Circular splines can not be constructed with the SplineTo primitive. Circular splines have to be created as circular spline segments and then added to the shape.


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