"
COPYRIGHT (c) 1995 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
Object subclass:#Geometric
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Graphics-Geometry'
!
!Geometric class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1995 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
documentation
"
Abstract superclass for geometric figures.
Concrete classes are (currently) Rectangle, Polygon and the classes
found in goodies/shape.
These are not graphical objects, but pure mathematical ones.
I.e. instances do not carry graphics attributes such as color, lineWidth etc.
Use instances of (subclasses) of DisplayObject or (the soon to be
implemented GraphicsAttributesWrapper.
Notice:
ST/X does not use Geometric instances for drawing (yet).
This class exists mainly to provide a superclass when ST-80
geometry classes are to be filed in.
[author:]
Claus Gittinger
[see also:]
Rectangle Polygon EllipticalArc Circle
Point
GraphicsContext
"
!
examples
"
circle; filled and unfilled:
[exBegin]
|v c|
v := (View extent:200@100) openAndWait.
c := Circle boundingBox:(10@10 corner:90@90).
v paint:Color blue.
c displayFilledOn:v.
c center:150@50.
v paint:Color red.
c displayStrokedOn:v.
[exEnd]
circle & rectangle; both filled:
[exBegin]
|v c|
v := (View extent:100@100) openAndWait.
c := Circle center:50@50 radius:40.
v paint:Color red.
c asRectangle displayFilledOn:v.
v paint:Color blue.
c displayFilledOn:v.
[exEnd]
elliptical arcs; filled & unfilled:
[exBegin]
|v e|
v := (View extent:200@100) openAndWait.
e := EllipticalArc
boundingBox:(10@10 corner:190@90)
startAngle:0
endAngle:270.
v paint:Color blue.
e displayFilledOn:v.
v paint:Color red.
e displayStrokedOn:v.
[exEnd]
polygon; filled & unfilled:
[exBegin]
|v p|
v := (View extent:100@100) openAndWait.
p := Polygon vertices:
(Array with:(10@10)
with:(90@90)
with:(10@90)).
v paint:Color blue.
p displayFilledOn:v.
v paint:Color red.
p displayStrokedOn:v.
[exEnd]
circles; filled & unfilled:
[exBegin]
|v c|
v := View new openAndWait.
c := Circle center:50@50 radius:40.
c displayFilledOn:v.
50 to:1 by:-1 do:[:r |
c radius:r.
v paint:(Color grey:(r * 2)).
c displayStrokedOn:v.
].
1 to:50 do:[:r |
c radius:r.
v paint:(Color grey:100-(r * 2)).
c displayStrokedOn:v.
]
[exEnd]
arcs; filled:
[exBegin]
|v ell|
v := View new openAndWait.
ell := EllipticalArc
boundingBox:(10@10 corner:90@90)
startAngle:0
sweepAngle:0.
#(45 90 135 180 225 270 315 360) keysAndValuesDo:[:index :angle |
index odd ifTrue:[
v paint:Color white
] ifFalse:[
v paint:Color black
].
ell sweepAngle:angle.
ell displayFilledOn:v.
Delay waitForSeconds:0.5.
].
[exEnd]
arcs; filled:
[exBegin]
|v ell|
v := View new openAndWait.
ell := EllipticalArc
boundingBox:(10@10 corner:90@90)
startAngle:0
sweepAngle:45.
#(45 90 135 180 225 270 315 360)
with:#( 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1)
do:[:angle :grey |
ell startAngle:angle-45.
v paint:(ColorValue red:grey green:0 blue:0).
ell displayFilledOn:v.
].
[exEnd]
spline; filled & unfilled:
[exBegin]
|v p|
v := (View extent:100@100) openAndWait.
p := Spline controlPoints:
(Array with:(20@20)
with:(80@80)
with:(20@80)).
v paint:Color blue.
p displayFilledOn:v.
v paint:Color red.
p displayStrokedOn:v.
[exEnd]
closed spline; filled & unfilled:
[exBegin]
|v p|
v := (View extent:100@100) openAndWait.
p := Spline controlPoints:
(Array with:(20@20)
with:(80@80)
with:(20@80)
with:(20@20)).
v paint:Color blue.
p displayFilledOn:v.
v paint:Color red.
p displayStrokedOn:v.
[exEnd]
"
! !
!Geometric methodsFor:'converting'!
asFiller
"return a wrapper which displays the receiver in its filled form"
^ FillingWrapper on:self
"Created: 8.5.1996 / 14:38:59 / cg"
"Modified: 8.5.1996 / 18:22:56 / cg"
!
asRectangle
"return the enclosing rectangle; same as #bounds"
^ self bounds
"Created: 8.5.1996 / 14:36:35 / cg"
!
asStroker
"return a wrapper which displays the receiver as stroked outline"
^ StrokingWrapper on:self
"Created: 8.5.1996 / 14:38:09 / cg"
"Modified: 8.5.1996 / 18:23:00 / cg"
! !
!Geometric methodsFor:'displaying'!
displayFilledOn:aGC
"display myself filled on a graphicsContext; the current graphics
attributes are used. Since we do not know how to do it, nothing is
drawn here."
^ self subclassResponsibility
"Modified: 8.5.1996 / 09:07:02 / cg"
!
displayOn:aGC
"display myself on a graphicsContext; the current graphics
attributes are used. The default here is to display the outline."
^ self displayStrokedOn:aGC
!
displayStrokedOn:aGC
"display my outline on a graphicsContext; the current graphics
attributes are usedSince we do not know how to do it, nothing is
drawn here."
^ self subclassResponsibility
"Modified: 8.5.1996 / 09:06:57 / cg"
! !
!Geometric methodsFor:'queries'!
bounds
"return the smallest enclosing rectangle"
^ self subclassResponsibility
"Created: 8.5.1996 / 13:56:08 / cg"
"Modified: 8.5.1996 / 14:06:31 / cg"
! !
!Geometric class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libbasic/Geometric.st,v 1.13 1996-05-08 18:16:58 cg Exp $'
! !