4.8 Segment Definition Primitives

Segment primitives can be used directly to construct shapes. A shape is constructed in this way by generating a number of segments, and adding these segments to the shape. Segment definition primitives are only meant for internal use in Bifrost. It is not recommended to use these primitives, except for defining circular spline segments, but instead to use the shape definition operations described in Shape Definition Primitives.

4.8.1 LineSegment

A line segment is described by two control points: Begin (= FirstPoint) and End (= LastPoint). A line segment is constructed by assigning values to the Begin and End points:

aSeg:@LineSegment
  (#
  do (100,100) -> begin;
     (200,200) -> end;
  #)
[45 bytes 50x5 GIF]

Resulting line segment

[904 bytes 32x32 GIF]

4.8.2 SplineSegment

As mentioned earlier there are two different kinds of spline segments: circular and non-circular splines. A circular spline is always considered closed, and a non-circular spline is considered closed if the last operation performed is Close. Non-circular splines are typically used in construction of shapes consisting of both line and spline segments, and circular splines are useful for making circles and ellipses. Spline segments have three operations used for creating the spline:

Open.
Takes one point as argument. The point is the first control point of the spline, and the spline is prepared to be constructed with further control points using AddControl.
AddControl.
This operation just adds a specified control point to the spline.
Close.
Closes a non-circular spline by adding FirstPoint to the spline definition. The operation has no effect on a circular spline. Notice, that it is still possible to add further control points to the spline definition after the Close operation.

The following examples illustrate the use of AddControl and Close for a non-circular spline:

aBow: @NonCircularSplineSegment
  (#
  do (  0,100) -> Open;
     (100,100) -> AddControl;
     (100,  0) -> AddControl;
     (  0,  0) -> AddControl;
  #);
[45 bytes 50x5 GIF]

Open non-circular spline:

[959 bytes 44x42 GIF]
aDrop: @NonCircularSplineSegment
  (# 
  do (  0,100) -> Open;
     (100,100) -> AddControl;
     (100,  0) -> AddControl;
     (  0,  0) -> AddControl;
     close;
  #);
[45 bytes 50x5 GIF]

Closed non-circular spline:

[982 bytes 44x42 GIF]

The next examples illustrate the use of AddControl for circular splines:

aSpline: @CircularSplineSegment   
  (#    
  do (  0,100) -> Open;   
     (100,100) -> AddControl;   
     (100,  0) -> AddControl;     
  #);
[45 bytes 50x5 GIF]

Circular spline with three controlpoints:

[967 bytes 44x42 GIF]
aCircle: @CircularSplineSegment
  (# 
  do (  0,100) -> Open;
     (100,100) -> AddControl;
     (100,  0) -> AddControl;
     (  0,  0) -> AddControl;
  #);
[45 bytes 50x5 GIF]

Circular spline with four controlpoints:

[992 bytes 44x42 GIF]

Notice that a circular spline is inherently closed.

4.8.3 Adding Segments to Shapes

When the segment is defined it can be added to a shape with two shape primitives: AddLine and AddSpline.

AddLine.
Adds a line segment to the shape. In case where FirstPoint of the line segment does not coincide with LastPoint of the shape, the line segment is moved to the appropriate position.
AddSpline.
AddSpline adds a spline to the shape in construction. In case where FirstPoint of the spline segment does not coincide with LastPoint of the shape, the spline segment is moved to the appropriate position.

The following example illustrates the use of AddLine:

aLine: @LineSegment 
  (#
  do (100,100) -> begin;
     (150,150) -> end;
  #);

anotherLine: @LineSegment
  (# 
  do (200,200) -> begin;
     (200,100) -> end;
  #);

aShape: @Shape
  (# 
  do aLine -> AddLine;
     anotherLine -> AddLine;
  #);
[45 bytes 50x5 GIF]

Two line segments

[969 bytes 50x50 GIF]
[45 bytes 50x5 GIF]

Resulting shape:

[937 bytes 25x51 GIF]

The following example illustrates the use of and AddSpline using the two splines defined previously:

aShape: @Shape
  (# 
  do aCircle -> AddSpline;
     aDrop   -> AddSpline;
  #);
[45 bytes 50x5 GIF]

Resulting shape:

[1013 bytes 41x41 GIF]

In the case where the spline is not closed, i.e. FirstPoint does not coincide with LastPoint of the shape, the spline is moved to the appropriate position by AddSpline:

aLine: @LineSegment         
  (#                        
  do (100,100) -> begin;    
     ( 50,150) -> end;      
  #);                       

anotherLine: @LineSegment
  (# 
  do ( 50,150) -> begin;
     (150,200) -> end;
  #);
[45 bytes 50x5 GIF]

Two lines

[936 bytes 40x40 GIF]
aSpline: @NonCircularSplineSegment
  (# 
  do (  0,200) -> Open;
     ( 50,250) -> AddControl;
     (100,200) -> AddControl;
     (100,100) -> AddControl;
     ( 50, 50) -> AddControl;
  #);
[45 bytes 50x5 GIF]

A Spline

[1010 bytes 40x76 GIF]
aShape: @Shape
  (# 
  do aLine -> AddLine;
     anotherLine -> AddLine;
     aSpline -> AddSpline;
  #);
[45 bytes 50x5 GIF]

Resulting shape:

[1kb 76x76 GIF]

It should be clear from the examples that it is complicated to use the segment definition primitives for shape construction. Therefore, for purpose of convenience and to make the graphics system more powerful, Bifrost also includes the small shape construction language presented earlier.


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