282
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
287
|
13 |
|
|
14 |
|
286
|
15 |
Geometric subclass:#LineSegment
|
|
16 |
instanceVariableNames:'startPoint endPoint'
|
282
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Graphics-Geometry'
|
|
20 |
!
|
|
21 |
|
286
|
22 |
!LineSegment class methodsFor:'documentation'!
|
282
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1996 by Claus Gittinger
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
|
|
37 |
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
286
|
42 |
LineSegments represent a line consisting of start and endPoint
|
|
43 |
(actually, its a vector, since the direction makes a difference when
|
|
44 |
instances are compared using #=).
|
282
|
45 |
|
|
46 |
[author:]
|
|
47 |
Claus Gittinger
|
|
48 |
|
|
49 |
[see also:]
|
286
|
50 |
Rectangle Polygon EllipticalArc Circle Spline Curve Point
|
282
|
51 |
GraphicsContext
|
|
52 |
"
|
|
53 |
|
286
|
54 |
! !
|
|
55 |
|
|
56 |
!LineSegment class methodsFor:'instance creation'!
|
|
57 |
|
|
58 |
from:start to:end
|
|
59 |
"return a new lineSegment."
|
|
60 |
|
|
61 |
^ self new start:start end:end
|
|
62 |
|
|
63 |
"Created: 8.5.1996 / 20:40:13 / cg"
|
282
|
64 |
!
|
|
65 |
|
286
|
66 |
with:p1 with:p2
|
|
67 |
"return a new lineSegment; the smaller point is taken as startPoint."
|
282
|
68 |
|
286
|
69 |
p1 < p2 ifTrue:[
|
|
70 |
self new start:p1 end:p2
|
|
71 |
].
|
|
72 |
^ self new start:p2 end:p1
|
282
|
73 |
|
286
|
74 |
"Created: 8.5.1996 / 20:41:03 / cg"
|
282
|
75 |
! !
|
|
76 |
|
286
|
77 |
!LineSegment methodsFor:'accessing'!
|
282
|
78 |
|
|
79 |
end
|
|
80 |
"return the endPoint"
|
|
81 |
|
|
82 |
^ endPoint
|
|
83 |
|
286
|
84 |
"Created: 8.5.1996 / 20:41:43 / cg"
|
|
85 |
!
|
|
86 |
|
|
87 |
end:aPoint
|
|
88 |
"set the endPoint"
|
|
89 |
|
|
90 |
endPoint := aPoint
|
|
91 |
|
|
92 |
"Created: 8.5.1996 / 20:41:54 / cg"
|
282
|
93 |
!
|
|
94 |
|
|
95 |
start
|
|
96 |
"return the startPoint"
|
|
97 |
|
|
98 |
^ startPoint
|
|
99 |
|
286
|
100 |
"Created: 8.5.1996 / 20:41:35 / cg"
|
282
|
101 |
!
|
|
102 |
|
286
|
103 |
start:aPoint
|
|
104 |
"set the startPoint"
|
|
105 |
|
|
106 |
startPoint := aPoint
|
|
107 |
|
|
108 |
"Created: 8.5.1996 / 20:42:07 / cg"
|
|
109 |
!
|
|
110 |
|
|
111 |
start:p1 end:p2
|
|
112 |
"set both the startPoint and the endPoint"
|
282
|
113 |
|
|
114 |
startPoint := p1.
|
286
|
115 |
endPoint := p2.
|
282
|
116 |
|
286
|
117 |
"Created: 8.5.1996 / 20:48:32 / cg"
|
282
|
118 |
! !
|
|
119 |
|
287
|
120 |
!LineSegment methodsFor:'comparing'!
|
|
121 |
|
|
122 |
= aLineSegment
|
|
123 |
"return true, if the receiver represents the same lineSegment
|
|
124 |
as the argument, aLineSegment"
|
|
125 |
|
|
126 |
aLineSegment species ~~ self species ifTrue:[^ false].
|
|
127 |
^ (startPoint = aLineSegment start
|
|
128 |
and:[endPoint = aLineSegment end])
|
|
129 |
|
|
130 |
"Created: 8.5.1996 / 22:13:02 / cg"
|
|
131 |
"Modified: 8.5.1996 / 22:14:34 / cg"
|
|
132 |
!
|
|
133 |
|
|
134 |
hash
|
|
135 |
"return a number useul for hashing.
|
|
136 |
Redefined, since #= is redefined."
|
|
137 |
|
|
138 |
^ (startPoint hash bitShift:12) bitOr:(endPoint hash)
|
|
139 |
|
|
140 |
"Modified: 8.5.1996 / 22:14:12 / cg"
|
|
141 |
! !
|
|
142 |
|
286
|
143 |
!LineSegment methodsFor:'converting'!
|
|
144 |
|
|
145 |
asPointArray
|
|
146 |
"return an array containing my points."
|
|
147 |
|
|
148 |
^ Array with:startPoint with:endPoint
|
|
149 |
|
|
150 |
"Created: 8.5.1996 / 20:46:08 / cg"
|
|
151 |
! !
|
|
152 |
|
|
153 |
!LineSegment methodsFor:'displaying'!
|
282
|
154 |
|
|
155 |
displayFilledOn:aGC
|
286
|
156 |
"raise an error - a lineSegment cannot be drawn filled"
|
282
|
157 |
|
286
|
158 |
self shouldNotImplement
|
282
|
159 |
|
286
|
160 |
"Created: 8.5.1996 / 21:04:27 / cg"
|
282
|
161 |
!
|
|
162 |
|
|
163 |
displayStrokedOn:aGC
|
286
|
164 |
"display the receiver in the graphicsContext, aGC"
|
|
165 |
|
|
166 |
aGC displayLineFrom:startPoint to:endPoint
|
|
167 |
|
|
168 |
"
|
|
169 |
|v|
|
282
|
170 |
|
286
|
171 |
v := View new openAndWait.
|
282
|
172 |
|
286
|
173 |
(LineSegment from:10@10 to:50@50) displayStrokedOn:v
|
|
174 |
"
|
|
175 |
|
|
176 |
"Modified: 8.5.1996 / 14:40:53 / cg"
|
|
177 |
"Created: 8.5.1996 / 21:05:16 / cg"
|
282
|
178 |
! !
|
|
179 |
|
286
|
180 |
!LineSegment methodsFor:'queries'!
|
282
|
181 |
|
|
182 |
bounds
|
|
183 |
"return the smallest enclosing rectangle"
|
|
184 |
|
286
|
185 |
|minX maxX minY maxY|
|
282
|
186 |
|
286
|
187 |
minX := startPoint x min:endPoint x.
|
|
188 |
maxX := startPoint x max:endPoint x.
|
|
189 |
minY := startPoint y min:endPoint y.
|
|
190 |
maxY := startPoint y max:endPoint y.
|
|
191 |
|
|
192 |
^ Rectangle left:minX right:maxX top:minY bottom:maxY
|
282
|
193 |
|
|
194 |
"
|
286
|
195 |
(LineSegment from:(10@10) to:(90@90)) bounds
|
282
|
196 |
"
|
|
197 |
|
286
|
198 |
"Modified: 8.5.1996 / 20:50:03 / cg"
|
282
|
199 |
! !
|
|
200 |
|
286
|
201 |
!LineSegment class methodsFor:'documentation'!
|
282
|
202 |
|
|
203 |
version
|
287
|
204 |
^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.4 1996-05-08 20:16:09 cg Exp $'
|
282
|
205 |
! !
|