|
Class: Geometric
Object
|
+--Geometric
|
+--Bezier
|
+--Circle
|
+--Curve
|
+--EllipticalArc
|
+--LineSegment
|
+--Polygon
|
+--Rectangle
|
+--Spline
- Package:
- stx:libbasic
- Category:
- Graphics-Geometry-Objects
- Version:
- rev:
1.55
date: 2022/07/02 15:03:21
- user: cg
- file: Geometric.st directory: libbasic
- module: stx stc-classLibrary: libbasic
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.
However, they ``know'' how to display themself as stroked or possibly
filled picture on a graphicsContext (although, the GC's current
paint and lineStyles are used).
Use instances of (subclasses) of DisplayObject or
of the GeometricWrapper classes for objects which keep the color
and lineStyle information with them.
Notice:
ST/X does not use Geometric instances for drawing (yet).
Except for Rectangle, Geometry and its subclasses exists mainly
for ST-80 compatibility and to provide a home when other (PD)
geometry classes are to be filed in.
copyrightCOPYRIGHT (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.
helper functions
-
boundingRectangleForPoints: aSequencableCollectionOfPoints
-
given a bunch of point, compute the boundingRectangle
(i.e. the smallest rectangle which encloses all of those points)
-
matrixToRotateBy: alpha
-
return a rotationmatrix;
the angle is interpreted as counter-clockwise (same as in Point >> rotateBy:)
TODO: cache to avoid recreating matrixes all the time
Usage example(s):
self matrixToRotateBy:0
self matrixToRotateBy:(90 degreesToRadians)
self matrixToRotateBy:(180 degreesToRadians)
self matrixToRotateBy:(270 degreesToRadians)
|
-
matrixToScaleBy: aPointOrNumber
-
return a scaling matrix - simple
TODO: cache to avoid recreating matrixes all the time
Usage example(s):
self matrixToScaleBy:1
self matrixToScaleBy:2
(10@10 corner:20@20) scaledBy:2
(10@10 corner:20@20) transformedBy:(Geometric matrixToScaleBy:2)
|
-
matrixToTranslateBy: aPointOrNumber
-
return a translation matrix - simple
TODO: cache to avoid recreating matrixes all the time
initialization
-
initialize
-
setup class constants
Usage example(s):
queries
-
isAbstract
-
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.
converting
-
asFiller
-
return a wrapper which displays the receiver in its filled form
Usage example(s):
|v r|
v := View new.
v extent:200@200.
v openAndWaitUntilVisible.
r := Rectangle origin:10@10 corner:100@100.
r asFiller displayOn:v.
|
-
asFiller: fillColor
-
return a wrapper which displays the receiver filled with fillColor
Usage example(s):
|v r|
v := View new.
v extent:200@200.
v openAndWaitUntilVisible.
r := Rectangle origin:10@10 corner:100@100.
(r asFiller:Color red) displayOn:v.
|
-
asRectangle
-
return the enclosing rectangle; same as #bounds
-
asStroker
-
return a wrapper which displays the receiver as stroked outline
-
asStroker: lineColor
-
return a wrapper which displays the receiver drawn with strokeColor
Usage example(s):
|v r|
v := View new.
v extent:200@200.
v openAndWaitUntilVisible.
r := Rectangle origin:10@10 corner:100@100.
(r asStroker:Color red) displayOn:v.
|
-
asVisualComponent
-
return a wrapper on the receiver, which responds to VisualComponent messages.
destructive transformations
-
scaleBy: scale
-
scale the receiver rectangle by scale (a Number or Point).
This is destructive (modifies the receiver, not a copy) and
should only be used if you know, that you are the exclusive owner
of the receiver. (use scaledBy: if in doubt)
** This method must be redefined in concrete classes (subclassResponsibility) **
-
translateBy: amount
-
translate (i.e. move) the receiver rectangle
by amount, a Point or Number (keeping extent unchanged).
This is destructive (modifies the receiver, not a copy) and
should only be used if you know, that you are the exclusive owner
of the receiver. (use translatedBy: if in doubt)
** This method must be redefined in concrete classes (subclassResponsibility) **
displaying
-
ascentOn: aGC
-
displayOn: does not draw above baseline
-
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.
** This method must be redefined in concrete classes (subclassResponsibility) **
-
displayOn: aGCOrStream
-
display myself on a graphicsContext; the current graphics
attributes are used. The default here is to display the outline.
Usage example(s):
|v r|
v := View new.
v extent:200@200.
v openAndWaitUntilVisible.
r := Rectangle origin:10@10 corner:100@100.
r displayOn:v.
|
-
displayOn: aGC x: x y: y
-
display myself on a graphicsContext at some coordinate;
the current graphics attributes are used.
The default here is to display the outline.
Usage example(s):
|v r|
v := View new.
v extent:200@200.
v openAndWaitUntilVisible.
r := Rectangle origin:10@10 corner:100@100.
r displayOn:v at:20@30.
|
-
displayStrokedOn: aGC
-
display my outline on a graphicsContext; the current graphics
attributes are used. Since we do not know how to do it, nothing is
drawn here.
** This method must be redefined in concrete classes (subclassResponsibility) **
helper functions
-
matrixToScaleBy: aPointOrNumber
-
return a scaling matrix - simple
TODO: cache to avoid recreating matrixes all the time
Usage example(s):
self matrixToScaleBy:1
self matrixToScaleBy:2
(10@10 corner:20@20) scaledBy:2 (20@20) extent: (20@20)
(10@10 corner:20@20) transformedBy:(Geometric matrixToScaleBy:2)
|
inspecting
-
inspector2TabDisplayObject
-
(comment from inherited method)
a tab, showing the receiver as display object
queries
-
bounds
-
return the smallest enclosing rectangle.
This resends computeBounds, to allow caching of bounds in
case this computation is expensive.
-
computeBounds
-
return the smallest enclosing rectangle.
** This method must be redefined in concrete classes (subclassResponsibility) **
-
outlineIntersects: aRectangle
-
return true, if the receiver's image intersects
aRectangle, when drawn as an outline.
Here, all we can do is to ask the boundary rectangle;
subclasses should reimplement better checks.
-
regionIntersects: aRectangle
-
return true, if the receiver's image intersects
aRectangle, when drawn as a filled version.
Here, all we can do is to ask the boundary rectangle;
subclasses should reimplement better checks.
testing
-
canBeFilled
-
return true, if the receiver can be drawn as a filled geometric.
Return false here, since we don't know.
-
isBezier2Segment
-
return true, if the receiver is a quadratic bezier segment
-
isGeometric
-
return true, if the receiver is a geometric object
-
isLineSegment
-
return true, if the receiver is a line segment
transformations
-
align: offset with: someCoordinate
-
return a new geometric object which is translated (i.e. moved)
such that the point offset in mySelf is placed on someCoordinate.
-
alignBottomLeftWith: someCoordinate
-
return a copy of myself where its bottomLeft is aligned with someCoordinate
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignBottomLeftWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
alignBottomRightWith: someCoordinate
-
return a copy of myself where its bottomRight is aligned with someCoordinate.
Same as alignCorner
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignBottomRightWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
alignCenterWith: someCoordinate
-
return a copy of myself where its center is aligned with someCoordinate.
Same as alignOrigin
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignCenterWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
alignCornerWith: someCoordinate
-
return a copy of myself where its corner is aligned with someCoordinate
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignCornerWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
alignOriginWith: someCoordinate
-
return a copy of myself where its origin is aligned with someCoordinate
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignOriginWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
alignTopLeftWith: someCoordinate
-
return a copy of myself where its topLeft is aligned with someCoordinate.
Same as alignOrigin
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignTopLeftWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
alignTopRightWith: someCoordinate
-
return a copy of myself where its topRight is aligned with someCoordinate.
Same as alignOrigin
Usage example(s):
|r1 r2 r3 v|
r1 := 0@0 corner:10@10.
r2 := 100@100 corner:200@200.
r3 := r1 copy alignTopRightWith:r2 corner.
v := (View extent:300@300) openAndWaitUntilVisible.
r2 displayOn:v.
r3 displayOn:v.
|
-
rotatedBy: angle about: rotationCenter
-
return a copy of the receiver, which is rotated around rotationCenter
by an angle (radians) around rotationCenter (which may be located outside);
the angle is interpreted as counter-clockwise (same as in Point >> rotatedBy:)
Usage example(s):
(Rectangle origin:10@10 corner:50@50) rotatedBy:(Float pi) around:0@0
(Rectangle origin:10@10 corner:50@50) rotatedBy:(Float pi) around:10@10
|
-
roundedToNearestIntegerPoint
-
return a copy of the receiver, where all points are rounded to ly on the nearest integer coordinate
** This method must be redefined in concrete classes (subclassResponsibility) **
-
scaledBy: aPointOrNumber
-
return a copy of the receiver, which is scaled by the argument, a point or number
-
transformedBy: aMatrix
-
return a copy of the receiver, which is transformed using aMatrix
** This method must be redefined in concrete classes (subclassResponsibility) **
-
translatedBy: amount
-
return a copy of the receiver which is translated (i.e. moved)
by amount, aPoint or Number
line segment:
|v l|
v := (View extent:100@100) openAndWaitUntilVisible.
l := LineSegment from:10@10 to:90@90.
v paint:Color red.
l displayStrokedOn:v.
l start:90@10 end:10@90.
v paint:Color blue.
l displayStrokedOn:v.
|
rectangle, unfilled:
|v r|
v := (View extent:100@100) openAndWaitUntilVisible.
r := Rectangle origin:10@10 corner:90@90.
v paint:Color red.
r displayStrokedOn:v.
|
circle; filled and unfilled:
|v c|
v := (View extent:200@100) openAndWaitUntilVisible.
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.
| circle & rectangle; both filled:
|v c|
v := (View extent:100@100) openAndWaitUntilVisible.
c := Circle center:50@50 radius:40.
v paint:Color red.
c asRectangle displayFilledOn:v.
v paint:Color blue.
c displayFilledOn:v.
| elliptical arcs; filled & unfilled:
|v e|
v := (View extent:200@100) openAndWaitUntilVisible.
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.
| polygon; filled & unfilled:
|v p|
v := (View extent:100@100) openAndWaitUntilVisible.
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.
|
circles; filled & unfilled:
|v c|
v := View new openAndWaitUntilVisible.
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.
]
| arcs; filled:
|v ell|
v := View new openAndWaitUntilVisible.
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.
].
| arcs; filled:
|v ell|
v := View new openAndWaitUntilVisible.
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.
].
| spline; filled & unfilled:
|v p|
v := (View extent:100@100) openAndWaitUntilVisible.
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.
|
closed spline; filled & unfilled:
|v p|
v := (View extent:100@100) openAndWaitUntilVisible.
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.
|
|