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