"
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 Curve
Point Arrow ArrowedSpline
GraphicsContext
StrokingWrapper
"
!
examples
"
low leel use:
[exBegin]
|v l|
v := (View extent:100@100) openAndWait.
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.
[exEnd]
as component (automatic redraw):
[exBegin]
|v l|
v := View extent:100@100.
l := LineSegment from:10@10 to:90@90.
v addComponent:(StrokingWrapper on:l).
l := LineSegment from:90@10 to:10@90.
v addComponent:((StrokingWrapper on:l) foregroundColor:(Color red)).
v open.
[exEnd]
"
! !
!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:'comparing'!
= aLineSegment
"return true, if the receiver represents the same lineSegment
as the argument, aLineSegment"
aLineSegment species ~~ self species ifTrue:[^ false].
^ (startPoint = aLineSegment start
and:[endPoint = aLineSegment end])
"Created: 8.5.1996 / 22:13:02 / cg"
"Modified: 8.5.1996 / 22:14:34 / cg"
!
hash
"return a number useul for hashing.
Redefined, since #= is redefined."
^ (startPoint hash bitShift:12) bitOr:(endPoint hash)
"Modified: 8.5.1996 / 22:14:12 / 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.8 1996-05-12 23:06:28 cg Exp $'
! !