eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Spline':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Spline


Inheritance:

   Object
   |
   +--Geometric
      |
      +--Spline
         |
         +--ArrowedSpline

Package:
stx:libbasic2
Category:
Graphics-Geometry-Objects
Version:
rev: 1.19 date: 2013/02/08 20:45:16
user: cg
file: Spline.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
scaletti@uxc.cso.uiuc.edu (Kurt J. Hebel)
adapted to ST/X & minor fixes by Claus Gittinger

Description:


Spline defines a path that includes an arbitrary collection of points 
connected by a third order curve. The curve passes through all controlPoints.
Both open and closed curves are possible.


Related information:

    Polygon
    LineSegment
    Circle
    EllipticalArc
    Rectangle
    Curve
    Arrow
    ArrowedSpline
    GraphicsContext
    StrokingWrapper
    FillingWrapper

Class protocol:

instance creation
o  controlPoints: aSequentialCollectionOfPoints
return a new spline, which passes through aSequentialCollectionOfPoints


Instance protocol:

accessing
o  controlPoints
return the collection of points through which the spline is to pass

o  controlPoints: aCollectionOfPoints
set the collection of points through which the spline is to pass

converting
o  asPointArray
return an array containing my approximated vertex points.

o  asPolygon
return a polygon, approximating the spline

o  asPolyline
same as #asPolygon - for ST-80 compatibility

displaying
o  displayFilledOn: aGC
Display this Spline as a filled polygon from approximated lines.

o  displayStrokedOn: aGC
Display this Spline as a series of approximating lines.

private
o  computeCurve
Compute an array for the derivatives at each knot.

o  computeDerivatives: values
Computes the first, second and third derivatives at each point
in the collection values.

o  computeLineSegments
compute a series of approximating lines.

o  validateDerivatives
Make sure that the function and derivative arrays are still valid.
If they are not, recompute them.

queries
o  computeBounds
return the smallest enclosing rectangle

o  isCyclic
return true, if this spline represents a closed curve

testing
o  canBeFilled
return true, if the receiver can be drawn as a filled geometric.
Always true here.


Examples:


open spline; filled & unfilled:
  |v s|

  v := (View extent:100@100) openAndWait.

  s := Spline controlPoints:
              (Array with:(20@20)
                     with:(80@80)
                     with:(20@80)).

  v paint:Color blue.
  s displayFilledOn:v.

  v paint:Color red.
  s displayStrokedOn:v.
closed spline; filled & unfilled:
  |v s|

  v := (View extent:100@100) openAndWait.

  s := Spline controlPoints:
              (Array with:(20@20)
                     with:(80@80)
                     with:(20@80)
                     with:(20@20)).

  v paint:Color blue.
  s displayFilledOn:v.

  v paint:Color red.
  s displayStrokedOn:v.
spiral:
  |v points s|

  v := View extent:(200 @ 200).

  v openAndWait.

  points := OrderedCollection new.
  90 to:10 by:-10 do:[:r |
      0 to:330 by:30 do:[:angle |
          |d|

          d := (angle / 360) * 10.
          points add:(Point r:r-d angle:angle) + (100@100)
      ].
  ].
  s := Spline controlPoints:points.

  v paint:Color red.
  s displayStrokedOn:v.
interactive example: click-left for first-points; right for last.
  |v points eventCatcher|

  v := StandardSystemView extent:(450 @ 450).
  v label:'Spline Example - (click left/middle)'.

  points := OrderedCollection new.
  v viewBackground:Color black.
  v openAndWait.

  eventCatcher := Plug new.
  eventCatcher respondTo:#handlesButtonPress:inView:
                    with:[:butt :view | true].
  eventCatcher respondTo:#buttonPress:x:y:view:
                    with:[:butt :x :y :view | 
                          v paint:(Color white).
                          v fillCircle:(x @ y) radius:3.
                          points add:(x @ y).

                          (butt == 1 or:[butt == #select]) ifFalse:[
                              v paint:(Color white).
                              v fillCircle:(x @ y) radius:3.

                              (Spline controlPoints:points) displayStrokedOn:v.

                              points := OrderedCollection new.
                          ]
                         ].

  v delegate:(eventCatcher)


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 02 Apr 2020 04:32:08 GMT