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