author | Claus Gittinger <cg@exept.de> |
Tue, 02 Mar 2004 09:45:25 +0100 | |
changeset 1412 | f495242466eb |
parent 1303 | 6ca5f36cdc63 |
child 1546 | db76252d4151 |
permissions | -rw-r--r-- |
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 |
||
1302 | 15 |
"{ Package: 'stx:libbasic2' }" |
16 |
||
286 | 17 |
Geometric subclass:#LineSegment |
18 |
instanceVariableNames:'startPoint endPoint' |
|
282 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
1303 | 21 |
category:'Graphics-Geometry-Objects' |
282 | 22 |
! |
23 |
||
286 | 24 |
!LineSegment class methodsFor:'documentation'! |
282 | 25 |
|
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
286 | 44 |
LineSegments represent a line consisting of start and endPoint |
45 |
(actually, its a vector, since the direction makes a difference when |
|
46 |
instances are compared using #=). |
|
282 | 47 |
|
48 |
[author:] |
|
49 |
Claus Gittinger |
|
50 |
||
51 |
[see also:] |
|
320 | 52 |
Rectangle Polygon EllipticalArc Circle Spline Curve |
331 | 53 |
Point Arrow ArrowedSpline |
282 | 54 |
GraphicsContext |
317 | 55 |
StrokingWrapper |
282 | 56 |
" |
57 |
||
317 | 58 |
! |
59 |
||
60 |
examples |
|
61 |
" |
|
319 | 62 |
low leel use: |
317 | 63 |
[exBegin] |
64 |
|v l| |
|
65 |
||
66 |
v := (View extent:100@100) openAndWait. |
|
67 |
||
68 |
l := LineSegment from:10@10 to:90@90. |
|
69 |
||
70 |
v paint:Color red. |
|
71 |
l displayStrokedOn:v. |
|
72 |
||
1302 | 73 |
l setStart:90@10 end:10@90. |
317 | 74 |
v paint:Color blue. |
75 |
l displayStrokedOn:v. |
|
76 |
[exEnd] |
|
319 | 77 |
as component (automatic redraw): |
78 |
[exBegin] |
|
79 |
|v l| |
|
80 |
||
81 |
v := View extent:100@100. |
|
82 |
||
83 |
l := LineSegment from:10@10 to:90@90. |
|
84 |
v addComponent:(StrokingWrapper on:l). |
|
85 |
||
86 |
l := LineSegment from:90@10 to:10@90. |
|
87 |
v addComponent:((StrokingWrapper on:l) foregroundColor:(Color red)). |
|
88 |
||
89 |
v open. |
|
90 |
[exEnd] |
|
317 | 91 |
" |
286 | 92 |
! ! |
93 |
||
94 |
!LineSegment class methodsFor:'instance creation'! |
|
95 |
||
96 |
from:start to:end |
|
97 |
"return a new lineSegment." |
|
98 |
||
1302 | 99 |
^ self new setStart:start end:end |
286 | 100 |
|
101 |
"Created: 8.5.1996 / 20:40:13 / cg" |
|
282 | 102 |
! |
103 |
||
286 | 104 |
with:p1 with:p2 |
105 |
"return a new lineSegment; the smaller point is taken as startPoint." |
|
282 | 106 |
|
1302 | 107 |
|l| |
108 |
||
109 |
l := self new. |
|
286 | 110 |
p1 < p2 ifTrue:[ |
1302 | 111 |
l setStart:p1 end:p2 |
112 |
] ifFalse:[ |
|
113 |
l setStart:p2 end:p1 |
|
286 | 114 |
]. |
1302 | 115 |
^ l. |
282 | 116 |
|
286 | 117 |
"Created: 8.5.1996 / 20:41:03 / cg" |
282 | 118 |
! ! |
119 |
||
286 | 120 |
!LineSegment methodsFor:'accessing'! |
282 | 121 |
|
122 |
end |
|
123 |
"return the endPoint" |
|
124 |
||
125 |
^ endPoint |
|
126 |
||
286 | 127 |
"Created: 8.5.1996 / 20:41:43 / cg" |
128 |
! |
|
129 |
||
130 |
end:aPoint |
|
131 |
"set the endPoint" |
|
132 |
||
133 |
endPoint := aPoint |
|
134 |
||
135 |
"Created: 8.5.1996 / 20:41:54 / cg" |
|
282 | 136 |
! |
137 |
||
1302 | 138 |
setStart:p1 end:p2 |
139 |
"set both the startPoint and the endPoint" |
|
140 |
||
141 |
startPoint := p1. |
|
142 |
endPoint := p2. |
|
143 |
! |
|
144 |
||
282 | 145 |
start |
146 |
"return the startPoint" |
|
147 |
||
148 |
^ startPoint |
|
149 |
||
286 | 150 |
"Created: 8.5.1996 / 20:41:35 / cg" |
282 | 151 |
! |
152 |
||
286 | 153 |
start:aPoint |
154 |
"set the startPoint" |
|
155 |
||
156 |
startPoint := aPoint |
|
157 |
||
158 |
"Created: 8.5.1996 / 20:42:07 / cg" |
|
159 |
! |
|
160 |
||
161 |
start:p1 end:p2 |
|
1302 | 162 |
"set both the startPoint and the endPoint. |
163 |
Obsolete - use setStart:end: for VW compatibility." |
|
282 | 164 |
|
1302 | 165 |
self obsoleteMethodWarning:'use #setStart:end: for VW compatibility'. |
166 |
self setStart:p1 end:p2. |
|
282 | 167 |
! ! |
168 |
||
287 | 169 |
!LineSegment methodsFor:'comparing'! |
170 |
||
171 |
= aLineSegment |
|
172 |
"return true, if the receiver represents the same lineSegment |
|
173 |
as the argument, aLineSegment" |
|
174 |
||
175 |
aLineSegment species ~~ self species ifTrue:[^ false]. |
|
176 |
^ (startPoint = aLineSegment start |
|
177 |
and:[endPoint = aLineSegment end]) |
|
178 |
||
179 |
"Created: 8.5.1996 / 22:13:02 / cg" |
|
180 |
"Modified: 8.5.1996 / 22:14:34 / cg" |
|
181 |
! |
|
182 |
||
183 |
hash |
|
184 |
"return a number useul for hashing. |
|
185 |
Redefined, since #= is redefined." |
|
186 |
||
187 |
^ (startPoint hash bitShift:12) bitOr:(endPoint hash) |
|
188 |
||
189 |
"Modified: 8.5.1996 / 22:14:12 / cg" |
|
190 |
! ! |
|
191 |
||
286 | 192 |
!LineSegment methodsFor:'converting'! |
193 |
||
194 |
asPointArray |
|
195 |
"return an array containing my points." |
|
196 |
||
197 |
^ Array with:startPoint with:endPoint |
|
198 |
||
199 |
"Created: 8.5.1996 / 20:46:08 / cg" |
|
200 |
! ! |
|
201 |
||
202 |
!LineSegment methodsFor:'displaying'! |
|
282 | 203 |
|
204 |
displayFilledOn:aGC |
|
286 | 205 |
"raise an error - a lineSegment cannot be drawn filled" |
282 | 206 |
|
286 | 207 |
self shouldNotImplement |
282 | 208 |
|
286 | 209 |
"Created: 8.5.1996 / 21:04:27 / cg" |
282 | 210 |
! |
211 |
||
212 |
displayStrokedOn:aGC |
|
286 | 213 |
"display the receiver in the graphicsContext, aGC" |
214 |
||
215 |
aGC displayLineFrom:startPoint to:endPoint |
|
216 |
||
217 |
" |
|
218 |
|v| |
|
282 | 219 |
|
286 | 220 |
v := View new openAndWait. |
282 | 221 |
|
286 | 222 |
(LineSegment from:10@10 to:50@50) displayStrokedOn:v |
223 |
" |
|
224 |
||
225 |
"Modified: 8.5.1996 / 14:40:53 / cg" |
|
226 |
"Created: 8.5.1996 / 21:05:16 / cg" |
|
282 | 227 |
! ! |
228 |
||
1412 | 229 |
!LineSegment methodsFor:'printing'! |
230 |
||
231 |
printOn:aStream |
|
232 |
aStream nextPutAll:'LineSegment from:'. |
|
233 |
startPoint printOn:aStream. |
|
234 |
aStream nextPutAll:' to:'. |
|
235 |
endPoint printOn:aStream. |
|
236 |
! ! |
|
237 |
||
286 | 238 |
!LineSegment methodsFor:'queries'! |
282 | 239 |
|
1412 | 240 |
angle |
241 |
"return the receiver's angle (in degrees) in a polar coordinate system." |
|
242 |
||
243 |
^ (endPoint - startPoint) angle |
|
244 |
||
245 |
" |
|
246 |
(LineSegment from:0@0 to:100@0) angle |
|
247 |
(LineSegment from:0@0 to:100@100) angle |
|
248 |
(LineSegment from:0@0 to:0@100) angle |
|
249 |
(LineSegment from:0@0 to:-100@100) angle |
|
250 |
(LineSegment from:0@0 to:-100@0) angle |
|
251 |
(LineSegment from:0@0 to:-100@-100) angle |
|
252 |
(LineSegment from:0@0 to:0@-100) angle |
|
253 |
" |
|
254 |
! |
|
255 |
||
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
356
diff
changeset
|
256 |
computeBounds |
282 | 257 |
"return the smallest enclosing rectangle" |
258 |
||
356 | 259 |
|x y minX maxX minY maxY| |
282 | 260 |
|
356 | 261 |
minX := maxX := startPoint x. |
262 |
x := endPoint x. |
|
263 |
minX := minX min:x. |
|
264 |
maxX := maxX max:x. |
|
265 |
||
266 |
minY := maxY := startPoint y. |
|
267 |
y := endPoint y. |
|
268 |
minY := minY min:y. |
|
269 |
maxY := maxY max:y. |
|
286 | 270 |
|
271 |
^ Rectangle left:minX right:maxX top:minY bottom:maxY |
|
282 | 272 |
|
273 |
" |
|
286 | 274 |
(LineSegment from:(10@10) to:(90@90)) bounds |
282 | 275 |
" |
276 |
||
356 | 277 |
"Modified: 26.5.1996 / 13:06:55 / cg" |
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
356
diff
changeset
|
278 |
"Created: 12.2.1997 / 11:43:50 / cg" |
1302 | 279 |
! |
280 |
||
281 |
length |
|
282 |
"return the length of the vector" |
|
283 |
||
284 |
^ startPoint dist:endPoint |
|
282 | 285 |
! ! |
286 |
||
764 | 287 |
!LineSegment methodsFor:'testing'! |
288 |
||
289 |
isLineSegment |
|
290 |
"return true, if the receiver is a line segment" |
|
291 |
||
292 |
^ true |
|
293 |
||
294 |
||
295 |
! ! |
|
296 |
||
1302 | 297 |
!LineSegment methodsFor:'transforming'! |
298 |
||
299 |
scaledBy:amount |
|
300 |
^ self species |
|
301 |
from:(startPoint scaledBy:amount) |
|
302 |
to:(endPoint scaledBy:amount) |
|
303 |
! |
|
304 |
||
305 |
translatedBy:amount |
|
306 |
^ self species |
|
307 |
from:(startPoint translatedBy:amount) |
|
308 |
to:(endPoint translatedBy:amount) |
|
309 |
! ! |
|
310 |
||
286 | 311 |
!LineSegment class methodsFor:'documentation'! |
282 | 312 |
|
313 |
version |
|
1412 | 314 |
^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.14 2004-03-02 08:45:25 cg Exp $' |
282 | 315 |
! ! |