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.23 date: 2022/03/08 22:47:40
user: cg
file: Spline.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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.

copyright

This class is based on a file from the Manchester Goodie library. It is not covered by the ST/X copyright and may be copied and used according the rules as stated by the athor and the manchester archive. The original readme was: The above file is a Manchester Goodie. It is distributed freely on condition that you observe these conditions in respect of the whole Goodie, and on any significant part of it which is separately transmitted or stored: * You must ensure that every copy includes this notice, and that source and author(s) of the material are acknowledged. * These conditions must be imposed on anyone who receives a copy. * The material shall not be used for commercial gain without the prior written consent of the author(s). For more information about the Manchester Goodies Library (from which this file was distributed) send e-mail: To: goodies-lib@cs.man.ac.uk Subject: help

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.

transformations
o  transformedBy: aMatrix
return a new spline which is me transformed by aMatrix


Examples:


open spline; filled & unfilled:
  |v s|

  v := (View extent:200@200) openAndWaitUntilVisible.
  v transformation:(WindowingTransformation 
                      scale:1 
                      translation:(100@100)).

  v paint:Color black.
  v displayLineFrom:(-90@0) to:(90@0).
  v displayLineFrom:(0@-90) to:(0@90).
  v paint:Color lightGrey.
  v displayLineFrom:(60@-90) to:(60@90).
  v displayLineFrom:(-90@20) to:(90@20).
  v displayLineFrom:(-90@80) to:(90@80).

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

  v paint:Color blue.
  s displayFilledOn:v.

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

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

  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) openAndWaitUntilVisible.

  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 openAndWaitUntilVisible.

  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 openAndWaitUntilVisible.

  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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:37:00 GMT