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