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