author | Claus Gittinger <cg@exept.de> |
Thu, 08 Jul 1999 18:14:43 +0200 | |
changeset 764 | 89df81c57e5b |
parent 490 | ef43c7a69346 |
child 1302 | 995effeb0c8b |
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 |
||
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:] |
|
320 | 50 |
Rectangle Polygon EllipticalArc Circle Spline Curve |
331 | 51 |
Point Arrow ArrowedSpline |
282 | 52 |
GraphicsContext |
317 | 53 |
StrokingWrapper |
282 | 54 |
" |
55 |
||
317 | 56 |
! |
57 |
||
58 |
examples |
|
59 |
" |
|
319 | 60 |
low leel use: |
317 | 61 |
[exBegin] |
62 |
|v l| |
|
63 |
||
64 |
v := (View extent:100@100) openAndWait. |
|
65 |
||
66 |
l := LineSegment from:10@10 to:90@90. |
|
67 |
||
68 |
v paint:Color red. |
|
69 |
l displayStrokedOn:v. |
|
70 |
||
71 |
l start:90@10 end:10@90. |
|
72 |
v paint:Color blue. |
|
73 |
l displayStrokedOn:v. |
|
74 |
[exEnd] |
|
319 | 75 |
as component (automatic redraw): |
76 |
[exBegin] |
|
77 |
|v l| |
|
78 |
||
79 |
v := View extent:100@100. |
|
80 |
||
81 |
l := LineSegment from:10@10 to:90@90. |
|
82 |
v addComponent:(StrokingWrapper on:l). |
|
83 |
||
84 |
l := LineSegment from:90@10 to:10@90. |
|
85 |
v addComponent:((StrokingWrapper on:l) foregroundColor:(Color red)). |
|
86 |
||
87 |
v open. |
|
88 |
[exEnd] |
|
317 | 89 |
" |
286 | 90 |
! ! |
91 |
||
92 |
!LineSegment class methodsFor:'instance creation'! |
|
93 |
||
94 |
from:start to:end |
|
95 |
"return a new lineSegment." |
|
96 |
||
97 |
^ self new start:start end:end |
|
98 |
||
99 |
"Created: 8.5.1996 / 20:40:13 / cg" |
|
282 | 100 |
! |
101 |
||
286 | 102 |
with:p1 with:p2 |
103 |
"return a new lineSegment; the smaller point is taken as startPoint." |
|
282 | 104 |
|
286 | 105 |
p1 < p2 ifTrue:[ |
106 |
self new start:p1 end:p2 |
|
107 |
]. |
|
108 |
^ self new start:p2 end:p1 |
|
282 | 109 |
|
286 | 110 |
"Created: 8.5.1996 / 20:41:03 / cg" |
282 | 111 |
! ! |
112 |
||
286 | 113 |
!LineSegment methodsFor:'accessing'! |
282 | 114 |
|
115 |
end |
|
116 |
"return the endPoint" |
|
117 |
||
118 |
^ endPoint |
|
119 |
||
286 | 120 |
"Created: 8.5.1996 / 20:41:43 / cg" |
121 |
! |
|
122 |
||
123 |
end:aPoint |
|
124 |
"set the endPoint" |
|
125 |
||
126 |
endPoint := aPoint |
|
127 |
||
128 |
"Created: 8.5.1996 / 20:41:54 / cg" |
|
282 | 129 |
! |
130 |
||
131 |
start |
|
132 |
"return the startPoint" |
|
133 |
||
134 |
^ startPoint |
|
135 |
||
286 | 136 |
"Created: 8.5.1996 / 20:41:35 / cg" |
282 | 137 |
! |
138 |
||
286 | 139 |
start:aPoint |
140 |
"set the startPoint" |
|
141 |
||
142 |
startPoint := aPoint |
|
143 |
||
144 |
"Created: 8.5.1996 / 20:42:07 / cg" |
|
145 |
! |
|
146 |
||
147 |
start:p1 end:p2 |
|
148 |
"set both the startPoint and the endPoint" |
|
282 | 149 |
|
150 |
startPoint := p1. |
|
286 | 151 |
endPoint := p2. |
282 | 152 |
|
286 | 153 |
"Created: 8.5.1996 / 20:48:32 / cg" |
282 | 154 |
! ! |
155 |
||
287 | 156 |
!LineSegment methodsFor:'comparing'! |
157 |
||
158 |
= aLineSegment |
|
159 |
"return true, if the receiver represents the same lineSegment |
|
160 |
as the argument, aLineSegment" |
|
161 |
||
162 |
aLineSegment species ~~ self species ifTrue:[^ false]. |
|
163 |
^ (startPoint = aLineSegment start |
|
164 |
and:[endPoint = aLineSegment end]) |
|
165 |
||
166 |
"Created: 8.5.1996 / 22:13:02 / cg" |
|
167 |
"Modified: 8.5.1996 / 22:14:34 / cg" |
|
168 |
! |
|
169 |
||
170 |
hash |
|
171 |
"return a number useul for hashing. |
|
172 |
Redefined, since #= is redefined." |
|
173 |
||
174 |
^ (startPoint hash bitShift:12) bitOr:(endPoint hash) |
|
175 |
||
176 |
"Modified: 8.5.1996 / 22:14:12 / cg" |
|
177 |
! ! |
|
178 |
||
286 | 179 |
!LineSegment methodsFor:'converting'! |
180 |
||
181 |
asPointArray |
|
182 |
"return an array containing my points." |
|
183 |
||
184 |
^ Array with:startPoint with:endPoint |
|
185 |
||
186 |
"Created: 8.5.1996 / 20:46:08 / cg" |
|
187 |
! ! |
|
188 |
||
189 |
!LineSegment methodsFor:'displaying'! |
|
282 | 190 |
|
191 |
displayFilledOn:aGC |
|
286 | 192 |
"raise an error - a lineSegment cannot be drawn filled" |
282 | 193 |
|
286 | 194 |
self shouldNotImplement |
282 | 195 |
|
286 | 196 |
"Created: 8.5.1996 / 21:04:27 / cg" |
282 | 197 |
! |
198 |
||
199 |
displayStrokedOn:aGC |
|
286 | 200 |
"display the receiver in the graphicsContext, aGC" |
201 |
||
202 |
aGC displayLineFrom:startPoint to:endPoint |
|
203 |
||
204 |
" |
|
205 |
|v| |
|
282 | 206 |
|
286 | 207 |
v := View new openAndWait. |
282 | 208 |
|
286 | 209 |
(LineSegment from:10@10 to:50@50) displayStrokedOn:v |
210 |
" |
|
211 |
||
212 |
"Modified: 8.5.1996 / 14:40:53 / cg" |
|
213 |
"Created: 8.5.1996 / 21:05:16 / cg" |
|
282 | 214 |
! ! |
215 |
||
286 | 216 |
!LineSegment methodsFor:'queries'! |
282 | 217 |
|
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
356
diff
changeset
|
218 |
computeBounds |
282 | 219 |
"return the smallest enclosing rectangle" |
220 |
||
356 | 221 |
|x y minX maxX minY maxY| |
282 | 222 |
|
356 | 223 |
minX := maxX := startPoint x. |
224 |
x := endPoint x. |
|
225 |
minX := minX min:x. |
|
226 |
maxX := maxX max:x. |
|
227 |
||
228 |
minY := maxY := startPoint y. |
|
229 |
y := endPoint y. |
|
230 |
minY := minY min:y. |
|
231 |
maxY := maxY max:y. |
|
286 | 232 |
|
233 |
^ Rectangle left:minX right:maxX top:minY bottom:maxY |
|
282 | 234 |
|
235 |
" |
|
286 | 236 |
(LineSegment from:(10@10) to:(90@90)) bounds |
282 | 237 |
" |
238 |
||
356 | 239 |
"Modified: 26.5.1996 / 13:06:55 / cg" |
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
356
diff
changeset
|
240 |
"Created: 12.2.1997 / 11:43:50 / cg" |
282 | 241 |
! ! |
242 |
||
764 | 243 |
!LineSegment methodsFor:'testing'! |
244 |
||
245 |
isLineSegment |
|
246 |
"return true, if the receiver is a line segment" |
|
247 |
||
248 |
^ true |
|
249 |
||
250 |
||
251 |
! ! |
|
252 |
||
286 | 253 |
!LineSegment class methodsFor:'documentation'! |
282 | 254 |
|
255 |
version |
|
764 | 256 |
^ '$Header: /cvs/stx/stx/libbasic2/LineSegment.st,v 1.11 1999-07-08 16:14:43 cg Exp $' |
282 | 257 |
! ! |