Polygon.st
author Claus Gittinger <cg@exept.de>
Tue, 18 Dec 2018 12:52:15 +0100
changeset 4777 b22943151ce0
parent 4080 8b66d15c3473
child 4769 89914ccfcf7d
child 4837 12de5519f0b6
permissions -rw-r--r--
#DOCUMENTATION by cg class: ZipStream class comment/format in: #compress:into: #uncompress:into:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4080
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
     1
"{ Encoding: utf8 }"
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
     2
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     3
"
4
1f66800df351 *** empty log message ***
claus
parents: 2
diff changeset
     4
 COPYRIGHT (c) 1988 by Claus Gittinger
68
6650e0d50a1a *** empty log message ***
claus
parents: 36
diff changeset
     5
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     6
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    13
"
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    15
4080
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
    16
"{ NameSpace: Smalltalk }"
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
    17
78
claus
parents: 68
diff changeset
    18
Geometric subclass:#Polygon
252
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    19
	instanceVariableNames:'vertices'
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    20
	classVariableNames:''
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    21
	poolDictionaries:''
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    22
	category:'Graphics-Geometry-Objects'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    23
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    24
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    25
!Polygon class methodsFor:'documentation'!
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    26
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    27
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    28
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    29
 COPYRIGHT (c) 1988 by Claus Gittinger
68
6650e0d50a1a *** empty log message ***
claus
parents: 36
diff changeset
    30
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    31
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    32
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    33
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    35
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    36
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    37
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    38
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    39
!
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    40
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    41
documentation
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    42
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    43
    Polygon - an array of points
78
claus
parents: 68
diff changeset
    44
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    45
    Adds simple boundary checking methods to Array.
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    46
    (needs much more - such as inside check, area computation etc.)
255
69a34808bf99 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    47
69a34808bf99 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    48
    [author:]
69a34808bf99 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    49
        Claus Gittinger
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
    50
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
    51
    [see also:]
331
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    52
        Rectangle EllipticalArc Spline Circle Point LineSegment Curve
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    53
        Arrow ArroedSpline
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    54
        GraphicsContext StrokingWrapper FillingWrapper
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    55
"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    56
!
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    57
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    58
examples
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    59
"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    60
  simple polygon; filled & unfilled:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    61
                                                                        [exBegin]
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    62
    |v p|
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    63
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    64
    v := (View extent:200@200) openAndWait.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    65
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    66
    p := Polygon vertices:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    67
                (Array with:(10@10)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    68
                       with:(90@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    69
                       with:(10@90)).
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    70
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    71
    v scale:2.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    72
    v paint:Color blue.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    73
    p displayFilledOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    74
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    75
    v paint:Color red.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    76
    p displayStrokedOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    77
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    78
    v scale:1; translation:100@0.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    79
    v paint:Color green.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    80
    p displayFilledOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    81
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    82
    v paint:Color black.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    83
    p displayStrokedOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    84
                                                                        [exEnd]
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    85
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    86
  arbitrary polygon; filled & unfilled:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    87
                                                                        [exBegin]
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    88
    |v p|
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    89
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    90
    v := (View extent:200@200) openAndWait.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    91
    v scale:2.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    92
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    93
    p := Polygon vertices:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    94
                (Array with:(10@10)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    95
                       with:(90@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    96
                       with:(50@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    97
                       with:(90@10)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    98
                       with:(10@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    99
                                   ).
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   100
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   101
    v paint:Color blue.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   102
    p displayFilledOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   103
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   104
    v paint:Color red.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   105
    p displayStrokedOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   106
                                                                        [exEnd]
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
   107
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
   108
! !
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   109
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   110
!Polygon class methodsFor:'instance creation'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   111
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   112
fromRectangle:aRectangle
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   113
    "return a new polygon, taking the rectangles vertices"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   114
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   115
    ^ self new vertices:(aRectangle asPointArray)
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   116
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   117
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   118
     Polygon fromRectangle:(50@50 corner:100@100)
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   119
    "
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   120
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   121
    "Modified: 8.5.1996 / 20:15:18 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   122
!
78
claus
parents: 68
diff changeset
   123
claus
parents: 68
diff changeset
   124
vertices:anArrayOfPoints
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   125
    "return a new polygon, given a collection of vertices"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   126
78
claus
parents: 68
diff changeset
   127
    ^ self new vertices:anArrayOfPoints
claus
parents: 68
diff changeset
   128
claus
parents: 68
diff changeset
   129
    "
claus
parents: 68
diff changeset
   130
     Polygon vertices:(Array with:10@10
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   131
                             with:20@20
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   132
                             with:30@30)
78
claus
parents: 68
diff changeset
   133
1430
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   134
     Polygon vertices:(#(10 10  100 0  50 50) pairWiseCollect:[:x :y | x @ y]).
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   135
    "
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   136
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   137
    "
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   138
     |p v|
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   139
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   140
     v := View new openAndWait.
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   141
     p := Polygon 
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   142
            vertices:(Array with:10@10
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   143
                            with:20@10
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   144
                            with:20@30).
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   145
     p displayOn:v
78
claus
parents: 68
diff changeset
   146
    "
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   147
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   148
    "Modified: 8.5.1996 / 20:11:31 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   149
! !
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   150
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   151
!Polygon methodsFor:'accessing'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   152
2317
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   153
add:aPoint
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   154
    vertices isNil ifTrue:[
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   155
        vertices := OrderedCollection new
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   156
    ].
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   157
    vertices add:aPoint
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   158
!
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   159
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   160
vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   161
    "return the array containing my points"
78
claus
parents: 68
diff changeset
   162
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   163
    ^ vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   164
!
78
claus
parents: 68
diff changeset
   165
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   166
vertices:anArrayOfPoints
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   167
    "set the array containing my points"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   168
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   169
    vertices := anArrayOfPoints
78
claus
parents: 68
diff changeset
   170
! !
claus
parents: 68
diff changeset
   171
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   172
!Polygon methodsFor:'converting'!
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   173
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   174
asPointArray
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   175
    "return an array containing my vertex points.
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   176
     Notice, that no copy of my vertices is created - you should not
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   177
     modify the returned collections points (unless you want to affect
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   178
     the polygon ...)."
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   179
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   180
    ^ vertices
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   181
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   182
    "Modified: 8.5.1996 / 20:43:39 / cg"
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   183
! !
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   184
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   185
!Polygon methodsFor:'displaying'!
78
claus
parents: 68
diff changeset
   186
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   187
displayFilledOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   188
    "display a filled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   189
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   190
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   191
    aGC fillPolygon:vertices 
78
claus
parents: 68
diff changeset
   192
claus
parents: 68
diff changeset
   193
    "
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   194
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   195
     v := View new openAndWait.
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   196
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   197
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   198
          Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   199
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   200
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   201
            with:35@60)) displayFilledOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   202
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   203
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   204
     v := View new openAndWait.
78
claus
parents: 68
diff changeset
   205
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   206
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   207
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   208
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   209
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   210
            with:35@60
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   211
            with:10@10)) displayStrokedOn:v
78
claus
parents: 68
diff changeset
   212
    "
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   213
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   214
    "Modified: 8.5.1996 / 14:41:47 / cg"
78
claus
parents: 68
diff changeset
   215
!
claus
parents: 68
diff changeset
   216
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   217
displayStrokedOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   218
    "display an unfilled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   219
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   220
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   221
    aGC displayPolygon:vertices 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   222
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   223
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   224
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   225
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   226
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   227
     [v shown] whileFalse:[Processor yield].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   228
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   229
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   230
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   231
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   232
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   233
            with:35@60)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   234
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   235
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   236
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   237
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   238
     [v shown] whileFalse:[Processor yield].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   239
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   240
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   241
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   242
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   243
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   244
            with:35@60
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   245
            with:10@10)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   246
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   247
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   248
    "Modified: 27.4.1996 / 14:52:29 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   249
! !
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   250
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   251
!Polygon methodsFor:'enumerating'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   252
78
claus
parents: 68
diff changeset
   253
edgesDo:aTwoArgBlock
claus
parents: 68
diff changeset
   254
    "evaluate aTwoArgBlock for each pair of vertices"
claus
parents: 68
diff changeset
   255
claus
parents: 68
diff changeset
   256
    1 to:vertices size-1 do:[:i |
claus
parents: 68
diff changeset
   257
	aTwoArgBlock value:(vertices at:i) value:(vertices at:i+1)
claus
parents: 68
diff changeset
   258
    ].
claus
parents: 68
diff changeset
   259
claus
parents: 68
diff changeset
   260
    "
claus
parents: 68
diff changeset
   261
     |v p|
claus
parents: 68
diff changeset
   262
claus
parents: 68
diff changeset
   263
     v := View new open.
claus
parents: 68
diff changeset
   264
     [v shown] whileFalse:[Processor yield].
claus
parents: 68
diff changeset
   265
claus
parents: 68
diff changeset
   266
     p := Polygon vertices:(Array with:5@5 
claus
parents: 68
diff changeset
   267
				  with:50@5 
claus
parents: 68
diff changeset
   268
				  with:30@30
claus
parents: 68
diff changeset
   269
				  with:5@5).
claus
parents: 68
diff changeset
   270
claus
parents: 68
diff changeset
   271
     p displayOn:v.
claus
parents: 68
diff changeset
   272
     (Delay forSeconds:3) wait.
claus
parents: 68
diff changeset
   273
claus
parents: 68
diff changeset
   274
     p edgesDo:[:p1 :p2 | v lineWidth:3. v displayLineFrom:p1 to:p2] 
claus
parents: 68
diff changeset
   275
    "
claus
parents: 68
diff changeset
   276
!
claus
parents: 68
diff changeset
   277
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   278
verticesDo:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   279
    "evaluate aBlock for each point"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   280
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   281
    vertices do:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   282
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   283
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   284
     |v p|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   285
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   286
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   287
     [v shown] whileFalse:[Processor yield].
78
claus
parents: 68
diff changeset
   288
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   289
     p := Polygon vertices:(Array with:5@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   290
				  with:50@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   291
				  with:30@30
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   292
				  with:5@5).
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   293
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   294
     p displayOn:v.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   295
     (Delay forSeconds:3) wait.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   296
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   297
     p verticesDo:[:p | v displayRectangleX:p x -3  y:p y -3  width:6 height:6] 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   298
    "
78
claus
parents: 68
diff changeset
   299
! !
claus
parents: 68
diff changeset
   300
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   301
!Polygon methodsFor:'queries'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   302
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   303
bottom
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   304
    "return the bottom boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   305
     that is the maximum y coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   306
78
claus
parents: 68
diff changeset
   307
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   308
    ^ vertices inject:(vertices at:1) y into:[:maxSoFar :p | maxSoFar max:(p y)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   309
78
claus
parents: 68
diff changeset
   310
    "
claus
parents: 68
diff changeset
   311
     (Polygon vertices:(
claus
parents: 68
diff changeset
   312
	Array
claus
parents: 68
diff changeset
   313
	    with:10@10
claus
parents: 68
diff changeset
   314
	    with:60@10
claus
parents: 68
diff changeset
   315
	    with:35@60)) bottom 
claus
parents: 68
diff changeset
   316
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   317
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   318
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   319
computeBounds
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   320
    "return the smallest enclosing rectangle"
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   321
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   322
    |minX maxX minY maxY t n "{ Class: SmallInteger }" |
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   323
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   324
    n := vertices size.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   325
    n == 0 ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   326
        ^ nil    "/ mhmh - should we return an empty rectangle here ?
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   327
    ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   328
    t := vertices at:1.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   329
    minX := maxX := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   330
    minY := maxY := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   331
    2 to:n do:[:i |
4080
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
   332
        |x y|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   333
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   334
        t := vertices at:i.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   335
        x := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   336
        y := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   337
        x < minX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   338
            minX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   339
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   340
            x > maxX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   341
                maxX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   342
            ]
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   343
        ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   344
        y < minY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   345
            minY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   346
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   347
            y > maxY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   348
                maxY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   349
            ]
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   350
        ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   351
    ].
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   352
    ^ Rectangle left:minX top:minY right:maxX bottom:maxY.
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   353
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   354
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   355
     |p|
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   356
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   357
     p := (Polygon vertices:(
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   358
            Array
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   359
                with:10@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   360
                with:60@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   361
                with:35@60)).
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   362
     p bounds 
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   363
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   364
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   365
    "Modified: 8.5.1996 / 20:51:42 / cg"
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   366
    "Created: 12.2.1997 / 11:44:11 / cg"
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   367
!
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   368
2091
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   369
containsPoint:aPoint
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   370
    "return true, if the argument, aPoint is contained in the receiver"
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   371
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   372
    |angle pPrev p1 p2 angle2D|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   373
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   374
    angle2D := [:p1 :p2 |
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   375
        "/   Return the angle between two vectors on a plane
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   376
        "/   The angle is from vector 1 to vector 2, positive anticlockwise
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   377
        "/   The result is between -pi -> pi
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   378
        |theta theta1 theta2|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   379
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   380
        theta1 := p1 x arcTan2:p1 y.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   381
        theta2 := p2 x arcTan2:p2 y.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   382
        theta := theta2 - theta1.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   383
        [theta > Float pi] whileTrue:[
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   384
            theta := theta - (Float pi * 2)
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   385
        ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   386
        [ theta < (Float pi negated) ] whileTrue:[
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   387
            theta := theta + (Float pi * 2)
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   388
        ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   389
        theta
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   390
    ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   391
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   392
    angle := 0.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   393
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   394
    pPrev := vertices last.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   395
    vertices do:[:pI |
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   396
        p1 := pPrev - aPoint.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   397
        p2 := pI - aPoint.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   398
        angle := angle + (angle2D value:p1 value:p2).
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   399
        pPrev := pI.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   400
    ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   401
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   402
    ^ angle abs >= Float pi
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   403
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   404
    "
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   405
     |p|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   406
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   407
     p := Polygon vertices:(Array 
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   408
                             with:10@10
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   409
                             with:30@10
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   410
                             with:20@20).
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   411
     TestCase assert:(p containsPoint:14@11).     
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   412
     TestCase assert:(p containsPoint:15@15).     
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   413
     TestCase assert:(p containsPoint:5@15) not.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   414
     TestCase assert:(p containsPoint:15@5) not.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   415
     TestCase assert:(p containsPoint:30@15) not. 
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   416
     TestCase assert:(p containsPoint:20@15).       
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   417
    "
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   418
!
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   419
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   420
left
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   421
    "return the left boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   422
     that is the minimum x coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   423
78
claus
parents: 68
diff changeset
   424
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   425
    ^ vertices inject:(vertices at:1) x into:[:minSoFar :p | minSoFar min:(p x)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   426
78
claus
parents: 68
diff changeset
   427
    "
claus
parents: 68
diff changeset
   428
     (Polygon vertices:(
claus
parents: 68
diff changeset
   429
	Array
claus
parents: 68
diff changeset
   430
	    with:10@10
claus
parents: 68
diff changeset
   431
	    with:60@10
claus
parents: 68
diff changeset
   432
	    with:35@60)) left  
claus
parents: 68
diff changeset
   433
    "
claus
parents: 68
diff changeset
   434
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   435
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   436
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   437
right
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   438
    "return the right boundary of the polygon,
88
claus
parents: 85
diff changeset
   439
     that is the maximum x coordinate of all its points"
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   440
78
claus
parents: 68
diff changeset
   441
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   442
    ^ vertices inject:(vertices at:1) x into:[:maxSoFar :p | maxSoFar max:(p x)]
claus
parents: 68
diff changeset
   443
claus
parents: 68
diff changeset
   444
    "
claus
parents: 68
diff changeset
   445
     (Polygon vertices:(
claus
parents: 68
diff changeset
   446
	Array
claus
parents: 68
diff changeset
   447
	    with:10@10
claus
parents: 68
diff changeset
   448
	    with:60@10
claus
parents: 68
diff changeset
   449
	    with:35@60)) right  
claus
parents: 68
diff changeset
   450
    "
claus
parents: 68
diff changeset
   451
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   452
!
78
claus
parents: 68
diff changeset
   453
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   454
top
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   455
    "return the top boundary of the polygon,
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   456
     that is the minimum y coordinate of all its points"
78
claus
parents: 68
diff changeset
   457
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   458
    (vertices size == 0) ifTrue: [^ nil].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   459
    ^ vertices inject:(vertices at:1) y into:[:minSoFar :p | minSoFar min:(p y)]
78
claus
parents: 68
diff changeset
   460
claus
parents: 68
diff changeset
   461
    "
claus
parents: 68
diff changeset
   462
     (Polygon vertices:(
claus
parents: 68
diff changeset
   463
	Array
claus
parents: 68
diff changeset
   464
	    with:10@10
claus
parents: 68
diff changeset
   465
	    with:60@10
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   466
	    with:35@60)) top  
78
claus
parents: 68
diff changeset
   467
    "
claus
parents: 68
diff changeset
   468
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   469
! !
78
claus
parents: 68
diff changeset
   470
2158
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   471
!Polygon methodsFor:'testing'!
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   472
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   473
canBeFilled
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   474
    "return true, if the receiver can be drawn as a filled geometric.
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   475
     Always true here."
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   476
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   477
    ^ true
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   478
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   479
    "Created: 8.5.1996 / 08:16:53 / cg"
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   480
! !
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   481
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   482
!Polygon class methodsFor:'documentation'!
78
claus
parents: 68
diff changeset
   483
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   484
version
4080
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
   485
    ^ '$Header$'
2317
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   486
!
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   487
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   488
version_CVS
4080
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
   489
    ^ '$Header$'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   490
! !
4080
8b66d15c3473 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 2317
diff changeset
   491