intitial checkin
authorClaus Gittinger <cg@exept.de>
Wed, 08 May 1996 21:06:02 +0200
changeset 282 f2f29344e676
parent 281 344857a33c20
child 283 59a8cfbc1e5e
intitial checkin
LineSegment.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LineSegment.st	Wed May 08 21:06:02 1996 +0200
@@ -0,0 +1,182 @@
+"
+ COPYRIGHT (c) 1996 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.
+"
+
+
+
+Geometric subclass:#LineSegment
+	instanceVariableNames:'startPoint endPoint'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Graphics-Geometry'
+!
+
+!LineSegment class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1996 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
+"
+    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
+        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."
+
+    p1 < p2 ifTrue:[
+        self new start:p1 end:p2
+    ].
+    ^ self new start:p2 end:p1
+
+    "Created: 8.5.1996 / 20:41:03 / cg"
+! !
+
+!LineSegment 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"
+!
+
+start
+    "return the startPoint"
+
+    ^ startPoint
+
+    "Created: 8.5.1996 / 20:41:35 / 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"
+
+    startPoint := p1.
+    endPoint := p2.
+
+    "Created: 8.5.1996 / 20:48:32 / 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'!
+
+displayFilledOn:aGC
+    "raise an error - a lineSegment cannot be drawn filled"
+
+    self shouldNotImplement
+
+    "Created: 8.5.1996 / 21:04:27 / cg"
+!
+
+displayStrokedOn:aGC
+    "display the receiver in the graphicsContext, aGC"
+
+    aGC displayLineFrom:startPoint to:endPoint
+
+    "
+     |v|
+
+     v := View new openAndWait.
+
+     (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"
+! !
+
+!LineSegment methodsFor:'queries'!
+
+bounds
+    "return the smallest enclosing rectangle"
+
+    |minX maxX minY maxY|
+
+    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
+
+    "
+     (LineSegment from:(10@10) to:(90@90)) bounds 
+    "
+
+    "Modified: 8.5.1996 / 20:50:03 / cg"
+! !
+
+!LineSegment class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.1 1996-05-08 19:06:02 cg Exp $'
+! !