LineSegment.st
changeset 286 09da374b5438
parent 284 1b272ff61339
child 287 779c959ab8f4
--- a/LineSegment.st	Wed May 08 21:33:53 1996 +0200
+++ b/LineSegment.st	Wed May 08 21:35:46 1996 +0200
@@ -10,16 +10,14 @@
  hereby transferred.
 "
 
-
-
-Geometric subclass:#Curve
-	instanceVariableNames:'startPoint middlePoint endPoint'
+Geometric subclass:#LineSegment
+	instanceVariableNames:'startPoint endPoint'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Graphics-Geometry'
 !
 
-!Curve class methodsFor:'documentation'!
+!LineSegment class methodsFor:'documentation'!
 
 copyright
 "
@@ -39,93 +37,57 @@
 
 documentation
 "
-    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.
+    LineSegments represent a line consisting of start and endPoint
+    (actually, its a vector, since the direction makes a difference when
+     instances are compared using #=).
 
     [author:]
         Claus Gittinger
 
     [see also:]
-        Rectangle Polygon EllipticalArc Circle Spline Point LineSegment
+        Rectangle Polygon EllipticalArc Circle Spline Curve Point
         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"
 !
 
-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.
+with:p1 with:p2
+    "return a new lineSegment; the smaller point is taken as startPoint."
 
-    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).
+    p1 < p2 ifTrue:[
+        self new start:p1 end:p2
+    ].
+    ^ self new start:p2 end:p1
 
-    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]
-"
+    "Created: 8.5.1996 / 20:41:03 / cg"
 ! !
 
-!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'!
+!LineSegment methodsFor:'accessing'!
 
 end
     "return the endPoint"
 
     ^ endPoint
 
-    "Created: 8.5.1996 / 21:08:35 / cg"
+    "Created: 8.5.1996 / 20:41:43 / cg"
+!
+
+end:aPoint
+    "set the endPoint"
+
+    endPoint := aPoint
+
+    "Created: 8.5.1996 / 20:41:54 / cg"
 !
 
 start
@@ -133,89 +95,86 @@
 
     ^ startPoint
 
-    "Created: 8.5.1996 / 21:08:44 / cg"
+    "Created: 8.5.1996 / 20:41:35 / cg"
 !
 
-start:p1 middle:p2 end:p3
-    "set the startPoint, middlePoint and the endPoint"
+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"
 
     startPoint := p1.
-    middlePoint := p2.
-    endPoint := p3.
+    endPoint := p2.
 
-    "Created: 8.5.1996 / 21:09:40 / cg"
+    "Created: 8.5.1996 / 20:48:32 / cg"
 ! !
 
-!Curve methodsFor:'displaying'!
+!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'!
 
 displayFilledOn:aGC
-    "draw the receiver as a filled curve in a graphicsContext, aGC"
+    "raise an error - a lineSegment cannot be drawn filled"
 
-    aGC fillPolygon:self computeLines
+    self shouldNotImplement
 
-    "Created: 8.5.1996 / 21:24:15 / cg"
-    "Modified: 8.5.1996 / 21:25:33 / cg"
+    "Created: 8.5.1996 / 21:04:27 / cg"
 !
 
 displayStrokedOn:aGC
-    "draw the receiver as a unfilled curve in a graphicsContext, aGC"
+    "display the receiver in the graphicsContext, aGC"
+
+    aGC displayLineFrom:startPoint to:endPoint
+
+    "
+     |v|
 
-    aGC displayPolygon:self computeLines
+     v := View new openAndWait.
 
-    "Modified: 8.5.1996 / 21:25:35 / cg"
+     (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"
 ! !
 
-!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'!
+!LineSegment methodsFor:'queries'!
 
 bounds
     "return the smallest enclosing rectangle"
 
-    |min max|
+    |minX maxX minY maxY|
 
-    min := (startPoint min: endPoint) min: middlePoint.
-    max := (startPoint max: endPoint) max: middlePoint.
-    ^ min corner: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
 
     "
-     (Curve from:10@10 to:50@100 through:50@50) bounds   
-     (Curve from:10@10 to:50@100 through:100@50) bounds 
+     (LineSegment from:(10@10) to:(90@90)) bounds 
     "
 
-    "Modified: 8.5.1996 / 21:18:50 / cg"
+    "Modified: 8.5.1996 / 20:50:03 / cg"
 ! !
 
-!Curve class methodsFor:'documentation'!
+!LineSegment class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.2 1996-05-08 19:32:21 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.3 1996-05-08 19:35:46 cg Exp $'
 ! !