Polygon.st
author Claus Gittinger <cg@exept.de>
Thu, 06 Sep 2007 17:31:09 +0200
changeset 1894 8bf137acc445
parent 1430 baf6bfed6d56
child 2091 24965fa2be83
permissions -rw-r--r--
if no unit is given in the readString, assume seconds.
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
1430
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   131
     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
   132
    "
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   133
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   134
    "
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   135
     |p v|
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
     v := View new openAndWait.
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   138
     p := Polygon 
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   139
            vertices:(Array with:10@10
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   140
                            with:20@10
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   141
                            with:20@30).
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   142
     p displayOn:v
78
claus
parents: 68
diff changeset
   143
    "
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   144
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   145
    "Modified: 8.5.1996 / 20:11:31 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   146
! !
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
!Polygon methodsFor:'accessing'!
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
vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   151
    "return the array containing my points"
78
claus
parents: 68
diff changeset
   152
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   153
    ^ vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   154
!
78
claus
parents: 68
diff changeset
   155
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   156
vertices:anArrayOfPoints
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   157
    "set the array containing my points"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   158
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   159
    vertices := anArrayOfPoints
78
claus
parents: 68
diff changeset
   160
! !
claus
parents: 68
diff changeset
   161
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   162
!Polygon methodsFor:'converting'!
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   163
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   164
asPointArray
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   165
    "return an array containing my vertex points.
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   166
     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
   167
     modify the returned collections points (unless you want to affect
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   168
     the polygon ...)."
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   169
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   170
    ^ vertices
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   171
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   172
    "Modified: 8.5.1996 / 20:43:39 / cg"
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
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   175
!Polygon methodsFor:'displaying'!
78
claus
parents: 68
diff changeset
   176
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   177
displayFilledOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   178
    "display a filled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   179
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   180
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   181
    aGC fillPolygon:vertices 
78
claus
parents: 68
diff changeset
   182
claus
parents: 68
diff changeset
   183
    "
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   184
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   185
     v := View new openAndWait.
135
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
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   188
          Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   189
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   190
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   191
            with:35@60)) displayFilledOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   192
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   193
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   194
     v := View new openAndWait.
78
claus
parents: 68
diff changeset
   195
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   196
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   197
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   198
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   199
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   200
            with:35@60
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   201
            with:10@10)) displayStrokedOn:v
78
claus
parents: 68
diff changeset
   202
    "
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   203
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   204
    "Modified: 8.5.1996 / 14:41:47 / cg"
78
claus
parents: 68
diff changeset
   205
!
claus
parents: 68
diff changeset
   206
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   207
displayStrokedOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   208
    "display an unfilled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   209
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   210
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   211
    aGC displayPolygon:vertices 
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
     |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)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   224
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   225
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   226
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   227
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   228
     [v shown] whileFalse:[Processor yield].
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 vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   231
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   232
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   233
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   234
            with:35@60
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   235
            with:10@10)) displayStrokedOn:v
135
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
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   238
    "Modified: 27.4.1996 / 14:52:29 / cg"
135
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
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   241
!Polygon methodsFor:'enumerating'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   242
78
claus
parents: 68
diff changeset
   243
edgesDo:aTwoArgBlock
claus
parents: 68
diff changeset
   244
    "evaluate aTwoArgBlock for each pair of vertices"
claus
parents: 68
diff changeset
   245
claus
parents: 68
diff changeset
   246
    1 to:vertices size-1 do:[:i |
claus
parents: 68
diff changeset
   247
	aTwoArgBlock value:(vertices at:i) value:(vertices at:i+1)
claus
parents: 68
diff changeset
   248
    ].
claus
parents: 68
diff changeset
   249
claus
parents: 68
diff changeset
   250
    "
claus
parents: 68
diff changeset
   251
     |v p|
claus
parents: 68
diff changeset
   252
claus
parents: 68
diff changeset
   253
     v := View new open.
claus
parents: 68
diff changeset
   254
     [v shown] whileFalse:[Processor yield].
claus
parents: 68
diff changeset
   255
claus
parents: 68
diff changeset
   256
     p := Polygon vertices:(Array with:5@5 
claus
parents: 68
diff changeset
   257
				  with:50@5 
claus
parents: 68
diff changeset
   258
				  with:30@30
claus
parents: 68
diff changeset
   259
				  with:5@5).
claus
parents: 68
diff changeset
   260
claus
parents: 68
diff changeset
   261
     p displayOn:v.
claus
parents: 68
diff changeset
   262
     (Delay forSeconds:3) wait.
claus
parents: 68
diff changeset
   263
claus
parents: 68
diff changeset
   264
     p edgesDo:[:p1 :p2 | v lineWidth:3. v displayLineFrom:p1 to:p2] 
claus
parents: 68
diff changeset
   265
    "
claus
parents: 68
diff changeset
   266
!
claus
parents: 68
diff changeset
   267
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   268
verticesDo:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   269
    "evaluate aBlock for each point"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   270
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   271
    vertices do:aBlock
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
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   274
     |v p|
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
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   277
     [v shown] whileFalse:[Processor yield].
78
claus
parents: 68
diff changeset
   278
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   279
     p := Polygon vertices:(Array with:5@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   280
				  with:50@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   281
				  with:30@30
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   282
				  with:5@5).
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
     p displayOn:v.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   285
     (Delay forSeconds:3) wait.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   286
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   287
     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
   288
    "
78
claus
parents: 68
diff changeset
   289
! !
claus
parents: 68
diff changeset
   290
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   291
!Polygon methodsFor:'queries'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   292
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   293
bottom
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   294
    "return the bottom boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   295
     that is the maximum y coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   296
78
claus
parents: 68
diff changeset
   297
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   298
    ^ vertices inject:(vertices at:1) y into:[:maxSoFar :p | maxSoFar max:(p y)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   299
78
claus
parents: 68
diff changeset
   300
    "
claus
parents: 68
diff changeset
   301
     (Polygon vertices:(
claus
parents: 68
diff changeset
   302
	Array
claus
parents: 68
diff changeset
   303
	    with:10@10
claus
parents: 68
diff changeset
   304
	    with:60@10
claus
parents: 68
diff changeset
   305
	    with:35@60)) bottom 
claus
parents: 68
diff changeset
   306
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   307
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   308
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   309
canBeFilled
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   310
    "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
   311
     Always true here."
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   312
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   313
    ^ true
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   314
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   315
    "Created: 8.5.1996 / 08:16:53 / cg"
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   316
!
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   317
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   318
computeBounds
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   319
    "return the smallest enclosing rectangle"
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   320
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   321
    |minX maxX minY maxY t n "{ Class: SmallInteger }" |
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   322
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   323
    n := vertices size.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   324
    n == 0 ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   325
        ^ nil    "/ mhmh - should we return an empty rectangle here ?
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
    t := vertices at:1.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   328
    minX := maxX := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   329
    minY := maxY := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   330
    2 to:n do:[:i |
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   331
        |x y t|
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   332
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   333
        t := vertices at:i.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   334
        x := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   335
        y := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   336
        x < minX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   337
            minX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   338
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   339
            x > maxX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   340
                maxX := x.
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
        y < minY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   344
            minY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   345
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   346
            y > maxY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   347
                maxY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   348
            ]
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
    ].
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   351
    ^ Rectangle left:minX top:minY right:maxX bottom:maxY.
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   352
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
     |p|
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
     p := (Polygon vertices:(
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   357
            Array
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   358
                with:10@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   359
                with:60@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   360
                with:35@60)).
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   361
     p bounds 
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   362
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   363
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   364
    "Modified: 8.5.1996 / 20:51:42 / cg"
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   365
    "Created: 12.2.1997 / 11:44:11 / cg"
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   366
!
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   367
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   368
left
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   369
    "return the left boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   370
     that is the minimum x coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   371
78
claus
parents: 68
diff changeset
   372
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   373
    ^ vertices inject:(vertices at:1) x into:[:minSoFar :p | minSoFar min:(p x)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   374
78
claus
parents: 68
diff changeset
   375
    "
claus
parents: 68
diff changeset
   376
     (Polygon vertices:(
claus
parents: 68
diff changeset
   377
	Array
claus
parents: 68
diff changeset
   378
	    with:10@10
claus
parents: 68
diff changeset
   379
	    with:60@10
claus
parents: 68
diff changeset
   380
	    with:35@60)) left  
claus
parents: 68
diff changeset
   381
    "
claus
parents: 68
diff changeset
   382
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   383
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   384
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   385
right
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   386
    "return the right boundary of the polygon,
88
claus
parents: 85
diff changeset
   387
     that is the maximum x coordinate of all its points"
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   388
78
claus
parents: 68
diff changeset
   389
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   390
    ^ vertices inject:(vertices at:1) x into:[:maxSoFar :p | maxSoFar max:(p x)]
claus
parents: 68
diff changeset
   391
claus
parents: 68
diff changeset
   392
    "
claus
parents: 68
diff changeset
   393
     (Polygon vertices:(
claus
parents: 68
diff changeset
   394
	Array
claus
parents: 68
diff changeset
   395
	    with:10@10
claus
parents: 68
diff changeset
   396
	    with:60@10
claus
parents: 68
diff changeset
   397
	    with:35@60)) right  
claus
parents: 68
diff changeset
   398
    "
claus
parents: 68
diff changeset
   399
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   400
!
78
claus
parents: 68
diff changeset
   401
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   402
top
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   403
    "return the top boundary of the polygon,
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   404
     that is the minimum y coordinate of all its points"
78
claus
parents: 68
diff changeset
   405
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   406
    (vertices size == 0) ifTrue: [^ nil].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   407
    ^ vertices inject:(vertices at:1) y into:[:minSoFar :p | minSoFar min:(p y)]
78
claus
parents: 68
diff changeset
   408
claus
parents: 68
diff changeset
   409
    "
claus
parents: 68
diff changeset
   410
     (Polygon vertices:(
claus
parents: 68
diff changeset
   411
	Array
claus
parents: 68
diff changeset
   412
	    with:10@10
claus
parents: 68
diff changeset
   413
	    with:60@10
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   414
	    with:35@60)) top  
78
claus
parents: 68
diff changeset
   415
    "
claus
parents: 68
diff changeset
   416
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   417
! !
78
claus
parents: 68
diff changeset
   418
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   419
!Polygon class methodsFor:'documentation'!
78
claus
parents: 68
diff changeset
   420
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   421
version
1430
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   422
    ^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.26 2004-03-20 13:19:25 cg Exp $'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   423
! !