--- a/Circle.st Wed May 08 21:06:54 1996 +0200
+++ b/Circle.st Wed May 08 21:32:21 1996 +0200
@@ -42,7 +42,7 @@
Claus Gittinger
[see also:]
- EllipticalArc Spline Polygon Rectangle
+ EllipticalArc Spline Curve Polygon Rectangle
GraphicsContext
"
! !
@@ -170,5 +170,5 @@
!Circle class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Circle.st,v 1.8 1996-05-08 19:06:41 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Circle.st,v 1.9 1996-05-08 19:32:02 cg Exp $'
! !
--- a/EllArc.st Wed May 08 21:06:54 1996 +0200
+++ b/EllArc.st Wed May 08 21:32:21 1996 +0200
@@ -43,7 +43,7 @@
Claus Gittinger
[see also:]
- Circle Spline Polygon Rectangle
+ Circle Spline Curve LineSegment Polygon Rectangle
GraphicsContext
"
! !
@@ -178,5 +178,5 @@
!EllipticalArc class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Attic/EllArc.st,v 1.6 1996-05-08 18:33:27 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Attic/EllArc.st,v 1.7 1996-05-08 19:31:58 cg Exp $'
! !
--- a/EllipticalArc.st Wed May 08 21:06:54 1996 +0200
+++ b/EllipticalArc.st Wed May 08 21:32:21 1996 +0200
@@ -43,7 +43,7 @@
Claus Gittinger
[see also:]
- Circle Spline Polygon Rectangle
+ Circle Spline Curve LineSegment Polygon Rectangle
GraphicsContext
"
! !
@@ -178,5 +178,5 @@
!EllipticalArc class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/EllipticalArc.st,v 1.6 1996-05-08 18:33:27 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/EllipticalArc.st,v 1.7 1996-05-08 19:31:58 cg Exp $'
! !
--- a/LineSegment.st Wed May 08 21:06:54 1996 +0200
+++ b/LineSegment.st Wed May 08 21:32:21 1996 +0200
@@ -12,14 +12,14 @@
-Geometric subclass:#LineSegment
- instanceVariableNames:'startPoint endPoint'
+Geometric subclass:#Curve
+ instanceVariableNames:'startPoint middlePoint endPoint'
classVariableNames:''
poolDictionaries:''
category:'Graphics-Geometry'
!
-!LineSegment class methodsFor:'documentation'!
+!Curve class methodsFor:'documentation'!
copyright
"
@@ -39,57 +39,93 @@
documentation
"
- LineSegments represent a line consisting of start and endPoint
- (actually, its a vector, since the direction makes a difference when
- instances are compared using #=).
+ A Curve is a conic section determined by three points
+ that interpolates the first and the third and is tangent to the angle formed
+ by the three points at the first and third points.
[author:]
Claus Gittinger
[see also:]
- Rectangle Polygon EllipticalArc Circle Spline Point
+ Rectangle Polygon EllipticalArc Circle Spline Point LineSegment
GraphicsContext
"
-! !
-
-!LineSegment class methodsFor:'instance creation'!
-
-from:start to:end
- "return a new lineSegment."
-
- ^ self new start:start end:end
-
- "Created: 8.5.1996 / 20:40:13 / cg"
!
-with:p1 with:p2
- "return a new lineSegment; the smaller point is taken as startPoint."
+examples
+"
+ filled & unfilled:
+ [exBegin]
+ |v c|
+
+ v := (View extent:100@100) openAndWait.
+
+ c := Curve start:(20@20) middle:(80@80) end:(20@80).
+
+ v paint:Color blue.
+ c displayFilledOn:v.
+
+ v paint:Color red.
+ c displayStrokedOn:v.
+ [exEnd]
+
+ with a grid (for demonstration):
+ [exBegin]
+ |v c|
+
+ v := (View extent:200@100) openAndWait.
- p1 < p2 ifTrue:[
- self new start:p1 end:p2
- ].
- ^ self new start:p2 end:p1
+ v lineStyle:#dashed.
+ v displayLineFrom:(20@0) to:(20@200).
+ v displayLineFrom:(180@0) to:(180@200).
+
+ v displayLineFrom:(0@20) to:(200@20).
+ v displayLineFrom:(0@80) to:(200@80).
+
+ v lineStyle:#solid.
+ c := Curve start:(20@20) middle:(180@80) end:(20@80).
- "Created: 8.5.1996 / 20:41:03 / cg"
+ v paint:Color blue.
+ c displayFilledOn:v.
+
+ v paint:Color red.
+ c displayStrokedOn:v.
+
+ v paint:(Color black).
+ v displayLineFrom:(20@20) to:(180@80).
+ v displayLineFrom:(20@80) to:(180@80).
+
+ [exEnd]
+"
! !
-!LineSegment methodsFor:'accessing'!
+!Curve class methodsFor:'instance creation'!
+
+from:startPoint to:endPoint through:middlePoint
+ "return a new curve, passing through the three given points"
+
+ ^ self new start:startPoint middle:middlePoint end:endPoint
+
+ "Created: 8.5.1996 / 21:16:39 / cg"
+!
+
+start:startPoint middle:middlePoint end:endPoint
+ "return a new curve, passing through the three given points"
+
+ ^ self new start:startPoint middle:middlePoint end:endPoint
+
+ "Created: 8.5.1996 / 21:19:30 / cg"
+! !
+
+!Curve methodsFor:'accessing'!
end
"return the endPoint"
^ endPoint
- "Created: 8.5.1996 / 20:41:43 / cg"
-!
-
-end:aPoint
- "set the endPoint"
-
- endPoint := aPoint
-
- "Created: 8.5.1996 / 20:41:54 / cg"
+ "Created: 8.5.1996 / 21:08:35 / cg"
!
start
@@ -97,86 +133,89 @@
^ startPoint
- "Created: 8.5.1996 / 20:41:35 / cg"
+ "Created: 8.5.1996 / 21:08:44 / cg"
!
-start:aPoint
- "set the startPoint"
-
- startPoint := aPoint
-
- "Created: 8.5.1996 / 20:42:07 / cg"
-!
-
-start:p1 end:p2
- "set both the startPoint and the endPoint"
+start:p1 middle:p2 end:p3
+ "set the startPoint, middlePoint and the endPoint"
startPoint := p1.
- endPoint := p2.
+ middlePoint := p2.
+ endPoint := p3.
- "Created: 8.5.1996 / 20:48:32 / cg"
+ "Created: 8.5.1996 / 21:09:40 / cg"
! !
-!LineSegment methodsFor:'converting'!
-
-asPointArray
- "return an array containing my points."
-
- ^ Array with:startPoint with:endPoint
-
- "Created: 8.5.1996 / 20:46:08 / cg"
-! !
-
-!LineSegment methodsFor:'displaying'!
+!Curve methodsFor:'displaying'!
displayFilledOn:aGC
- "raise an error - a lineSegment cannot be drawn filled"
+ "draw the receiver as a filled curve in a graphicsContext, aGC"
- self shouldNotImplement
+ aGC fillPolygon:self computeLines
- "Created: 8.5.1996 / 21:04:27 / cg"
+ "Created: 8.5.1996 / 21:24:15 / cg"
+ "Modified: 8.5.1996 / 21:25:33 / cg"
!
displayStrokedOn:aGC
- "display the receiver in the graphicsContext, aGC"
-
- aGC displayLineFrom:startPoint to:endPoint
-
- "
- |v|
+ "draw the receiver as a unfilled curve in a graphicsContext, aGC"
- v := View new openAndWait.
+ aGC displayPolygon:self computeLines
- (LineSegment from:10@10 to:50@50) displayStrokedOn:v
- "
-
- "Modified: 8.5.1996 / 14:40:53 / cg"
- "Created: 8.5.1996 / 21:05:16 / cg"
+ "Modified: 8.5.1996 / 21:25:35 / cg"
! !
-!LineSegment methodsFor:'queries'!
+!Curve methodsFor:'helpers'!
+
+computeLines
+ "compute the lines which approxiamte this curve"
+
+ |lines pa pb
+ numberOfSegments "{ Class: SmallInteger }"|
+
+ lines := OrderedCollection new.
+
+ "/ Compute the number of line segments used to approximate the curve.
+ pa := middlePoint - startPoint.
+ pb := endPoint - middlePoint.
+ numberOfSegments := 5 max:pa x abs + pa y abs + pb x abs + pb y abs // 20.
+
+ "/ Add all of the points necessary for the path.
+ lines add:startPoint.
+ 1 to:numberOfSegments do:[:seg |
+ lines add:
+ ((pa * seg // numberOfSegments + startPoint) * (numberOfSegments - seg)
+ + ((pb * (seg - 1) // numberOfSegments + middlePoint) * (seg - 1)))
+ // (numberOfSegments - 1)
+ ].
+ lines add:endPoint.
+
+ ^ lines
+
+ "Created: 8.5.1996 / 21:23:29 / cg"
+! !
+
+!Curve methodsFor:'queries'!
bounds
"return the smallest enclosing rectangle"
- |minX maxX minY maxY|
+ |min max|
- minX := startPoint x min:endPoint x.
- maxX := startPoint x max:endPoint x.
- minY := startPoint y min:endPoint y.
- maxY := startPoint y max:endPoint y.
-
- ^ Rectangle left:minX right:maxX top:minY bottom:maxY
+ min := (startPoint min: endPoint) min: middlePoint.
+ max := (startPoint max: endPoint) max: middlePoint.
+ ^ min corner:max
"
- (LineSegment from:(10@10) to:(90@90)) bounds
+ (Curve from:10@10 to:50@100 through:50@50) bounds
+ (Curve from:10@10 to:50@100 through:100@50) bounds
"
- "Modified: 8.5.1996 / 20:50:03 / cg"
+ "Modified: 8.5.1996 / 21:18:50 / cg"
! !
-!LineSegment class methodsFor:'documentation'!
+!Curve class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.1 1996-05-08 19:06:02 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.2 1996-05-08 19:32:21 cg Exp $'
! !
--- a/Polygon.st Wed May 08 21:06:54 1996 +0200
+++ b/Polygon.st Wed May 08 21:32:21 1996 +0200
@@ -44,7 +44,7 @@
Claus Gittinger
[see also:]
- Rectangle EllipticalArc Spline Circle Point
+ Rectangle EllipticalArc Spline Circle Point LineSegment Curve
GraphicsContext
"
!
@@ -404,5 +404,5 @@
!Polygon class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.21 1996-05-08 19:06:54 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.22 1996-05-08 19:32:14 cg Exp $'
! !
--- a/Spline.st Wed May 08 21:06:54 1996 +0200
+++ b/Spline.st Wed May 08 21:32:21 1996 +0200
@@ -67,7 +67,7 @@
Both open and closed curves are possible.
[see also:]
- Polygon Circle EllipticalArc Rectangle
+ Polygon LineSegment Circle EllipticalArc Rectangle Curve
GraphicsContext
[author:]
@@ -514,5 +514,5 @@
!Spline class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Spline.st,v 1.5 1996-05-08 19:06:36 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Spline.st,v 1.6 1996-05-08 19:31:53 cg Exp $'
! !